The UART peripheral is used for serial communication over TX and RX pins.
More...
|
enum | uart_txpo_t { UART_TXPO_0 = 0
, UART_TXPO_2
, UART_TXPO_0_FLOW_CONTROL
, UART_TXPO_NONE = 0xff
} |
| UART transmit pinout options.
|
|
enum | uart_rxpo_t {
UART_RXPO_0 = 0
, UART_RXPO_1
, UART_RXPO_2
, UART_RXPO_3
,
UART_RXPO_NONE = 0xff
} |
| UART receive pinout options.
|
|
|
void | uart_init (uint32_t baud) |
| Initializes the UART peripheral for a board with a defined UART_SERCOM.
|
|
void | uart_enable (void) |
| Enables the UART peripheral for a board with a defined UART_SERCOM.
|
|
void | uart_set_run_in_standby (bool run_in_standby) |
| Sets whether the UART_SERCOM should run in standby mode.
|
|
void | uart_set_irda_mode (bool irda) |
| Sets IRDA mode for the UART_SERCOM.
|
|
void | uart_write (char *data, size_t length) |
| Writes data to the UART peripheral for a board with a defined UART_SERCOM.
|
|
size_t | uart_read (char *data, size_t max_length) |
| Reads data from the UART peripheral for a board with a defined UART_SERCOM.
|
|
bool | uart_read_byte (char *byte) |
| Reads a single byte from the UART peripheral for a board with a defined UART_SERCOM.
|
|
void | uart_disable (void) |
| Disables the UART peripheral for a board with a defined UART_SERCOM.
|
|
void | uart_init_instance (uint8_t sercom, uart_txpo_t txpo, uart_rxpo_t rxpo, uint32_t baud) |
| initializes a specific SERCOM UART instance.
|
|
void | uart_set_run_in_standby_instance (uint8_t sercom, bool run_in_standby) |
| Enables a specific SERCOM UART instance.
|
|
void | uart_set_irda_mode_instance (uint8_t sercom, bool irda) |
| Sets IRDA mode for a specific SERCOM instance.
|
|
void | uart_enable_instance (uint8_t sercom) |
| Enables a specific SERCOM UART instance.
|
|
void | uart_write_instance (uint8_t sercom, char *data, size_t length) |
| Writes data to a specific SERCOM UART instance.
|
|
size_t | uart_read_instance (uint8_t sercom, char *data, size_t max_length) |
| Reads data from a specific SERCOM UART instance.
|
|
bool | uart_read_byte_instance (uint8_t sercom, char *byte) |
| Reads a single byte from a specific SERCOM UART instance.
|
|
void | uart_disable_instance (uint8_t sercom) |
| Disables a specific SERCOM UART instance.
|
|
void | uart_irq_handler (uint8_t sercom) |
| UART IRQ handler.
|
|
The UART peripheral is used for serial communication over TX and RX pins.
Note that Gossaermer's UART implementation is interrupt-driven, which is different from the SPI and I2C peripherals. If you want to use the UART, you MUST implement the following function, replacing 'N' with the SERCOM number you are using: void irq_handler_sercomN(void) { uart_irq_handler(N); }
This interrupt handler will allow the UART to buffer incoming data to a FIFO, which is what you're actually reading from when you call uart_read
.
- Warning
- If you don't implement the interrupt handler, your application will hang, and you'll be confused until you read this line! (or in my case, write it)
◆ uart_disable_instance()
void uart_disable_instance |
( |
uint8_t |
sercom | ) |
|
Disables a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to disable. |
◆ uart_enable_instance()
void uart_enable_instance |
( |
uint8_t |
sercom | ) |
|
Enables a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to enable. |
◆ uart_init()
void uart_init |
( |
uint32_t |
baud | ) |
|
Initializes the UART peripheral for a board with a defined UART_SERCOM.
- Parameters
-
baud | The desired baud rate. |
◆ uart_init_instance()
initializes a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to initialize. |
txpo | The TX pinout. |
- See also
- uart_txpo_t
- Parameters
-
- See also
- uart_rxpo_t
- Parameters
-
baud | The desired baud rate |
◆ uart_irq_handler()
void uart_irq_handler |
( |
uint8_t |
sercom | ) |
|
UART IRQ handler.
Call this function from the IRQ handler for the UART SERCOM. For example, if you are using SERCOM5, you would do this: void irq_handler_sercom5(void) { uart_irq_handler(5); }
UART transmssion and reception are interrupt driven, and nothing will work if this function is not called.
- Parameters
-
◆ uart_read()
size_t uart_read |
( |
char * |
data, |
|
|
size_t |
max_length |
|
) |
| |
Reads data from the UART peripheral for a board with a defined UART_SERCOM.
- Parameters
-
data | The buffer to read into. |
max_length | The maximum number of bytes to read. |
- Returns
- The number of bytes read.
◆ uart_read_byte()
bool uart_read_byte |
( |
char * |
byte | ) |
|
Reads a single byte from the UART peripheral for a board with a defined UART_SERCOM.
- Parameters
-
- Returns
- true if a byte was read.
◆ uart_read_byte_instance()
bool uart_read_byte_instance |
( |
uint8_t |
sercom, |
|
|
char * |
byte |
|
) |
| |
Reads a single byte from a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to use. |
byte | The byte read. |
- Returns
- true if a byte was read.
◆ uart_read_instance()
size_t uart_read_instance |
( |
uint8_t |
sercom, |
|
|
char * |
data, |
|
|
size_t |
max_length |
|
) |
| |
Reads data from a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to use. |
data | The buffer to read into. |
max_length | The maximum number of bytes to read. |
- Returns
- The number of bytes read.
◆ uart_set_irda_mode()
void uart_set_irda_mode |
( |
bool |
irda | ) |
|
Sets IRDA mode for the UART_SERCOM.
- Parameters
-
irda | true if the UART should run in IRDA mode. |
◆ uart_set_irda_mode_instance()
void uart_set_irda_mode_instance |
( |
uint8_t |
sercom, |
|
|
bool |
irda |
|
) |
| |
Sets IRDA mode for a specific SERCOM instance.
- Parameters
-
sercom | The SERCOM instance to configure. |
irda | true if the UART should run in IRDA mode. |
◆ uart_set_run_in_standby()
void uart_set_run_in_standby |
( |
bool |
run_in_standby | ) |
|
Sets whether the UART_SERCOM should run in standby mode.
- Parameters
-
run_in_standby | true if the UART should run in standby mode. |
◆ uart_set_run_in_standby_instance()
void uart_set_run_in_standby_instance |
( |
uint8_t |
sercom, |
|
|
bool |
run_in_standby |
|
) |
| |
Enables a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to enable. |
◆ uart_write()
void uart_write |
( |
char * |
data, |
|
|
size_t |
length |
|
) |
| |
Writes data to the UART peripheral for a board with a defined UART_SERCOM.
- Parameters
-
data | The data to write. |
length | The number of bytes to write. |
◆ uart_write_instance()
void uart_write_instance |
( |
uint8_t |
sercom, |
|
|
char * |
data, |
|
|
size_t |
length |
|
) |
| |
Writes data to a specific SERCOM UART instance.
- Parameters
-
sercom | The SERCOM instance to use. |
data | The data to write. |
length | The number of bytes to write. |