This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52832 uart buffer size

hi, i have set the uart buffer size as 64. but when i am transmitting data,i found that the size might not enough(eg. there are 100 Bytes to send).how could i do except for expanding the size? i have try to use twice to send the data by for(;;), but it isn't successful.

Parents Reply Children
  • init code:

    void bsp_uart_init(void)
    {
    	uint32_t                     err_code;
    	const app_uart_comm_params_t comm_params =
    	{
    		RX_PIN_NUMBER,
    		TX_PIN_NUMBER,
    		RTS_PIN_NUMBER,
    		CTS_PIN_NUMBER,
    		APP_UART_FLOW_CONTROL_DISABLED,
    		false,
    		UART_BAUDRATE_BAUDRATE_Baud115200
    	};
    	APP_UART_FIFO_INIT( &comm_params,
    			                       UART_RX_BUF_SIZE,
    			                       UART_TX_BUF_SIZE,
    			                       uart_rx_handle,
    			                       APP_IRQ_PRIORITY_LOW,
    			                       err_code);
    	APP_ERROR_CHECK(err_code);
    }
    

    send data func:

    void bsp_uart_send_data(uint8_t * p_data, uint16_t length)
    {
    	uint8_t tx_buff[MAX_RX_LEN] = {0};
    	uint8_t idx = 0;
    	memcpy(&tx_buff[idx], p_data, length);
    	idx += length;
        for (uint32_t i = 0; i < idx; i++)
        {
            while(app_uart_put(tx_buff[i]) != NRF_SUCCESS);
        }
    }
    
  • the init code and the send data code is all above,anytime when i need to send data ,i will call this func "bsp_uart_send_data",and when the param "length" is bigger than "UART_TX_BUF_SIZE",it will not work

  • How long is MAX_RX_LEN? If 'length' is longer than MAX_RX_LEN you will modify bytes that is outside of tx_buff when you use memcpy() like that. When I tested your code this resulted hard faults.

    I suggest that you try something like this instead:

    void bsp_uart_send_data(uint8_t * p_data, uint16_t length)
    {
        for (uint32_t i = 0; i < length; i++)
        {
            while(app_uart_put(*p_data) != NRF_SUCCESS);
            p_data++;
        }
    }
    

    This also seems to work:

    void bsp_uart_send_data(uint8_t * p_data, uint16_t length)
    {
        for (uint32_t i = 0; i < length; i++)
        {
            while(app_uart_put(p_data[i]) != NRF_SUCCESS);
        }
    }
    

    but I'm no C expert so I don't know what is most optimal.

Related