UART

Last Updated on : 2022-11-24 09:20:20

API list

Function name Description
user_uart_init UART initialization. Configure UART parameters and register the receive callbacks.
user_uart_send UART transmits data.
user_uart_disbale Disable the UART.

API description

user_uart_init

Function prototype

void user_uart_init(user_uart_config_t *config);

Parameter description

Parameter name Parameter type Description
*config user_uart_config_t The values in the user_uart_config_t enum.

user_uart_send

Function prototype

void user_uart_send(UART_ID_T uart_id, uint8_t* data, uint16_t data_len);

Parameter description

Parameter name Parameter type Description
uart_id UART_ID_T The values in the UART_ID_T enum, indicating the UART number.

user_uart_disbale

Function prototype

void user_uart_disbale(UART_ID_T uart_id);

Parameter description

Parameter name Parameter type Description
uart_id UART_ID_T The values in the UART_ID_T enum, indicating the UART number.

Usage description

hal_uart.h contains interface definition. Pay attention to when a function can be called, which might be during or after dev_system_on_init. Here is an example of function calls.

static void __uart_rx_callback(uint8_t *data, uint16_t len)
{
    // TODO: The UART receive handler. This callback is not run in an interrupt environment.
}
 
static void uart_demo(void)
{
    user_uart_config_t uart_cfg = TYZS3_USART_CONFIG_DEFAULT; /// The default UART configuration of TYZS3 modules.
 
    uart_cfg.func = __uart_rx_callback; /// Populate it with the UART receive callback.
    user_uart_init(&uart_cfg);
    
    uint8_t test_data[2] = {0x01, 0x02};
    user_uart_send(UART_ID_UART0, test_data, sizeof(test_data)); /// The UART transmits data.
    
}