Hello,
I am attempting to use UART in 9-bit mode for our RS485 network. The following text is written in the chip's (LM4F232H5QC) datasheet:
■ EIA-485 9-bit support
All the slaves check for the address qualifier in the place of the parity bit and, if set, then compare the byte received with the preprogrammed address. If the address matches, then it receives or sends further data. If the address does not match, it drops the address byte and any subsequent data bytes. If the UART is in 9-bit mode, then the receiver operates with no parity mode.
So I enable the hardware feature and test the function with the following code (master and slave):
// ... ROM_UARTConfigSetExpClk(RS485_UART_BASE, ROM_SysCtlClockGet(), RS485_BAUD, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_ONE); UARTFIFOLevelSet(RS485_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); UARTIntEnable(RS485_UART_BASE, UART_INT_TX | UART_INT_RX | UART_INT_RT | UART_INT_9BIT); // Master address is 0x01,slave is 0x02 UART9BitAddrSet(RS485_UART_BASE, 0x01, 0xFF); UART9BitEnable(RS485_UART_BASE); // ... // Send the address byte to start a transmit UART9BitAddrSend(RS485_UART_BASE, 0x02); // Send packets in the interrupt function UARTCharPutNonBlocking(RS485_UART_BASE, data[i]);
I run the code, and block in the function UART9BitAddrSend():
void UART9BitAddrSend(unsigned long ulBase, unsigned char ucAddr) { unsigned long ulLCRH; // // Check the arguments. // ASSERT(UARTBaseValid(ulBase)); // // Wait until the FIFO is empty and the UART is not busy. // while(HWREG(ulBase + UART_O_FR) & (UART_FR_TXFE | UART_FR_BUSY)) {//#################### Block here, the logic seems to be error ######################## }//#################### UART_FR_TXFE bit set when FIFO is empty ######################## // // Force the address/data bit to 1 to indicate this is an address byte. // ulLCRH = HWREG(ulBase + UART_O_LCRH); HWREG(ulBase + UART_O_LCRH) = ((ulLCRH & ~UART_LCRH_EPS) | UART_LCRH_SPS | UART_LCRH_PEN); // // Send the address. // HWREG(ulBase + UART_O_DR) = ucAddr; // // Wait until the address has been sent. // while(HWREG(ulBase + UART_O_FR) & (UART_FR_TXFE | UART_FR_BUSY)) { } // // Restore the address/data setting. // HWREG(ulBase + UART_O_LCRH) = ulLCRH; }
I try to correct the mistake and send out the address byte. But the slave receive all bytes sent by master, includding the address byte, even if the address is NOT match!
My question is:
- Is something wrong in function UART9BitAddrSend() in StellarisWare library?
- How can I use UART in the hardware 9-bit mode? Some samples?
Thanks,
Kimec Shieh