The USART driver provides the interface to configure and use the USART peripheral.
The USART supports several kinds of comminication modes such as full-duplex asynchronous/ synchronous serial commnunication,RS485 with driver control signal,ISO7816,SPI and Test modes.
To start a USART transfer with PDC support, the user could follow these steps:
-
Configure USART with expected mode and baudrate(see USART_Configure), which could be done by:
- Resetting and disabling transmitter and receiver by setting US_CR(Control Register).
- Conifguring the USART in a specific mode by setting USART_MODE bits in US_MR(Mode Register)
- Setting baudrate which is different from mode to mode.
-
Enable transmitter or receiver respectively by set US_CR_TXEN or US_CR_RXEN in US_CR.
-
Read from or write to the peripheral with USART_ReadBuffer or USART_WriteBuffer. These operations could be done by polling or interruption.
-
For polling, check the status bit US_CSR_ENDRX/US_CSR_RXBUFF (READ) or US_CSR_ENDTX/ US_CSR_TXBUFE (WRITE).
-
For interruption,"enable" the status bit through US_IER and realize the hanler with USARTx_IrqHandler according to IRQ vector table which is defined in board_cstartup_<toolchain>.c To enable the interruption of USART,it should be configured with priority and enabled first through NVIC .
For more accurate information, please look at the USART section of the Datasheet.
Related files :
usart.c
usart.h