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
  • Hi Cory 

    Check the size of your RX buffer. The interrupt triggers when it is full.

  • 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.

  • 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.

Reply
  • 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.

Children
No Data