I'm working on a application where UART1 is getting a continuous stream of data. I parse it and use some parts for the D2A and other parts are "translated" and sent to UART0.
Most of the ISR code in the project comes from other projects I written in the past.
The following init code is called early in main(). The problem is that any combination of two of timer0, uart0 and uart1 works correctly. As soon as I add the third my timer0 ISR fails. I have used this chip only once before and that project has been in production for over a year. The other project also uses both UARTs but not at the same baud rate and not with the "intensity" of data.
static void Initialize8032( void ) { // // Set up on-board timers. // Timer 0 is used as the system clock. // Timer 1 is used to time fsp protocol related parameters // Timer 2 is used as the UART0 baud rate generator (no interrupt) // // stop timers 0 & 1 TMOD = 0x11; // timers 0 and 1 are 16-bit, manual reload TL0 = ( -10 * ONE_MSEC & 0x00ff ); TH0 = ( -10 * ONE_MSEC & 0xff00 ) >> 8; TCON = 0x15; // Start timer 0 only;, external ints are EDGE triggered. // TR0 = 1; // IT0 = 1; // IT1 = 1; // Configure internal serial port and baud rate generator and enable the // serial port interrupt. The onboard UART is used to communciate with // the scorer. // // RCAP2 baud rate equation: // RCAP2(H,L) = 65536 - (Osc Freq)/((32*baud rate)) // in X2 Mode: // RCAP2 baud rate equation: // RCAP2(H,L) = 65536 - (Osc Freq)/((16*baud rate)) S0CON = 0x40; // Mode 1, 8-bit UART, receive disabled T2CON = 0x30; // Turn off baud rate generator #ifdef MC2 RCAP2L = 0xB8; // 9600 baud @ 11.059 Mhz 6 clocks RCAP2H = 0xFF; #else RCAP2L = 0xEE; RCAP2H = 0xFF; #endif T2CON = 0x34; // Turn on baud rate generator S0CON = 0x50; // Mode 1, 8-bit UART, receive enabled IP0 = 0x00; IP0H = 0x00; IP1 = 0x05; IP1H = 0x05; IEN0 = 0x92; IEN1 = 0x01; } void InitializeUART1( baud_rates_t baud ) { // Lookup table - translates "device_baud_rates_t" to actual value for BRGR0 and BRGR1 static uint16_t code BaudRateDL[] = { 0x8E00, // DEVICE_BAUD_110 TODO: UNTESTED 0x88B5, // DEVICE_BAUD_300 TODO: UNTESTED 0x2400, // DEVICE_BAUD_1200 0x11f0, // DEVICE_BAUD_2400 0x08F8, // DEVICE_BAUD_4800 0x0470, // DEVICE_BAUD_9600 0x0238, // DEVICE_BAUD_19200 0x011C, // DEVICE_BAUD_38400 0x008F, // DEVICE_BAUD_57600 TODO: WRONG VALUE 0x0095 // DEVICE_BAUD_115200 TODO: WRONG VALUE }; // Setup UART1 as Mode 1. It can only use the Internal Baud rate Generator (IBRG). S1STAT = 0x20; // The IBRG must be disabled before BRG0 and BRG1 can be loaded. BRGCON = BRGCON & ~0x01; S1CON = 0x40; BRGR0 = (uint8_t)(BaudRateDL[ baud ] & 0xff); BRGR1 = (uint8_t)(BaudRateDL[ baud ] >> 8); // The IBRG must be turned back on BRGCON |= 0x01; REN_1 = 1; }
Do you have any thoughts on the problem or a recommendation of a currently available emulator?