mikroSDK Reference Manual
|
UART Hardware Abstraction Layer API Reference. More...
Functions list | |
void | hal_uart_configure_default (hal_uart_config_t *config) |
Configure UART configuration structure with default values. More... | |
err_t | hal_uart_open (handle_t *handle, bool hal_obj_open_state) |
Open the UART HAL layer object on selected pins. More... | |
err_t | hal_uart_set_baud (handle_t *handle, hal_uart_config_t *config) |
Set the UART baud rate. More... | |
err_t | hal_uart_set_parity (handle_t *handle, hal_uart_config_t *config) |
Set the UART parity. More... | |
err_t | hal_uart_set_stop_bits (handle_t *handle, hal_uart_config_t *config) |
Set the number of UART stop bits. More... | |
err_t | hal_uart_set_data_bits (handle_t *handle, hal_uart_config_t *config) |
Set the number of UART data bits. More... | |
void | hal_uart_set_blocking (handle_t *handle, bool blocking) |
Set UART HAL in blocking/non-blocking mode. More... | |
size_t | hal_uart_write (handle_t *handle, uint8_t *buffer, size_t size) |
Write data to UART. More... | |
size_t | hal_uart_print (handle_t *handle, char *text) |
Print the string to UART. More... | |
size_t | hal_uart_println (handle_t *handle, char *text) |
Print the string to UART and append new line. More... | |
size_t | hal_uart_read (handle_t *handle, uint8_t *buffer, size_t size) |
Read data from UART. More... | |
size_t | hal_uart_bytes_available (hal_uart_t *hal_obj) |
Check number of data available to read. More... | |
void | hal_uart_clear (hal_uart_t *hal_obj) |
Discard all characters from UART buffers. More... | |
err_t | hal_uart_close (handle_t *handle) |
Close UART HAL layer object. More... | |
API for configuring and manipulating UART HAL module.
void hal_uart_configure_default | ( | hal_uart_config_t * | config | ) |
Configures structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
[in,out] | config | UART HAL layer configuration structure. See hal_uart_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
---|---|
Tx pin | HAL_PIN_NC (invalid pin) |
Rx pin | HAL_PIN_NC (invalid pin) |
Baud rate | 115200 |
Data bits | 8 data bits |
Parity | no parity |
Stop bits | 1 stop bit |
Tx buffer | cleared |
Rx buffer | cleared |
Tx ring buffer size | zero |
Rx ring buffer size | zero |
Example
err_t hal_uart_open | ( | handle_t * | handle, |
bool | hal_obj_open_state | ||
) |
Function opens the UART HAL layer object on selected pins and allocates memory needed for UART module, pins and ring buffers for specified object. Also, initializes interrupts on the global level.
[in,out] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | hal_obj_open_state | UART state, is it open or not. |
Example
err_t hal_uart_set_baud | ( | handle_t * | handle, |
hal_uart_config_t * | config | ||
) |
Initializes module on the hardware level and sets the baud rate to specified config->baud
value.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | config | UART HAL config structure. See hal_uart_config_t structure definition for detailed explanation. |
Example
err_t hal_uart_set_parity | ( | handle_t * | handle, |
hal_uart_config_t * | config | ||
) |
Sets parity on hardware level based on config->parity
value.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | config | UART HAL config structure. |
Example
err_t hal_uart_set_stop_bits | ( | handle_t * | handle, |
hal_uart_config_t * | config | ||
) |
Sets stop bits on hardware level based on config->stop_bits
value.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | config | UART HAL config structure. |
Example
err_t hal_uart_set_data_bits | ( | handle_t * | handle, |
hal_uart_config_t * | config | ||
) |
Sets data bits on hardware level based on config->data_bits
value.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | config | UART HAL config structure. |
Example
void hal_uart_set_blocking | ( | handle_t * | handle, |
bool | blocking | ||
) |
Sets the UART HAL to work in blocking/non-blocking mode.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | blocking | true for blocking mode, false for non-blocking mode. |
Example
size_t hal_uart_write | ( | handle_t * | handle, |
uint8_t * | buffer, | ||
size_t | size | ||
) |
Writes at most size
bytes of data from buffer
to the device.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | buffer | Array containing data to be written. |
[in] | size | Number of bytes to be written. |
Example
size_t hal_uart_print | ( | handle_t * | handle, |
char * | text | ||
) |
Print the string pointed to by text.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | text | Pointer to text array. |
Example :
size_t hal_uart_println | ( | handle_t * | handle, |
char * | text | ||
) |
Print the string pointed to by text and append new line at the end.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[in] | text | Pointer to text array. |
Example
size_t hal_uart_read | ( | handle_t * | handle, |
uint8_t * | buffer, | ||
size_t | size | ||
) |
Reads at most size
bytes of data from the device into buffer
.
[in] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
[out] | buffer | Array to place read data in. |
[in] | size | Number of bytes to be written. |
Example
size_t hal_uart_bytes_available | ( | hal_uart_t * | hal_obj | ) |
Check number of data available to read.
[in] | hal_obj | UART HAL object. See hal_uart_t structure definition for detailed explanation. |
Example
void hal_uart_clear | ( | hal_uart_t * | hal_obj | ) |
Discards all characters from the output and input buffer.
[in] | hal_obj | UART HAL object. See hal_uart_t structure definition for detailed explanation. |
Example
err_t hal_uart_close | ( | handle_t * | handle | ) |
Closes UART HAL layer object, disables all interrupts, resets pin AF to default values, clears all buffers used by object and disables module clock for lower power consumption.
[in,out] | handle | UART handle. See hal_uart_t structure definition for detailed explanation. |
Example