I have a machine with eighteen TM4C1231D5PM microcontrollers on a UART bus. A computer transmits a command to turn on and off GPIO pins connected to relays. A command consists of start character (<), three address characters (018) and either an open (O) or close (C) command finally a end character (>). An example to open a relay would look like, <018O7>. To verify the microcontroller has turned on/off a relay it responds with >0< for open and >1< for closed. When the computer attempts to open all relays on the microcontroller at address 18 it tends to get stuck. The computer will send <018O7> and the microcontroller will respond with "<",
I have written the class that communicates with each microcontroller to re-transmit the same <018O7> command when it receives only ">". Windows does re-transmit, but the microcontroller does not respond.
The UART0 interrupt handler for UART0 is,
void UARTIntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART0_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART0_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // cmd_index = 0; while(ROM_UARTCharsAvail(UART0_BASE)) { cmd[cmd_index] = ROM_UARTCharGet(UART0_BASE); cmd_index++; } if (cmd[0] == '<') { addr_str[0] = cmd[1]; addr_str[1] = cmd[2]; addr_str[2] = cmd[3]; addr = atoi(&addr_str); if (addr == 18) { if (cmd[4] == 'O') //Open Command { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); char channel = cmd[5]; if (channel == '0') //Channel 1 -> R8 -> F3 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0); UARTSend(">0<",3); } else if(channel == '1') //Channel 2 -> R7 -> F2 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); UARTSend(">0<",3); } else if(channel == '2') //Channel 3 -> R6 -> F1 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); UARTSend(">0<",3); } else if(channel == '3') //Channel 4 -> R5 -> F0 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0); UARTSend(">0<",3); } else if(channel == '4') //Channel 5 -> R4 -> A7 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, 0); UARTSend(">0<",3); } else if(channel == '5') //Channel 6 -> R3 -> A6 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, 0); UARTSend(">0<",3); } else if(channel == '6') //Channel 7 -> R2 -> A5 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_5, 0); UARTSend(">0<",3); } else if(channel == '7') //Channel 8 -> R1 -> A4 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0); UARTSend(">0<",3); } else if(channel == '8') { //Channel SIG8 -> R9 -> B5 ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, 0); UARTSend(">0<",3); } else if (channel == '9') { //Channel SIG7 -> R10 -> B4 ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0); UARTSend(">0<",3); } else if (channel == 'A') { //Channel SIG6 -> R11 -> E4 ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, 0); UARTSend(">0<",3); } else if (channel == 'B') { //Channel SIG5 -> R12 -> E5 ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0); UARTSend(">0<",3); } else if (channel == 'C') { //Channel SIG4 -> R13 -> D0 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0); UARTSend(">0<",3); } else if (channel == 'D') { //Channel SIG3 -> R14 -> D1 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0); UARTSend(">0<",3); } else if (channel == 'E') { //Channel SIG2 -> R15 -> D2 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0); UARTSend(">0<",3); } else if (channel == 'F') { //Channel SIG1 -> R16 -> D3 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, 0); UARTSend(">0<",3); } } if (cmd[4] == 'C') { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); char channel = cmd[5]; if (channel == '0') //Channel 1 -> R8 -> F3 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3); UARTSend(">1<",3); } else if(channel == '1') //Channel 2 -> R7 -> F2 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); UARTSend(">1<",3); } else if(channel == '2') //Channel 3 -> R6 -> F1 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1); UARTSend(">1<",3); } else if(channel == '3') //Channel 4 -> R5 -> F0 { ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); UARTSend(">1<",3); } else if(channel == '4') //Channel 5 -> R4 -> A7 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_PIN_7); UARTSend(">1<",3); } else if(channel == '5') //Channel 6 -> R3 -> A6 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_PIN_6); UARTSend(">1<",3); } else if(channel == '6') //Channel 7 -> R2 -> A5 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_PIN_5); UARTSend(">1<",3); } else if(channel == '7') //Channel 8 -> R1 -> A4 { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_PIN_4); UARTSend(">1<",3); } else if(channel == '8') { //Channel SIG8 -> R9 -> B5 ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5); UARTSend(">1<",3); } else if (channel == '9') { //Channel SIG7 -> R10 -> B4 ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_PIN_4); UARTSend(">1<",3); } else if (channel == 'A') { //Channel SIG6 -> R11 -> E4 ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4); UARTSend(">1<",3); } else if (channel == 'B') { //Channel SIG5 -> R12 -> E5 ROM_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, GPIO_PIN_5); UARTSend(">1<",3); } else if (channel == 'C') { //Channel SIG4 -> R13 -> D0 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0); UARTSend(">1<",3); } else if (channel == 'D') { //Channel SIG3 -> R14 -> D1 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_PIN_1); UARTSend(">1<",3); } else if (channel == 'E') { //Channel SIG2 -> R15 -> D2 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_PIN_2); UARTSend(">1<",3); } else if (channel == 'F') { //Channel SIG1 -> R16 -> D3 ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, GPIO_PIN_3); UARTSend(">1<",3); } } if (cmd[4] == 'S') //Status Command { ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); char channel = cmd[5]; if (channel == '0') //Channel 1 -> R8 -> F3 { ch_state = ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_3); ch_state = ch_state >> 3; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '1') //Channel 2 -> R7 -> F2 { ch_state = ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2); ch_state = ch_state >> 2; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '2') //Channel 3 -> R6 -> F1 { ch_state = ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1); ch_state = ch_state >> 1; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '3') //Channel 4 -> R5 -> F0 { ch_state = ROM_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0); ch_state = ch_state >> 0; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '4') //Channel 5 -> R4 -> A7 { ch_state = ROM_GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_7); ch_state = ch_state >> 7; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '5') //Channel 6 -> R3 -> A6 { ch_state = ROM_GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_6); ch_state = ch_state >> 6; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '6') //Channel 7 -> R2 -> A5 { ch_state = ROM_GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_5); ch_state = ch_state >> 5; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '7') //Channel 8 -> R1 -> A4 { ch_state = ROM_GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_4); ch_state = ch_state >> 4; if (ch_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '8') //Signal State -> All GPIO Pins Must Be On { //Channel SIG8 -> R9 -> B5 s8_state = ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_5); s8_state = s8_state >> 5; if (s8_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == '9') //Signal State -> All GPIO Pins Must Be On { //Channel SIG7 -> R10 -> B4 s7_state = ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4); s7_state = s7_state >> 4; if (s7_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == 'A') //Signal State -> All GPIO Pins Must Be On { //Channel SIG6 -> R11 -> E4 s6_state = ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4); s6_state = s6_state >> 4; if (s6_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == 'B') //Signal State -> All GPIO Pins Must Be On { //Channel SIG5 -> R12 -> E5 s5_state = ROM_GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5); s5_state = s5_state >> 5; if (s5_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == 'C') //Signal State -> All GPIO Pins Must Be On { //Channel SIG4 -> R13 -> D0 s4_state = ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_0); s4_state = s4_state >> 0; if (s4_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == 'D') //Signal State -> All GPIO Pins Must Be On { //Channel SIG3 -> R14 -> D1 s3_state = ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_1); s3_state = s3_state >> 1; if (s3_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == 'E') //Signal State -> All GPIO Pins Must Be On { //Channel SIG2 -> R15 -> D2 s2_state = ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_2); s2_state = s2_state >> 2; if (s2_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } else if(channel == 'F') //Signal State -> All GPIO Pins Must Be On { //Channel SIG1 -> R16 -> D3 s1_state = ROM_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_3); s1_state = s1_state >> 3; if (s1_state == 1) UARTSend(">1<",3); else UARTSend(">0<",3); } } } }
The UARTSend function is,
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { //ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); //delayMs(10); // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // ROM_UARTCharPut(UART0_BASE, *pui8Buffer++); } while (ROM_UARTBusy(UART0_BASE)) { } ROM_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0); }
Does anyone have any suggestions on how to fix this?
Thanks,
Allan