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.

F28M35H52C: Trying to develop a simple Modbus Ascii application using UART1 of master cortex m3 core. Using CCS 6.0 on linux mint.

Part Number: F28M35H52C

The application uses both Receive and Transmit Interrupt. I have disabled FIFO operations as i faced receiving problem before disabling. 

 

I have been testing this application using a modbus master which transmits 8 bytes from my laptop. I receive 8 bytes on the controller and do some processing in between before i transmit some response.

 

Now transmission is where i am stuck, When i try to transmit some data i had a break point at UARTCharPut(data) function and single stepped expecting to see the same data on the receiving (laptop) terminal. But i do not see anything transmitted and some other times when i run the code with out any break points i see that the data get transmitted but not in the rite order that it was sent.

 

I have tried every possible option that was mentioned in the UART section of TI reference manual for F28M35H controller.  

 

Please find the application project attached (.7z) in this post,  Any help pointing out where am i slipping ?Modbus-Slave.7z

  • Andres,

    It will be helpful if you post small snippets of relevant code, reading through an entire project can be very time consuming.

    I am not positive how breakpoints work on the M3, it is possible that they are disturbing the UART function. I will see what I can find on this topic.

    As for the data being transmitted in the wrong order, could you provide an example?

      • What types of data(int, char, uint etc.) are you providing to the UARTCharPut function?
      • Can you use the memory browser to read the data immediately before transmit to check if it is correct?

    Regards,
    Cody

  • Thanks for the reply cody,

     

    Here is what i am trying to do,

     

    1. Initialize UART1 as explained in the reference manual, This can be seen in ${PROJECT}/src/UART_Interface.c file. The exact code snippet initializing the UART1 can be seen below:

     

        void InitUART1(void){

     

        SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

        InitMasterInterrupt();

        GPIOPinConfigure(GPIO_PD0_U1RX);

        GPIOPinConfigure(GPIO_PD1_U1TX);

        GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);

        UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(SYSTEM_CLOCK_SPEED), 9600,

                                                 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |

                                                  UART_CONFIG_PAR_NONE));

     

        // Enable the UART0 interrupt.

         IntRegister(INT_UART1, UART1IntHandler);

         IntEnable(INT_UART1);

         UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_TX);

      }


    NOTE: I have disabled the FIFO mode by commenting out the FIFO enabling MACRO inside UARTEnable function. I started receiving the data in the order i sent from Master after i disabled the FIFO.  

     

    2. I have defined UART1 Interrupt handler in ${PROJECT}/src/UART_Interrupt.c file. This handler is used to handle both RX and TX generated interrupts. The code snippet for Handler can be seen below: 

     

        void UART1IntHandler(void)

        {

            unsigned long ulStatus;



             ulStatus = UARTIntStatus(UART1_BASE, true);





             if(0x10 & ulStatus)

            {

                 UART1Buffer[UART1Count++]  = UARTCharGet(UART1_BASE);  // storing the byte data what ever i have received in a buffer! 



                 if(UART1Count>30)

                {

               UART1Count = 0;

                }

               TX_cnt = 0;

           }

           else

           {

                   TX_cnt=1;

           }



          UARTIntClear(UART1_BASE, ulStatus);

       }

     

    3. Once the data is received i do some modbus data processing before i transmit some data back to master. The transmission is defined in a file ${PROJECT}/src/UART_Interface.c. The code snippet can be seen below:


    extern unsigned int TX_cnt;

    void WriteToUART1(const unsigned char pucBuffer)

    {

    //UARTCharPut(UART1_BASE,pucBuffer);           // Used this first before using TX interrupt method as seen below after while(1) 

     

    while(1)

    {

    if(UARTSpaceAvail(UART1_BASE))

    {

    UARTCharPut(UART1_BASE,pucBuffer);

    while(!TX_cnt);

    TX_cnt=0;

    return;

    }

    }

    }

     

    • What types of data(int, char, uint etc.) are you providing to the UARTCharPut function?

     As you can see above(code snippet 3) i am using char data. 

    • Can you use the memory browser to read the data immediately before transmit to check if it is correct?

    I have not tried using memory browser, but i check the UARTDR register in the register window with breakpoints when transmitting.Here i see that the data does not get refreshed after i step over the UARTChrPut() function. i.e i do not see the same data in UARTDR register what i tried to transmit. So this leads to data Tranmission loss or data received on the Master in worng order.


    Below is a example scenario, when i say wrong order of data received:


    Ex: lets say i am trying to transmit 0123456789 byte by byte through UART1 with FIFO disabled, so i should expect data recevied in the same order on Master Terminal. But rather i sometimes receive 12087 with some data loss and wrong order or sometimes i receive 0123465897.


    I have not considered using DMA, but i thought it should not be required for this simple application ? Please suggest. 


    Thanks

  • Andres,

    Lets try to limit where the problem could be. Can you use an Oscilloscope to ensure that the correct frames are being transmitted?

    Another thing you may try is loopback, connecting TX to RX and RX to TX of another UART or the SCI module on the same device.


    Regards,
    Cody