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.

CCS/TMS570LC4357: UART BUFFER PROBLEM

Part Number: TMS570LC4357

Tool/software: Code Composer Studio

Hello,

I work with the uart of the Hercules but I have a problem. I use an array to store the bytes that recive the MCU trought the uart port, but I see that the program lost the first byte that recive.

For example, when send the secuence 1234, the MCU send trought other uart only 234, and if I send again the secuence 1234 the MCU display 2341.

I share the basic code that use in the ISR and in the main code. 

int main(void)

{
/* USER CODE BEGIN (3) */
int i=0;
MCU_Init();

//sci_Restart();
while(1)
{
rx_next=0;
rx_read=0;
rxb_next=0;
rxb_read=0;

delay(10);

if(flag_Blue==1){ //Read the buffer 
sciSend(BLUE,11, (unsigned char*)"\r\nbuffer!\r\n");

while(flag_Blue==1){
sciSendByte(BLUE,rx_buffer_blue[rxb_read]);
rxb_read++;
rxb_next--;
if(rxb_next==-1){
flag_Blue=0;
rxb_read=0;
rxb_next=0;
for(i=0;i<100;i++){
rx_buffer_blue[i]=0;}
}
}
}

 }

void sciNotification(sciBASE_t *sci, unsigned flags)
{

if(sci==BLUE){
sciReceive(sci,1,(unsigned char *)&rx_buffer_blue[rxb_next]);
sciSendByte(BLUE,rx_buffer_blue[rxb_next]);
rxb_next++;

if(sciIsRxReady(sci)==0){
flag_Blue=1;
}

}

If you have any suggestion or question , please tell me

  • I update the code, because I not use in the moment the instruction scisendbyte inside of the sci notificacion. This part of the code is:

    void sciNotification(sciBASE_t *sci, unsigned flags)
    {

    if(sci==BLUE){
    sciReceive(sci,1,(unsigned char *)&rx_buffer_blue[rxb_next]);
    rxb_next++;

    if(sciIsRxReady(sci)==0){
    flag_Blue=1;
    }

    }
  • Hello Sanchez,

    Unfortunately, I wasn't able to dive too deep into this to determine an exact root cause, but in prior issues like this I found that there was an issue with initialization of the interrupt and the first byte is lost because the interrupt doesn't come until the second byte.

    Where in your code do you initialize/enable the interrupt during your code startup?
  • Hello Chuck,

    Above of the initialitation of the interrupt I share a part of my code:

    // @file HL_sys_main.c

    #include "HL_sci.h"
    #include "HL_het.h"
    #include "HL_gio.h"
    #include "stdlib.h"
    #include "HL_sci.h"

    /* USER CODE END */
    /* Include Files */

    #include "HL_sys_common.h"

    /* USER CODE BEGIN (1) */
    //==================================Variables IRIDIUM & DEBUG
    unsigned char command;
    unsigned char rx_buffer_blue[100];
    int rx_next=0;
    int rx_read=0;
    int rxb_next=0;
    int rxb_read=0;

    uint8_t flag_Blue=0;

    void Plot_Debug();

    void sci_Restart()

    {
    sciInit();
    _enable_IRQ();

    sciEnableNotification(BLUE, SCI_RX_INT);
    sciReceive(BLUE, 1, (unsigned char *)&rx_buffer_blue);

    }

    void MCU_Init()

    {
    //int i=0;
    sciInit();
    adcInit();
    //adcInit();
    //sciSend(DEBUG, 11, (unsigned char*)"MCU INIT!\r\n");
    gioSetDirection(hetPORT1, 0x2040240A);
    gioSetPort(hetPORT1, 0x00000000);
    gioSetDirection(hetPORT2, 0xFFFFFFFF);
    gioSetPort(hetPORT2, 0x00000000);

    _enable_IRQ();
    sciEnableNotification(BLUE, SCI_RX_INT);

    //Inputs

    //gioSetBit(hetPORT1,12,0); //CTS
    //gioSetBit(hetPORT1,16,0); //DCD
    //gioSetBit(hetPORT1,14,0); //DSR

    //Outputs

    gioSetBit(hetPORT2,13,1); //RTS 
    gioSetBit(hetPORT1,29,1); //DTR 

    sciReceive(BLUE, 1, (unsigned char *)&rx_buffer_blue[99]);

    rx_buffer_blue[99]=0;
    sciSend(BLUE, 11, (unsigned char*)"MCU Init!\r\n");
    }

    /* USER CODE END */

    /** @fn void main(void)
    * @brief Application main function
    * @note This function is empty by default.
    *
    * This function is called after startup.
    * The user can use this function to implement the application.
    */

    /* USER CODE BEGIN (2) */

    /* USER CODE END */

    int main(void)

    {
    /* USER CODE BEGIN (3) */
    int i=0;
    MCU_Init();

    //sci_Restart();
    while(1)
    {
    rx_next=0;
    rx_read=0;
    rxb_next=0;
    rxb_read=0;

    delay(10);

    if(flag_Blue==1){ //Read the buffer 
    sciSend(BLUE,11, (unsigned char*)"\r\nbuffer!\r\n");

    while(flag_Blue==1){
    sciSendByte(BLUE,rx_buffer_blue[rxb_read]);
    rxb_read++;
    rxb_next--;
    if(rxb_next==-1){
    flag_Blue=0;
    rxb_read=0;
    rxb_next=0;
    for(i=0;i<100;i++){
    rx_buffer_blue[i]=0;}
    }
    }
    }

     }

    void sciNotification(sciBASE_t *sci, unsigned flags)

    {

    if(sci==BLUE){
    sciReceive(sci,1,(unsigned char *)&rx_buffer_blue[rxb_next]);
    sciSendByte(BLUE,rx_buffer_blue[rxb_next]);
    rxb_next++;

    }

    {


    I followed the example of you IT, the only difference is the buffer, this buffers  storage the bytes that received in the port (color blue)

  • Hi Sanchez
    Were you able to solve this issue?
    Regards
    Mukul