Escolar Documentos
Profissional Documentos
Cultura Documentos
Author Message
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.
Code:
#include <18F4550.h>
#fuses HSPLL,CPUDIV1,PLL6,NOWDT,NOPROTECT,NOLVP,NODEBUG,VREGEN,USBDIV
#use delay(clock=48000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7)
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_rda
void serial_isr() {
int t;
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 !!
}
BYTE bgetc() {
BYTE c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}
void main() {
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");
do {
delay_ms(3000);
printf("\r\nBuffered data => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE);
}
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...
...
004C: BTFSS F9D.5 // <- this checks if EUSART RX Int is unmasked
004E: GOTO 0058 // <- this goes to "return of ISR"
0052: BTFSC F9E.5 // <- this checks if EUSART RX Int flag is clear
0054: GOTO 01A6 // <- this branches to serial_isr
0058: ...
2 от 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...
fab
Last edited by fabien.casas on Fri Jan 12, 2007 7:55 am; edited 1 time in total
I'd add a hardware buffer flush, before enabling the interrupts, and also add 'errors' to the
RS232 statement. Something like:
Code:
What else shares with the serial on this chip?. Is it disabled? (SPI).
Best Wishes
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
If the code is checking the input bit, then a software UART is being used. Why?. Don't touch the
TRIS registers 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, CPUDIV, PLL5, NOPROTECT, BROWNOUT, BORV43, PUT,
STVREN, BBSIZ2, NOLVP, NOWRT, LPT1OSC, IESO, FCMEN, PBADEN, NOWRTC, NOWRTB,
NOEBTR, NOEBTRB, NOCPB, 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:
Best Wishes
That's it Ttelmah !
Joined: 28 Nov 2006
Posts: 6
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
admirable way... ).
I guess there are settings that can't be set from user'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.
fab
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...
5 от 5 01.3.2007 г. 09:29