CCS :: View topic - SOLVED: problem with INT_RDA not beein...
FAQ
Forum Help Profile
Official CCS
http://ccsinfo.com/forum/viewtopic.php?t=29446&highlight=inte...
Search
to check your private messages
SOLVED: problem with INT_RDA not beeing fired CCS Forum Index -> General CCS C Discussion View previous topic :: View next topic Author fabien.casas
Message SOLVED: problem with INT_RDA not beeing fired Posted: Thu Jan 11, 2007 12:15 pm
ed: 28 Nov 2006 Posts: 6
Hi all, I'm developping software for a 18F4550 with CCS v. 3.249, and I have a strange problem with the UART receive interrupt. The built-in serial functions (putchar, getch, kbhit...) work fine, but my RDA ISR seems to never be called. So I made a new project, starting from ex_SISR.c. I changed the fuses and #use to match my hardware, and added a small (validated) snippet to blink a led at each received char:
Code: #include <18F4550.h>
#fuses HSPLL,UDIV1,PLL6,NOWDT,NOPROTECT,NOLVP,NODEBUG,VREGEN,USBDIV #use delay(clock=48000000) #use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#bit WATCHDOG_DISABLE = 0xF92.4 #bit GIE = 0xFF2.7 #bit PIE = 0xFF2.6 #bit RCIF = 0xF9E.5 #bit RCIE = 0xF9D.5 #byte RCSTA = 0xFAB #byte TXSTA = 0xFAC
#define BUFFER_SIZE 32 BYTE buffer[BUFFER_SIZE]; BYTE next_in = 0; BYTE next_out = 0;
#int_rda void serial_isr() { int t; // this blinks a LED : static int1 b; if (b) output_high (PIN_C0); else output_low (PIN_C0); b = ! b;
1 от 5
01.3.2007 г. 09:29
CCS :: View topic - SOLVED: problem with INT_RDA not beein...
http://ccsinfo.com/forum/viewtopic.php?t=29446&highlight=inte...
buffer[next_in]=getc(); t=next_in; next_in=(next_in+1) % BUFFER_SIZE; if(next_in==next_out) next_in=t; // Buffer full !! } #define bkbhit (next_in!=next_out) BYTE bgetc() { BYTE c; while(!bkbhit) ; c=buffer[next_out]; next_out=(next_out+1) % BUFFER_SIZE; return(c); }
void main() { WATCHDOG_DISABLE = TRUE;// external watchdog disabled enable_interrupts(global); enable_interrupts(int_rda); if (PIE) printf("\nPIE\n"); if (RCIE) printf("\nRCIE\n"); printf ("\nRCSTA = 0x%X\n", RCSTA);
printf("\r\n\Running...\r\n"); // The program will delay for 10 seconds and then display // any data that came in during the 10 second delay do { delay_ms(3000); printf("\r\nBuffered data => "); while(bkbhit) putc( bgetc() ); } while (TRUE); }
Here is what I get as an output: Quote:
PIE RCIE RCSTA = 0x00 Running... azer Buffered data => Buffered data =>"
-> (global interrupts,) peripheral interrupts and EUSART Receive Interrupt are enabled -> the characters I sent to the PIC ("azer") are not transmitted back, -> the LED (on RC0) is not blinking when I send characters to the PIC -> PIC EUSART is disabled (RCSTA:SPEN = 0), despite #use rs232, and despite obvious serial communication... Looking at the ASM code, I found this: Code: ... 004C: 004E: 0052: 0054: 0058:
2 от 5
BTFSS GOTO BTFSC GOTO ...
F9D.5 // <- this checks if EUSART RX Int is unmasked 0058 // <- this goes to "return of ISR" F9E.5 // <- this checks if EUSART RX Int flag is clear 01A6 // <- this branches to serial_isr
01.3.2007 г. 09:29
CCS :: View topic - SOLVED: problem with INT_RDA not beein...
http://ccsinfo.com/forum/viewtopic.php?t=29446&highlight=inte...
which seems rather ok to me, despite my poor ASM skills. So here are my questions, at least: - could someone please point out that obvious mistake I'm not seeing ? - how does the "#use rs232" stuff bind to the hardware resources ? - does the "#use rs232" stuff bind to the PIC's serial peripheral (like EUSART or MSSP) ? Thanks for your help. fab Last edited by fabien.casas on Fri Jan 12, 2007 7:55 am; edited 1 time in total
Ttelmah Guest
Posted: Thu Jan 11, 2007 1:09 pm
I'd add a hardware buffer flush, before enabling the interrupts, and also add 'errors' to the RS232 statement. Something like: Code: while (RCIF) getc();
What else shares with the serial on this chip?. Is it disabled? (SPI). Best Wishes fabien.casas
ed: 28 Nov 2006 Posts: 6
Posted: Fri Jan 12, 2007 3:37 am
Thanks for your answer. I've added the "errors" option, and flushed the buffer and the flag before enabling interrupts, as you suggested, but there's still no interrupt.
Yes, on 18F4550, the EUSART shares its Rx pin (RC7) with the SPI device (MSSP). The SPI uses it as the SDO line. My software doesn't use SPI, and I could check it is disabled. I've set RC6 (Tx) as an output, and RC7 (Rx) as an input as suggested by the datasheet, before enabling interrupts, but still no luck. By the way, I've looked at the ASM generated by the "kbhit" built-in function, and it seems that it checks the state of the Rx pin. I would have thought it checked the interrupt flag instead... Is there something that can prevent the serial built-ins from using interrupts, other than the "DISABLE_INTS" option ?
fab Ttelmah Guest
Posted: Fri Jan 12, 2007 5:01 am
If the code is checking the input bit, then a software UART is being used. Why?. Don't touch the TRIS s yourself. The compiler does this for you, and it may be confusing it. Add 'bits=8' to the #use statement. I have just coded a 'test' program as follows: Code: #include <18F4450.h> #device adc=8 #FUSES NOWDT, WDT128, HSPLL, UDIV, PLL5, NOPROTECT, BROWNOUT, BORV43, PUT, STVREN, BBSIZ2, NOLVP, NOWRT, LPT1OSC, IESO, FCMEN, PBADEN, NOWRTC, NOWRTB, NOEBTR, NOEBTRB, NOB, MCLR, NOXINST #use delay(clock=48000000) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS) int1 have_data=false; int8 chr; #int_RDA
3 от 5
01.3.2007 г. 09:29
CCS :: View topic - SOLVED: problem with INT_RDA not beein...
http://ccsinfo.com/forum/viewtopic.php?t=29446&highlight=inte...
RDA_isr() { chr=getc(); have_data=false; } void main() { setup_adc_ports(NO_ANALOGS|VSS_VDD); setup_adc(ADC_OFF|ADC_TAD_MUL_0); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); setup_low_volt_detect(FALSE); setup_oscillator(False); while (TRUE) { if (have_data) { putc(chr); have_data=false; } } }
This runs perfectly (I am using a 20Mhz clock), and is using the hardware UART: Code: .................... #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS) 009C: BTFSS F9E.5 009E: BRA 009C 00A0: MOVFF FAB,18 00A4: MOVFF FAE,01 00A8: BTFSS 18.1 00AA: BRA 00B0 00AC: BCF FAB.4 00AE: BSF FAB.4 00B0: NOP 00B2: GOTO 00B8 (RETURN)
Best Wishes fabien.casas
ed: 28 Nov 2006 Posts: 6
Posted: Fri Jan 12, 2007 7:54 am
That's it Ttelmah ! Quote: If the code is checking the input bit, then a software UART is being used.
I tried with just adding "bits=8" to the use_rs232 statement, but that was not enough, my code was still using a software uart. The problem was that I didnot configure my device/source code properly, using the "device editor" tool ! The Rx and Tx pins in the "Edit Device" dialog box were not set. With these set, the compiler generated code for REAL uart (and so my LED started to blink in an irable way... ). I guess there are settings that can't be set from 's code (I tried completing my #fuse list with your example, and it didn't work either). So I'll be more carefull next time. Thanks a lot Ttelmah, you really helped me ! fab Display posts from previous: All Posts
Oldest First
CCS Forum Index -> General CCS C Discussion
Go All times are GMT - 6 Hours
Page 1 of 1
4 от 5
01.3.2007 г. 09:29
CCS :: View topic - SOLVED: problem with INT_RDA not beein...
http://ccsinfo.com/forum/viewtopic.php?t=29446&highlight=inte...
Jump to: General CCS C Discussion You can post new topics You can reply to topics You cannot edit your posts You cannot delete your posts You cannot vote in polls
Go in in in in in
this this this this this
forum forum forum forum forum
Powered by phpBB © 2001, 2005 phpBB Group
5 от 5
01.3.2007 г. 09:29