Uart Callback function only getting two bytes

Hello all,

Does anyone know why the callback function only gets the first two chars of a string? I thought it was suppose to trigger off each incoming byte.

Parents Reply
  • Hi Lou,

    Currently I'm not using the uart_read function. Just relying on the callback itself. Modifying the stock example, the size is uint8_t g_out_of_band[10];. It triggers twice filling the first two array indexes when I'm sending a value of "hello". So I end up with 2 values h and e.

Children
  • Hi Cory,

    Could you please share the callback function of your project for us to get more information.

  • void uart1_callback(uart_callback_args_t *p_args)  //uart event callback function prototype
    {
       fsp_err_t err = FSP_SUCCESS;
        g_uart_event = p_args->event;
        /* Handle the UART event */
        switch (p_args->event)
        {
            /* Received a character */
            case UART_EVENT_RX_CHAR:
            {
    
                /* Only put the next character in the receive buffer if there is space for it */
                if (sizeof(g_out_of_band_received) > g_out_of_band_index)
                {
                    /* Write either the next one or two bytes depending on the receive data size */
                    if (UART_DATA_BITS_8 >= g_uart0_cfg.data_bits)
                    {
                        g_out_of_band_received[g_out_of_band_index++] = (uint8_t) p_args->data;
    
                    }
                    else
                    {
                        uint16_t *p_dest = (uint16_t*) &g_out_of_band_received[g_out_of_band_index];
                        *p_dest = (uint16_t) p_args->data;
                        g_out_of_band_index += 2;
                    }
                }
    
                break;
            }
                /* Receive complete */
            case UART_EVENT_RX_COMPLETE:
            {
                g_receive_complete = 1;
                break;
            }
                /* Transmit complete */
            case UART_EVENT_TX_COMPLETE:
            {
                g_transfer_complete = 1;
                break;
            }
            default:
            {
    
            }
        }

    How do I get this call_back function to read more than bytes? I am using RTOS and not sure if this has anything to do with my issue.

  • Hello Cory,

    Thank you for reaching out Renesas Engineering Community.

    First of all  as already mentioned we would like to share with us some sample code to check what might is going wrong in your project. Also please provide us the part number of the MCU you are using.

    Regarding your issue, please let me attach for you an example project, I have created to replicate your issue on RA2L1.  I am sending from a Serial Terminal the word hello as you do.

    In my sample code I have a buffer which has a total size of 15 bytes. As soon as the whole buffer fills my code hits a breakpoint. 

    As you can see the characters I am sending have been received with no issues.

    As you in my code I am not calling the Read API and the buffer fills every time I get a UART_EVENT_RX_CHAR  event and I receive one character per time.

    Hope this will help you proceed.

    Best Regards,

    IK

    RA2L1_UART_RX_example.zip

  • Hello,

    I am using the RA4M3 series with a custom board as well as free rtos in my project. I am using the example call_back function in my code. I need to handle an unknown length of incoming data. But for testing purposes, I am only sending the string "hello" in one send and only receiving the values H and E.  

    uint8_t  g_out_of_band[10] - is the size of my array

    note: in your example above, you are getting the full "hello" value. I never am. H and E on every callback. So my buffer would be filled with hehehe.

    note: I get an overflow error after the 2nd byte. So I get H and E and an overflow instead of the next character.

    void uart1_callback(uart_callback_args_t *p_args)  //uart event callback function prototype
    {
       fsp_err_t err = FSP_SUCCESS;
        g_uart_event = p_args->event;
        /* Handle the UART event */
        switch (p_args->event)
        {
            /* Received a character */
            case UART_EVENT_RX_CHAR:
            {
    
                /* Only put the next character in the receive buffer if there is space for it */
                if (sizeof(g_out_of_band_received) > g_out_of_band_index)
                {
                    /* Write either the next one or two bytes depending on the receive data size */
                    if (UART_DATA_BITS_8 >= g_uart0_cfg.data_bits)
                    {
                        g_out_of_band_received[g_out_of_band_index++] = (uint8_t) p_args->data;
    
                    }
                    else
                    {
                        uint16_t *p_dest = (uint16_t*) &g_out_of_band_received[g_out_of_band_index];
                        *p_dest = (uint16_t) p_args->data;
                        g_out_of_band_index += 2;
                    }
                }
    
                break;
            }
                /* Receive complete */
            case UART_EVENT_RX_COMPLETE:
            {
                g_receive_complete = 1;
                break;
            }
                /* Transmit complete */
            case UART_EVENT_TX_COMPLETE:
            {
                g_transfer_complete = 1;
                break;
            }
            default:
            {
    
            }
        }
    }
     

  • Hello Cory,

    Please also share with us your configuration.xml file to check.

    Best Regards,

    IK

  • I see what's going on. For whatever reason, the callback only grabs the initial 2 bytes. Then, at some point, the rest of the data gets added to the array. It would be nice if there was some way to know when the data is done transferring.  

  • Hi Cory,

    When the transferring is done, it will send a flag to callback, you can check the p_args->event. It should be UART_EVENT_TX_COMPLETE or UART_EVENT_RX_COMPLETE.

  • I was under the impression that the UART_EVENT_RX_COMPLETE flag was only sent when using the UART_READ function.