/*---------------------------------------------------------------------------------------------------------*/ void RS485_9bitModeMaster() { volatile int32_t i32; uint8_t g_u8SendDataGroup1[10] = {0}; uint8_t g_u8SendDataGroup2[10] = {0}; uint8_t g_u8SendDataGroup3[10] = {0}; uint8_t g_u8SendDataGroup4[10] = {0}; printf("\n\n"); printf("+-----------------------------------------------------------+\n"); printf("| RS485 9-bit Master Test |\n"); printf("+-----------------------------------------------------------+\n"); printf("| The function will send different address with 10 data |\n"); printf("| bytes to test RS485 9-bit mode. Please connect TX/RX to |\n"); printf("| another board and wait its ready to receive. |\n"); printf("| Press any key to start... |\n"); printf("+-----------------------------------------------------------+\n\n"); GetChar(); /* Set RS485-Master as AUD mode */ /* Enable AUD mode to HW control RTS pin automatically */ /* You also can use GPIO to control RTS pin for replacing AUD mode*/ UART_SelectRS485Mode(UART1, UART_ALT_CSR_RS485_AUD_Msk, 0); /* Set RTS pin active level as high level active */ UART1->MCR &= ~UART_MCR_LEV_RTS_Msk; UART1->MCR |= UART_RTS_IS_HIGH_LEV_ACTIVE; /* Set TX delay time */ UART1->TOR = 0x2000; /* Prepare Data to transmit*/ for(i32 = 0; i32 < 10; i32++) { g_u8SendDataGroup1[i32] = i32; g_u8SendDataGroup2[i32] = i32 + 10; g_u8SendDataGroup3[i32] = i32 + 20; g_u8SendDataGroup4[i32] = i32 + 30; } /* Send different address and data for test */ printf("Send Address %x and data 0~9\n", MATCH_ADDRSS1); RS485_SendAddressByte(MATCH_ADDRSS1); RS485_SendDataByte(g_u8SendDataGroup1, 10); printf("Send Address %x and data 10~19\n", UNMATCH_ADDRSS1); RS485_SendAddressByte(UNMATCH_ADDRSS1); RS485_SendDataByte(g_u8SendDataGroup2, 10); printf("Send Address %x and data 20~29\n", MATCH_ADDRSS2); RS485_SendAddressByte(MATCH_ADDRSS2); RS485_SendDataByte(g_u8SendDataGroup3, 10); printf("Send Address %x and data 30~39\n", UNMATCH_ADDRSS2); RS485_SendAddressByte(UNMATCH_ADDRSS2); RS485_SendDataByte(g_u8SendDataGroup4, 10); printf("Transfer Done\n"); }
/*---------------------------------------------------------------------------------------------------------*/ void RS485_9bitModeMaster() { int32_t i32; uint8_t g_u8SendDataGroup1[10] ={0}; uint8_t g_u8SendDataGroup2[10] ={0}; uint8_t g_u8SendDataGroup3[10] ={0}; uint8_t g_u8SendDataGroup4[10] ={0}; printf("\n\n"); printf("+-----------------------------------------------------------+\n"); printf("| RS485 9-bit Master Test |\n"); printf("+-----------------------------------------------------------+\n"); printf("| The functin will send different address with 10d ata bytes|\n"); printf("| to test RS485 9-bit mode. Please connect TX/RX to another |\n"); printf("| board and wait its ready to receive. |\n"); printf("| Press any key to start... |\n"); printf("+-----------------------------------------------------------+\n\n"); GetChar(); /* Set RS485-Master as AUD mode*/ _UART_SEL_FUNC(UART1,UART_FUNC_SEL_RS485); UART1->ALT_CSR = UART_ALT_CSR_RS485_AUD_Msk; /* Enable AUD to HW control RTS pin automatically */ /* You alse can use GPIO to control RTS pin for replacing AUD mode*/ /* Prepare Data to transmit*/ for(i32=0;i32<10;i32++) { g_u8SendDataGroup1[i32] = i32; g_u8SendDataGroup2[i32] = i32+10; g_u8SendDataGroup3[i32] = i32+20; g_u8SendDataGroup4[i32] = i32+30; } /* Send For different Address and data for test */ printf("Send Address %x and data 0~9\n",MATCH_ADDRSS1); RS485_SendAddressByte( MATCH_ADDRSS1 ); RS485_SendDataByte(g_u8SendDataGroup1,10); printf("Send Address %x and data 10~19\n",UNMATCH_ADDRSS1); RS485_SendAddressByte( UNMATCH_ADDRSS1 ); RS485_SendDataByte(g_u8SendDataGroup2,10); printf("Send Address %x and data 20~29\n",MATCH_ADDRSS2); RS485_SendAddressByte( MATCH_ADDRSS2 ); RS485_SendDataByte(g_u8SendDataGroup3,10); printf("Send Address %x and data 30~39\n",UNMATCH_ADDRSS2); RS485_SendAddressByte( UNMATCH_ADDRSS2 ); RS485_SendDataByte(g_u8SendDataGroup4,10); printf("Transfer Done\n"); }
/*---------------------------------------------------------------------------------------------------------*/ void RS485_9bitModeMaster() { int32_t i32; uint8_t g_u8SendDataGroup1[10] = {0}; uint8_t g_u8SendDataGroup2[10] = {0}; uint8_t g_u8SendDataGroup3[10] = {0}; uint8_t g_u8SendDataGroup4[10] = {0}; printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| Pin Configure |\n"); printf("+-----------------------------------------------------------+\n"); printf("| _______ _______ |\n"); printf("| | | | | |\n"); printf("| |Master |---TXD1(P1.3) <====> RXD1(P1.2)---| Slave | |\n"); printf("| | |---RTS1(P0.1) <====> RTS1(P0.1)---| | |\n"); printf("| |_______| |_______| |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n"); /* 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 happened,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 happened,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. */ printf("\n"); printf("+-----------------------------------------------------------+\n"); printf("| RS485 Function Test (9-bit Master) |\n"); printf("+-----------------------------------------------------------+\n"); printf("| The function will send different address with 10 data bytes|\n"); printf("| to test RS485 9-bit mode. Please connect TX/RX to another |\n"); printf("| board and wait its ready to receive. |\n"); printf("| Press any key to start... |\n"); printf("+-----------------------------------------------------------+\n\n"); GetChar(); /* Select UART RS485 function mode */ UART1->FUN_SEL = UART_FUNC_SEL_RS485; /* Set RS485-Master as AUD mode */ /* Enable AUD mode to HW control RTS pin automatically */ /* You also can use GPIO to control RTS pin for replacing AUD mode*/ UART1->ALT_CSR = UART_ALT_CSR_RS485_AUD_Msk; /* Set RTS pin active level as low level active */ UART1->MCR = UART1->MCR & (~UART_MCR_LEV_RTS_Msk) | UART_RTS_IS_LOW_LEV_ACTIVE; /* Prepare Data to transmit*/ for(i32 = 0; i32 < 10; i32++) { g_u8SendDataGroup1[i32] = i32; g_u8SendDataGroup2[i32] = i32 + 10; g_u8SendDataGroup3[i32] = i32 + 20; g_u8SendDataGroup4[i32] = i32 + 30; } /* Send For different Address and data for test */ printf("Send Address %x and data 0~9\n", MATCH_ADDRSS1); RS485_SendAddressByte(MATCH_ADDRSS1); RS485_SendDataByte(g_u8SendDataGroup1, 10); printf("Send Address %x and data 10~19\n", UNMATCH_ADDRSS1); RS485_SendAddressByte(UNMATCH_ADDRSS1); RS485_SendDataByte(g_u8SendDataGroup2, 10); printf("Send Address %x and data 20~29\n", MATCH_ADDRSS2); RS485_SendAddressByte(MATCH_ADDRSS2); RS485_SendDataByte(g_u8SendDataGroup3, 10); printf("Send Address %x and data 30~39\n", UNMATCH_ADDRSS2); RS485_SendAddressByte(UNMATCH_ADDRSS2); RS485_SendDataByte(g_u8SendDataGroup4, 10); printf("\nTransfer Done\n"); }