View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Apr 30, 2018 6:22 am |
|
|
Hi TT,
Yes, simple getc, putc and printf test example works correct.
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Mon Apr 30, 2018 7:02 am |
|
|
You are sure the data format is 'right?. Specify it in the setup. So 8 bits no parity, and double check at the other end.
The only reason it can really go wrong, is that the getc, 'thinks' it has finished, and returns, while the actual incoming data has another low clock which then arrives. This then means the interrupt triggers again, and starts to read incorrect data. Now the sort of thing that would cause this would be (for example) having 9bit data arriving. The software UART does not 'test' for framing errors, so would not report a problem. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Mon Apr 30, 2018 8:04 am |
|
|
Mr.TT com. parameters are OK(9600/8/N/1). With those parameters and without ext_int sw_uart work correct! Another strange thing is when debugging, after second byte I sent int_ext fire! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Mon Apr 30, 2018 11:40 am |
|
|
Which says it is seeing a rising edge....
Have you got a logic analyser?.
Pulse a pin when the interrupt handler gets to the end of the getc. Then have the analyser record the incoming data stream from this point. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Wed May 02, 2018 12:23 am |
|
|
Hi TT,
I have no logic analyzer, but simple test with push button ext_int fire from low to high transition which is incorrect! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Wed May 02, 2018 1:11 am |
|
|
OK.
A quick look at the listing shows you are hitting a database error with the compiler for this chip....
Code: |
//Use this:
#bit INT1EP=getenv("BIT:INT1EP")
#zero_ram
void main(){
delay_ms(500); // wait PLL Lock.
printf("\r\n Hello from 'SW-UART' on DsPic33Ep512MU810");
INT1EP=TRUE; //falling edge
clear_interrupt(INT_EXT1); //in case it is set by setting the edge
ENABLE_INTERRUPTS(INT_EXT1);
for(;;){
if(fl){
putc(c);
fl = FALSE;
}
}
}
|
Report this to CCS.
For some reason the compiler is setting bit 5, not bit 1 to control the polarity. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Wed May 02, 2018 5:13 am |
|
|
Now INT_EXT fire correct, but the data is wrong! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Wed May 02, 2018 7:05 am |
|
|
What do you mean wrong?. If it is triggering at the right place, then it should give the same as when you use it without interrupts (though you might need the SAMPLE_EARLY option).
What is it giving? If you send 'A' for example, what do you get?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9127 Location: Greensville,Ontario
|
|
Posted: Wed May 02, 2018 8:03 am |
|
|
hmm.. I'm wondering if there's maybe no MAX232 between PIC and PC ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Wed May 02, 2018 8:18 am |
|
|
He claims though that it works without using the interrupt. Otherwise I'd suspect something similar.... |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Wed May 02, 2018 12:30 pm |
|
|
Hi,
Yes, without using interrupt, getc and putc data are equal. With interrupt using every time I get 0x00. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9127 Location: Greensville,Ontario
|
|
Posted: Thu May 03, 2018 5:14 am |
|
|
It might be time to post your current code. There's been a LOT of changes in this thread and something might now be obvious, at least it could be tested by others. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Thu May 03, 2018 5:36 am |
|
|
temtronic wrote: | It might be time to post your current code.There's been a LOT of changes in this thread and something might now be obvious,at leat it could be tested by others. |
I also think so:
Code: | #include <33EP512MU810.h>
#device ICSP=1
#use delay(crystal=8MHz, clock=16MHz)
#FUSES NOWDT //No Watch Dog Timer
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //
#bit INT1EP=getenv("BIT:INT1EP")
#pin_select INT1=PIN_G12
#use rs232(baud=9600, xmit=PIN_G13, rcv=PIN_G12, SAMPLE_EARLY)
char c;
int1 fl = FALSE;
#int_ext1
void int1_swuart_isr(void){
c=getc();
fl = TRUE;
}
#zero_ram
void main(){
char c;
delay_ms(500); // wait PLL Lock.
printf("\r\n Hello from 'SW-UART' on DsPic33Ep512MU810");
INT1EP=TRUE; //falling edge
//ext_int_edge(INT_EXT1, H_TO_L);
clear_interrupt(INT_EXT1); //in case it is set by setting the edge
ENABLE_INTERRUPTS(INT_EXT1);
for(;;){
if(fl){
putc(c);
fl = FALSE;
}
//c = getc(); // ok
//putc(c); // ok
}
}
|
P.S I'm using MAX3232 level convertor. |
|
|
|