Professional Documents
Culture Documents
June 2016
Agenda
• UART Feature
• UART Block Diagram
• UART Baud Rate Setting
• UART Auto Flow Control Function
• RS-485 Function Mode
• LIN Function Mode
• Functions and Sample Code in BSP
• Sample Code
2
UART Feature
• Up to 3 fully programmable UART channels
• Programmable baud-rate generator.
• Programmable serial-interface.
• Entry FIFO for Tx/Rx data payloads.
(UART0/UART1/UART264/16/16 bytes)
• Support auto flow control function (nCTS, nRTS) ) in UART0 and UART1.
• Support IrDA SIR function mode
• Support RS-485 function mode
• Support LIN function.
3
UART Block Diagram
APB_BUS
UART_CLK
IrDA Encode IrDA Decode
UART0_EN(APBCLK[16])
22.1184 MHz
11
UART0_CLK
10
1/(UART_N + 1)
PLL FOUT
01
UART_N(CLKDIV[11:8])
4~24 MHz
00
UART1_EN(APBCLK[17]) UART1_CLK
UART2_EN(APBCLK[18]) UART2_CLK
User can easy generate standard baud-rate via 22.1184 MHz clock source
Supported Baud rates are
5
4800,9600,19200,38400,57600,115200,230400,460800,921600
UART Baud Rate Setting(1/2)
• Fully programmable serial interface
Even, odd or no-parity
5 ~ 8bits 1 ~ 2bits
• Baud-rate generator
6
UART Baud Rate Setting(2/2)
System source = 22.1184MHz
Baud rate Mode0 Mode1 Mode2
921600 x A=0,B=11 A=22
A=1,B=15
460800 A=1 A=2,B=11 A=46
A=4,B=15
230400 A=4 A=6,B=11 A=94
A=10,B=15
115200 A=10 A=14,B=11 A=190
A=22,B=15
57600 A=22 A=30,B=11 A=382
A=62,B=8
A=46,B=11
38400 A=34 A=34,B=15 A=574
A=126,B=8
A=94,B=11
19200 A=70 A=70,B=15 A=1150
A=254,B=8
A=190,B=11
9600 A=142 A=142,B=15 A=2302
A=510,B=8
A=382,B=11 7
4800 A=286 A=286,B=15 A=4606
UART Auto Flow Control Function
Tx FIFO
/CTS
Flow Control /RTS
Chip 2
BUS
RX
Serial to Parallel TX
Rx FIFO
/RTS
Flow Control /CTS
9
LIN Function Mode
• Support LIN master/slave node mode
• LIN header selection
- Break field + Sync field + Identifier field
• LIN break field count setting (master only)
- 8-bits ~ 15-bits
• Support LIN header and bit error detect interrupt
Frame slot
Frame
Response Inter-
space frame
Header Response space
NUC029xEE_BSP_v3.00.001
NUC029 Series
Document Driver Reference Guide
SampleCode
StdDriver
UART_TxRx_Function
UART_TxRx_Function.uvproj
KEIL
11
Functions and Sample Code in BSP- Revised
• uart.c
- uint32_t UART_Open(UART_T* uart, uint32_t u32baudrate)
Open and set UART function
- uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes)
Read UART data
- uint32_t UART_Write(UART_T* uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
Write UART data
• system_NUC029xEE.h
- # define DEBUG_PORT UART0
Change default printf port
12
Functions and Sample Code in BSP
• \SampleCode\StdDriver
- UART_Autoflow_Master - UART_IrDA_Master
- UART_Autoflow_Slave - UART_IrDA_Slave
- UART_PDMA - UART_LIN
- UART_TxRxFunction - UART_RS485_Master
- UART_Wakeup - UART_RS485_Slave
13
UART Sample Code
int main (void)
{
……
/* Configure UART0 and set UART0 baud rate */
UART_Open(UART0, 115200);
/* Enable Interrupt and install the call back function */
UART_EnableInt(UART0, (UART_IER_RDA_IEN_Msk | UART_IER_THRE_IEN_Msk | UART_IER_TOUT_IEN_Msk));
NVIC_EnableIRQ(UART02_IRQn);
……
while(1);
}
void UART02_IRQHandler(void)
{
UART_WRITE(UART0, UART_READ(UART0));
}
14
UART Sample Code
int SYS_Init(void)
{
……
/* Enable UART module clock */
CLK_EnableModuleClock(UART0_MODULE);
/* Select UART module clock source as HIRC and UART module clock divider as 1 */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HIRC, CLK_CLKDIV0_UART(1));
15
Thank you!