??? 03/14/06 09:20 Read: times |
#112110 - UART0 interrupt not generating |
hi
i am struck with some stange problem. i was using polling type communication on uart0 on F124. the only interurrput i use is Timer 2 for timing. now i changed the program for making serial communication using interrupts. but it is not generating serial interrupt at all. not only that Timer 2 interrupt also not generating if i set uart0 interrupt priority high. what could be wrong? the same program is working fine with polling coomunication and only timer2 interrupt was used. initialisation code as below void Init_COM() { SFRPAGE = LEGACY_PAGE; SSTA0 = 0x1A; // disable double baud and select timer 3 for baud rate SCON0 = 0x50; // mode 1. enable receiver clear RI & TI. RI0 = 0; TI0 = 0; // to send first char ok SFRPAGE = UART1_PAGE; RI1 = 0; // uart1 TI1 = 1; SFRPAGE = LEGACY_PAGE; t_in = 0; // transmi buffer t_out = 0; r_in = 0; // receive buffer r_out = 0; ti_restart = 1; // to send first character ES0 = 1; // enable Serial Interrupt PS = 1; // serial interrupt to high priority ET2 = 1; PT2 = 0; // Timer 2 low Priority EA = 1; } serial Io routines as below file sio.c #include <string.h> #include "sio.h" #define TBUF_SIZE 128 /*** Must be one of these powers of 2 (2,4,8,16,32,64,128) ***/ #define RBUF_SIZE 128 /*** Must be one of these powers of 2 (2,4,8,16,32,64,128) ***/ #define TBUF_SPACE xdata /*** Memory space where the transmit buffer resides ***/ #define RBUF_SPACE xdata /*** Memory space where the receive buffer resides ***/ #define CTRL_SPACE xdata /*** Memory space for the buffer indexes ***/ #if TBUF_SIZE < 2 #error TBUF_SIZE is too small. It must be larger than 1. #elif TBUF_SIZE > 128 #error TBUF_SIZE is too large. It must be smaller than 129. #elif ((TBUF_SIZE & (TBUF_SIZE-1)) != 0) #error TBUF_SIZE must be a power of 2. #endif #if RBUF_SIZE < 2 #error RBUF_SIZE is too small. It must be larger than 1. #elif RBUF_SIZE > 128 #error RBUF_SIZE is too large. It must be smaller than 129. #elif ((RBUF_SIZE & (RBUF_SIZE-1)) != 0) #error RBUF_SIZE must be a power of 2. #endif static TBUF_SPACE unsigned char tbuf [TBUF_SIZE]; static RBUF_SPACE unsigned char rbuf [RBUF_SIZE]; static CTRL_SPACE unsigned char t_in = 0; static CTRL_SPACE unsigned char t_out = 0; static CTRL_SPACE unsigned char r_in = 0; static CTRL_SPACE unsigned char r_out = 0; static bit ti_restart = 0; /* NZ if TI=1 is required */ static unsigned char oldsfrPage = 0; static void com_isr (void) interrupt 4 { oldsfrPage = SFRPAGE; SFRPAGE = LEGACY_PAGE; //Received data interrupt. if (RI0 != 0) { RI0 = 0; if (((r_in - r_out) & ~(RBUF_SIZE-1)) == 0) { rbuf [r_in & (RBUF_SIZE-1)] = SBUF0; r_in++; } } // Transmitted data interrupt. if(TI0 != 0) { TI0 = 0; if(t_in != t_out) { SBUF0 = tbuf [t_out & (TBUF_SIZE-1)]; t_out++; ti_restart = 0; } else { ti_restart = 1; } } SFRPAGE = oldsfrPage; } #pragma disable char putchar1 (unsigned char c) { SFRPAGE = LEGACY_PAGE; //If the buffer is full, return an error value. if (com_tbuflen () >= TBUF_SIZE) return (-1); //Add the data to the transmit buffer. If the //transmit interrupt is disabled, then enable it. tbuf [t_in & (TBUF_SIZE - 1)] = c; t_in++; if(ti_restart) { ti_restart = 0; TI0 = 1; /* generate transmit interrupt */ } return (0); } #pragma disable int getc (void) { if (com_rbuflen () == 0) return (-1); return (rbuf [(r_out++) & (RBUF_SIZE - 1)]); } #pragma disable unsigned char com_rbuflen (void) { return (r_in - r_out); } #pragma disable unsigned char com_tbuflen (void) { return (t_in - t_out); } if i set PT2 = 0; and PS = 1; timer 2 interrupt is not generating. it is set PT2 = 1; nad PS = 0; timer 2 interrupt is generating. i put debug code to display the values for some SFRs as below EA = 1 PS0 = 1 PT2 = 1 ET2 = 1 TI0 = 1 t_in = 128 t_out = 0 eventhough TI0 = 1 it is not generating interrupt why ? in the main program i wrote the following. if(putchar1('A') == -1) // if buffer is full putchar2('E'); // send 'E' on serial port 2 it is not sending any characters on UART0. i get stream of characters 'E' on UART1. means buffer is full. kindly suggest me location of the fault thanks & regards Haribabu |