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.

Interrupt Rx SCI Hercules TMS570LS0432

Other Parts Discussed in Thread: TMS570LS0432

Hello,

I'm Juan Carlos, and I start to work with Launchpad Hercules the with TMS570LS0432.
I saw the video to work with SCI on the Launchpad, and the my project functioning correctly, but I can't understand the function with the line that mark in this code.
Why is necessary write this line? I understand that in the interrupt the MCU read the data in the SCI Rx, but in the example code, first the MCU read the data.
If I erase this line, the interrupt don't work.

void main(void)
{
/* USER CODE BEGIN (3) */
_enable_IRQ();
sciInit();
sciEnableNotification(scilinREG,SCI_RX_INT);

sciSend(scilinREG, 21, (unsigned char*)"Please press a key!\r\n");
sciReceive(scilinREG, 1, (unsigned char *)&command);    //<- I can't understand this line
while(1);

/* USER CODE END */
}

/* USER CODE BEGIN (4) */
void sciNotification(sciBASE_t *sci, unsigned flags)
{
sciReceive(sci, 1, (unsigned char *)&command);
sciSend(sci, 1, (unsigned char*)&command);
}
/* USER CODE END */
void esmGroup1Notification(int bit)
{
return;
}

void esmGroup2Notification(int bit)
{
return;
}

Thanks

  • Juan Carlos,

    You need to call sciReceive() to initialize the pointer to the rx buffer and the transfer length global variables:

    void sciReceive(sciBASE_t *sci, uint32 length, uint8 * data)
    {
    /* USER CODE BEGIN (17) */
    /* USER CODE END */

    if ((sci->SETINT & (uint32)SCI_RX_INT) == (uint32)SCI_RX_INT)
    {
    /* we are in interrupt mode */

    /* clear error flags */
    sci->FLR = ((uint32) SCI_FE_INT | (uint32) SCI_OE_INT | (uint32) SCI_PE_INT);

    g_sciTransfer_t.rx_length = length;
    /*SAFETYMCUSW 45 D MR:21.1 <APPROVED> "Valid non NULL input parameters are only allowed in this driver" */
    g_sciTransfer_t.rx_data = data;
    }

    These are used by the ISR so if they are not initialized, your ISR will not function properly.
  • Hello Anthony 

    Thanks for your answer, in this moment I try to read a frame of a protocol between the hercules and other device, but I have a problems. I can't read byte per byte the frame. 

    I only read a 0x00 in the buffer and only a one byte no more. Do you now what is the posible problem?

    In the architecture of the Hercules I use 4 uarts for comunication with other devices,  and in the scinotification I use the next code:


    void sciNotification(sciBASE_t *sci, unsigned flags)
    {
    uint8_t frame[10]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    uint8_t trash[10]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    int i=0;
    int header=0;

    if(sci==CPU)                                                              // This line is to verificate the source of the interrupts CPU=sciREG3
    {
    while(sciIsRxReady(CPU))
    {
    frame[i]=sciReceiveByte(CPU);
    i=i+1;
    }
    header=frame[0];

    if(header == 0x31)
    {
    sciSend(CPU, 8, (unsigned char*)"action\r\n");
    }
    else if(header==0x32)
    {
    sciSend(CPU, 6, (unsigned char*)"read\r\n");
    }
    else
    {
    sciSend(CPU, 6, (unsigned char*)"nada\r\n");
    }
    }
    else
    {
    sciSend(CPU, 7, (unsigned char*)"error\r\n");
    }
    }

  • Hi Juan Carlos,

    I can't really tell much just by the code above.
    Have you looked at the transmit and receive lines with an oscilloscope to see what is on the line?
    Are you seeing the transmission received at the other end of the line but not the reception?
    These are things I'd suggest starting with.

    Also with a UART it is necessary that the baud rates are matching and that the actual baud rates
    (with errors due to oscillator divider values) match the target baud rate value within < 2%.
    Although I wouldn't expect this sort of thing to cause you to recieve 0 if you are only slightly off.

    Make sure you look at whether or not any error flags are set in the SCI's SCIFLR as well - sometimes
    this gives invaluable clues as to what is going on.
  • Hello Anthony,

    Well the protocol has a many frames but no with the same lenght, the MCU need read the all byte in each frame , but in the example only read a one byte and storage in a variable command.

    When the number of the bytes is a equal a x lenght a flag (variable ) is in 1, and the main program the MCU can take a decisión if is a correct frame or not.

    In this moment I modify the code and increment the number of the bytes for read

    sciSend(sci, 1, (unsigned char*)&command);

    I change the number of 1 to 5, but I cant read the last byte that is the CRC of the frame, normaly the lenght is 5 bytes or 6, but in my protocol exist frames with 8 bytes.

    thanks
  • Hello Antony,

    I use the same post to update the status with my work with the SCI peripheral.

    In this moment I have a problem because I can't understan the performance of the buffer of SCI. In my code I read the buffer of this peripheral because I send a frame with 5 bytes with a script of python.

    When I turn On my MCU and sended a frame with the script, the MCU response is good, and I can see the bytes in a variable of my code in correct order like in the image (0x31,0x59,0x17,0xb2,0xd6)

    but in a second time, I send again the same frame with the script and with the debug tool I can see that the frame are in other order (bad order for my aplication)

    I see the signals in my oscilloscope and the byte are ok in the line of rx of mcu, but I can't understand what happend with the order of the bytes in the buffer. I used the example of the configuration of SCI and use function to call the init function of the peripheral and enable the IRQ:

    void MCU_Init(){
    sciInit();
    adcInit();
    canInit();
    gioInit();
    mibspiInit();

    //RTD_Configuration();

    gioSetDirection(hetPORT1, 0xFFFFFFFF);
    gioSetDirection(hetPORT2, 0xFFFFFFFF);
    gioSetPort(hetPORT1, 0x000003FF);
    canIoSetPort(canREG2,0,0);
    canIoSetPort(canREG3,0,0);

    _enable_IRQ();
    sciEnableNotification(CPU, SCI_RX_INT);

    sciReceive(DEBUG, 5, (unsigned char *)&cpu_frame);

    sciReceive(CPU, 5, (unsigned char *)&cpu_frame);

    }

    this is the section of the IRQ

    void sciNotification(sciBASE_t *sci, unsigned flags)
    {
    if(sci==CPU){
    sciReceive(sci, 5, (unsigned char *)&cpu_frame);
    flag_CPU=1;
    }
    if(sci==DEBUG){
    sciReceive(sci, 5, (unsigned char *)&cpu_frame);
    flag_CPU=1;
    }
    }