/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Unlock protected registers */ SYS->REGWRPROT = 0x59; SYS->REGWRPROT = 0x16; SYS->REGWRPROT = 0x88; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS->REGWRPROT = 0x0; /* Init UART0 for printf */ UART0_Init(); /* Init UART1 for testing */ UART1_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\n\nUART Sample Program\n"); /* UART RS485 sample slave function */ RS485_9bitModeSlave(); }
/*---------------------------------------------------------------------------------------------------------*/ void RS485_FunctionTest() { uint32_t u32Item; printf("\n\n"); printf("+-----------------------------------------------------------+\n"); printf("| IO Setting |\n"); printf("+-----------------------------------------------------------+\n"); printf("| ______ _______ |\n"); printf("| | | | | |\n"); printf("| |Master|---TXD1(pin46) <====> RXD1(pin45)---|Slave | |\n"); printf("| | |---RTS1(pin39) <====> RTS1(pin39)---| | |\n"); printf("| |______| |_______| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n\n"); printf("+-----------------------------------------------------------+\n"); printf("| RS485 Function Test |\n"); printf("+-----------------------------------------------------------+\n"); printf("| Please select Master or Slave test |\n"); printf("| [0] Master [1] Slave |\n"); printf("+-----------------------------------------------------------+\n\n"); u32Item = GetChar(); /* The sample code is used to test RS485 9-bit mode and needs two Module test board to complete the test. Master: 1.Set AUD mode and HW will control RTS pin. LEV_RTS is set to '0'. 2.Master will send four different address with 10 bytes data to test Slave. 3.Address bytes : the parity bit should be '1'. (Set UA_LCR = 0x2B) 4.Data bytes : the parity bit should be '0'. (Set UA_LCR = 0x3B) 5.RTS pin is low in idle state. When master is sending, RTS pin will be pull high. Slave: 1.Set AAD and AUD mode firstly. LEV_RTS is set to '0'. 2.The received byte, parity bit is '1' , is considered "ADDRESS". 3.The received byte, parity bit is '0' , is considered "DATA". (Default) 4.AAD: The slave will ignore any data until ADDRESS match ADDR_MATCH value. When RLS and RDA interrupt is happend,it means the ADDRESS is received. Check if RS485_ADD_DETF is set and read UA_RBR to clear ADDRESS stored in rx_fifo. NMM: The slave will ignore data byte until disable RX_DIS. When RLS and RDA interrupt is happend,it means the ADDRESS is received. Check the ADDRESS is match or not by user in UART_IRQHandler. If the ADDRESS is match,clear RX_DIS bit to receive data byte. If the ADDRESS is not match,set RX_DIS bit to avoid data byte stored in FIFO. */ if(u32Item =='0') RS485_9bitModeMaster(); else RS485_9bitModeSlave(); }