UART baudrate change gives non-intuitive result

kaolpr
Posts: 1
Joined: Thu Nov 22, 2018 8:34 pm

UART baudrate change gives non-intuitive result

Postby kaolpr » Thu Nov 22, 2018 8:47 pm

In my application I need to first send some bytes using one baudrate and then, using the same UART, switch to another. I used the following code:

Code: Select all

uart_config_t uart_config = {
        .baud_rate = 250000,
        .data_bits = UART_DATA_8_BITS,
        .parity    = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_2,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
};
uart_param_config(UART_NUM_2, &uart_config);
uart_set_pin(UART_NUM_2, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
uart_driver_install(UART_NUM_2, 2048, 0, 0, NULL, 0); // Expecting blocking TX calls as TX buffer is set to 0

uint8_t buffer[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE}; // First byte will be sent using lower baudrate

while(1) {
	// The slow part
        uart_set_baudrate(UART_NUM_2, 50000));
        uart_write_bytes(UART_NUM_2, (const char *) buffer, 1);
        // uart_wait_tx_done(UART_NUM_2, 1000 / portTICK_PERIOD_MS);   <- also tried with this one, though with 0 TX buffer it seems to be pointless
        
        // The fast part
        uart_set_baudrate(UART_NUM_2, 200000));
        uart_write_bytes(UART_NUM_2, (const char *) buffer, 5);        
}
Well, it seems that something is wrong here (I'm a newbie to this platform) as both bytes are in fact sent with the letter baudrate (200000). Could you please direct me what can be wrong here?

Who is online

Users browsing this forum: No registered users and 102 guests