This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1231D5PM: UART0 Fails to Transmitt

Part Number: TM4C1231D5PM

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

  • Hi,

      I'm not 100% clear on your system. Can you answer a few questions. 

     - Reading your code, it seems that when <018O7> is sent, the channel 8 is selected to open the relay connected to PA4. Is that correct?

     - If all 18 MCUs receives the same command, then each MCU will still select channel 8 to open the relay connected to PA4, isn't? You mentioned "When the computer attempts to open all relays on the microcontroller at address 18 it tends to get stuck."  I'm confused as to how are you going to send a command so that each MCU will open a different relay. For example MCU1 will open channel 1, MCU2 opens channel2 and so on so forth at the same time.

     - You said the all UARTs are connected to a bus. How does that work? Why if different UARTs return different status? Don't they create a conflict they are connected to a bus?

     - If you put a breakpoint on line 14 on the UARTSend() function, do you the >0< in the *pui8Buffer?

     - For experiment, if you only enable one UART and disconnect the other 17, will you see different results?

  • Hi Charles,

    - Reading your code, it seems that when <018O7> is sent, the channel 8 is selected to open the relay connected to PA4. Is that correct?

    Yes that is correct. The relay connected to PA4 should open.

    - If all 18 MCUs receives the same command, then each MCU will still select channel 8 to open the relay connected to PA4, isn't? You mentioned "When the computer attempts to open all relays on the microcontroller at address 18 it tends to get stuck."  I'm confused as to how are you going to send a command so that each MCU will open a different relay. For example MCU1 will open channel 1, MCU2 opens channel2 and so on so forth at the same time.

    The address on each card is changed before a card is programmed,

    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) //Address can be from 18 to 35.
            {

     - You said the all UARTs are connected to a bus. How does that work? Why if different UARTs return different status? Don't they create a conflict they are connected to a bus?

    The UARTs are connected to RS485 bus that eventually gets connected to a computer. Each microcontroller is programmed with a different address, so only one microcontroller can respond when asked to open or close.

     - If you put a breakpoint on line 14 on the UARTSend() function, do you the >0< in the *pui8Buffer?

    I can't get Code Composer Studio to reliably hit a break point at line 14.

    I wanted to attempt to try and clock the MCU at 80MHz, but I must not have done it correctly. I think the problem may be how I am clocking the MCU. Changing from this,

    ROM_SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_SYSDIV_5);

    to this,

    ROM_SysCtlClockSet(SYSCTL_OSC_INT | SYSCTL_USE_OSC | SYSCTL_SYSDIV_1);

    Seemed to fix the problem.

    Thanks,

    Allan