GlobLib
HAL and API libraries for MCUs and hardware.
|
This module contains low level functions for USART interaction. More...
Files | |
file | stm32f103cb_usart.h |
Header file for stm32f103cb USART. | |
Macros | |
#define | USART_DEFAULT_BAUD USART_BAUD_9600 |
The default baud rate used by setup function. | |
#define | USART_DEFAULT_STOP USART_STOP_ONE |
The default stop bits used by setup function. | |
#define | USART_DEFAULT_DATA USART_DATA_EIGHT |
The default data frame used by setup function. | |
#define | USART_DEFAULT_PARITY USART_PARITY_NONE |
The default parity used by setup function. | |
Typedefs | |
typedef void(* | v_fp_u8) (uint8_t) |
Function pointer typedef for void function with uint8_t parameter. | |
Enumerations |
Functions | |
mcu_error | USART_setup (usart_periph peripheral) |
Initialize USART port. More... | |
mcu_error | USART_setBaud (usart_periph peripheral, usart_baud baud) |
Set the baud rate for the port. More... | |
v_fp_u8 | USART_add_put (usart_periph peripheral) |
Return the address of the peripheral put function. More... | |
mcu_error | USART_put (usart_periph peripheral, uint8_t byte) |
Send a byte on the given peripheral. More... | |
uint8_t | USART_get (usart_periph peripheral) |
Get a byte on the given peripheral (blocking). More... | |
mcu_error | USART_setStop (usart_periph peripheral, usart_stop stopBits) |
Set the number of stop bits for the port. More... | |
mcu_error | USART_setParity (usart_periph peripheral, usart_parity parity) |
Set the parity for the port. More... | |
mcu_error | USART_setData (usart_periph peripheral, usart_data data) |
Set the data frame size for the port. More... | |
mcu_error | USART_setRxISR (usart_periph peripheral, void(*new_handler)(uint8_t received)) |
Sets the target function called when recieve ISR is triggered. More... | |
mcu_error | USART_setTxISR (usart_periph peripheral, void(*new_handler)(void)) |
Sets the target function called when transmit ISR is triggered. More... | |
mcu_error | USART_enableISR (usart_periph peripheral, usart_isr isr_type) |
Enables the specified ISR function. More... | |
mcu_error | USART_disableISR (usart_periph peripheral, usart_isr isr_type) |
Disables the specified ISR function. More... | |
This module contains low level functions for USART interaction.
The USART peripherals are mapped to the following pins for the ports
Any USART data structure created needs to be initialized with USART_setup(), this function initializes the given usart peripheral with the following parameters
enum usart_baud |
Baud rate options for the port.
These value are utilised with function USART_setBaud()
Definition at line 122 of file stm32f103cb_usart.h.
enum usart_data |
Data frame lengths for the port.
These values are utilised with function USART_setData()
Enumerator | |
---|---|
USART_DATA_EIGHT |
Eight bit data frame for the port. |
USART_DATA_NINE |
Nine bit data frame for the port. |
Definition at line 112 of file stm32f103cb_usart.h.
enum usart_isr |
ISR values for the port.
These values are utilised with function USART_enableISR() and USART_disableISR()
Enumerator | |
---|---|
USART_TX |
Transmit ISR. |
USART_RX |
Recieve ISR. |
Definition at line 137 of file stm32f103cb_usart.h.
enum usart_parity |
Parity option available for the port.
These values are utilised with function USART_setParity()
Enumerator | |
---|---|
USART_NONE |
No parity for the port. |
USART_ODD |
Odd parity for the port. |
USART_EVEN |
Even parity for the port. |
Definition at line 91 of file stm32f103cb_usart.h.
enum usart_periph |
Peripheral ports available on the MCU.
These values are used with function USART_setup()
Enumerator | |
---|---|
USART_1 |
First peripheral port. |
USART_2 |
Second peripheral port. |
USART_3 |
Third peripheral port. |
Definition at line 79 of file stm32f103cb_usart.h.
enum usart_stop |
Stop bit options available for the port.
These values are utilised with function USART_setStop()
Enumerator | |
---|---|
USART_STOP_ONE |
One stop bit for the port. |
USART_STOP_TWO |
Two stop bits for the port. |
Definition at line 102 of file stm32f103cb_usart.h.
v_fp_u8 USART_add_put | ( | usart_periph | peripheral | ) |
Return the address of the peripheral put function.
peripheral | The USART peripheral to get. |
Definition at line 860 of file stm32f103cb_usart.c.
mcu_error USART_disableISR | ( | usart_periph | peripheral, |
usart_isr | isr_type | ||
) |
Disables the specified ISR function.
By default, ISRs are enabled. This can be used to disable them.
peripheral | The USART peripheral to modify. |
isr_type | The type of ISR to change, define by usart_isr |
Definition at line 1047 of file stm32f103cb_usart.c.
mcu_error USART_enableISR | ( | usart_periph | peripheral, |
usart_isr | isr_type | ||
) |
Enables the specified ISR function.
peripheral | The USART peripheral to modify. |
isr_type | The type of ISR to change, define by usart_isr |
Definition at line 1136 of file stm32f103cb_usart.c.
uint8_t USART_get | ( | usart_periph | peripheral | ) |
Get a byte on the given peripheral (blocking).
peripheral | The usart number to send on. |
Definition at line 891 of file stm32f103cb_usart.c.
mcu_error USART_put | ( | usart_periph | peripheral, |
uint8_t | byte | ||
) |
Send a byte on the given peripheral.
peripheral | The usart number to send on. |
byte | The byte to send. |
Definition at line 826 of file stm32f103cb_usart.c.
mcu_error USART_setBaud | ( | usart_periph | peripheral, |
usart_baud | baud | ||
) |
Set the baud rate for the port.
peripheral | The USART peripheral to modify. |
baud | Baud rate defined by usart_baud to be used. |
Definition at line 250 of file stm32f103cb_usart.c.
mcu_error USART_setData | ( | usart_periph | peripheral, |
usart_data | data | ||
) |
Set the data frame size for the port.
peripheral | The USART peripheral to modify. |
data | Data frame size as define in in usart_data. |
Definition at line 565 of file stm32f103cb_usart.c.
mcu_error USART_setParity | ( | usart_periph | peripheral, |
usart_parity | parity | ||
) |
Set the parity for the port.
peripheral | The USART peripheral to modify. |
parity | Parity option defined in usart_parity. |
Definition at line 687 of file stm32f103cb_usart.c.
mcu_error USART_setRxISR | ( | usart_periph | peripheral, |
void(*)(uint8_t received) | new_handler | ||
) |
Sets the target function called when recieve ISR is triggered.
The recieve ISR is called when a byte is ready to be read in the receive buffer.
By default, the ISR flag is cleared first then the function specified by this pointer is called.
If no function has been specified this pointed to NULL.
The function specified must be of this type.
peripheral | The USART peripheral to modify. |
new_handler | Address of the function for the ISR to point to. |
Definition at line 983 of file stm32f103cb_usart.c.
mcu_error USART_setStop | ( | usart_periph | peripheral, |
usart_stop | stopBits | ||
) |
Set the number of stop bits for the port.
peripheral | The USART peripheral to modify. |
stopBits | Number of stop bits to use defined in usart_stop. |
Definition at line 443 of file stm32f103cb_usart.c.
mcu_error USART_setTxISR | ( | usart_periph | peripheral, |
void(*)(void) | new_handler | ||
) |
Sets the target function called when transmit ISR is triggered.
The transmit ISR is called when a byte has finished being sent from the buffer.
By default, the ISR flag is cleared first then the function specified by this pointer is called.
If no function has been specified this pointed to NULL.
The function specified must be of this type.
peripheral | The USART peripheral to modify. |
new_handler | Address of the function for the ISR to point to. |
Definition at line 1015 of file stm32f103cb_usart.c.
mcu_error USART_setup | ( | usart_periph | peripheral | ) |
Initialize USART port.
This must be called before any other feature is used.
This sets up the given USART peripheral to the default macro defined settings.
peripheral | The USART peripheral to modify. |
Definition at line 79 of file stm32f103cb_usart.c.