M052LBN - UART테스트
M052LBN UART 특징
M0521은 2채널의 UART가 있다. 그리고 FIFO 있고.. RS485 9bit 모지원한다. 저렴한 MCU에서 지원은 좋은것 같다.
- Separate receive / transmit 16/16 bytes entry FIFO for data payloads
- hardware auto-flow control and flow control
- Supports RS-485 9-bit mode
- Supports hardware or software enable to program RTS pin to control RS-485 transmission direction directly
M052LBN UART 블록도
M052LBN UART 초기화 코드
void U0_Init(unsigned char baud)
{
SYS_UnlockReg();
/* Enable UART module clock */
CLK_EnableModuleClock(UART0_MODULE);
/* Select UART module clock source */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
/* Set P3 multi-function pins for UART0 RXD and TXD */
SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0);
/* Lock protected registers */
SYS_LockReg();
U0_SetBaud(baud);
}
M052LBN UART 송수신 함수
void U0_PutByte(unsigned char Data)
{
while((UART0->FSR & UART_FSR_TE_FLAG_Msk) == 0);
UART0->THR = Data;
}
unsigned char U0_GetByte(void)
{
while(UART0->FSR & UART_FSR_RX_EMPTY_Msk);
return UART0->RBR;
}
M052LBN RS485 기능