uart_init, passing in an uart_config_t struct. This struct defines the RX/TX pins, the baud rate, and the rx/write_done callbacks.
uart_init
config argument defines the pins, configuration, and callbacks for the UART device. It contains the following fields:
pin_t
The RX pin (or
NO_PIN to disable RX)pin_t
The TX pin (or
NO_PIN to disable TX)uint32_t
The baud rate (e.g. 115200)
callback
Called for each byte received on the RX pin
callback
Called when data transmission on the TX pin has finished
void *
Data that will be passed in the first argument of the callbacks
rx_data, write_done) are optional. They all use the user_data pointer as their first argument.
Example
uart_write
count bytes from the memory pointed to by buffer to the given uart device.Returns
true on success, or false if the UART device is already busy transmitting data from a previous uart_write call (and the new data won’t be transmitted).
The data starts transmitting after uart_write returns. Once Wokwi finishes transmitting the data, the write_done callback is called (from the uart_config_t structure that you passed to uart_init).