This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I intend to use my controller in a half duplex system. I have a GPIO20 connected to the direction control of the RS485 interface IC.
At all times the GPIO20 is output 0 indicating RX state. Only when I want to send something over RS485 network, I set the GPIO20 to switch to TX state.
I am unable to understand, how should I ensure completion of transmission before resetting the GPIO20 pin.
I tried polling:
int RS232_Send(char *buf) { int a = 0; GpioDataRegs.GPASET.bit.GPIO20 = 1; while ((buf[a] != 0) && (SciaRegs.SCIRXST.bit.RXERROR != 1)) { if (SciaRegs.SCIFFTX.bit.TXFFST < 4) { SciaRegs.SCITXBUF = buf[a++]; } } while (SciaRegs.SCIFFTX.bit.TXFFINT == 0); GpioDataRegs.GPACLEAR.bit.GPIO20 = 1; if (SciaRegs.SCIRXST.bit.RXERROR == 1) { // if there is an error reset the SCI RS232_Reset(); GpioDataRegs.GPACLEAR.bit.GPIO20 = 1; return 1; } return 0; }
I tried using interrupt method
int RS232_Send(char *buf) { int a = 0; GpioDataRegs.GPASET.bit.GPIO20 = 1; while ((buf[a] != 0) && (SciaRegs.SCIRXST.bit.RXERROR != 1)) { if (SciaRegs.SCIFFTX.bit.TXFFST < 4) { SciaRegs.SCITXBUF = buf[a++]; } } SciaRegs.SCIFFTX.bit.TXFFIENA = 1; if (SciaRegs.SCIRXST.bit.RXERROR == 1) { // if there is an error reset the SCI RS232_Reset(); GpioDataRegs.GPACLEAR.bit.GPIO20 = 1; return 1; } return 0; } __interrupt void tx_comp(void){ GpioDataRegs.GPACLEAR.bit.GPIO20 = 1; SciaRegs.SCIFFTX.bit.TXFFINTCLR = 1; SciaRegs.SCIFFTX.bit.TXFFIENA = 0; PieCtrlRegs.PIEACK.all = PIEACK_GROUP9; }
In both the above cases the GPIO20 is cleared well before the last character in the transmit string, as a result last 2 or 3 characters are not received by the RS485 device.
Please let me know any other method which will ensure a total transmission completion and then turn off the GPIO20.
hi Soham,
You could use the below registers to check the status of communication and then turn off the GPIO20:
SCICTL2->TXEMPTY : if tx has nothing to send
SCICTL2-> TXRDY : If SCITXBUF is full or not
If using FIFOs:
SCIFFTX-> TXFFIL : Level of FIFO
In case if you wish to use RX as an identifier
SCIRXST-> RXRDY : No new character in SCIRXBUF or not
If using FIFOs: : SCIFFRX->RXFFST : Level of FIFO
Regards.
Thank you Meghana,
I tried checking the SCICTL2.TXEMPTY status and SCICTL2.TXRDY status.
Both are not working. Resetting the TX pin while checking the status of above bits, resets it well before the last byte. The number of bytes being missed is also not constant.
I found the following post which is similar to my application.
http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/412155?RS485-TX-ENABLE-signal
It seems TI recommends to use a timer and set it according to the time taken for a complete transmission after TXRDY is set.
I wanted to avoid using the main timer or ePWM. So I have setup a 'for' loop with assembly instructions to wait till all the bytes are transmitted and reset the TX enable pin.
Regards
Hello Meghana,
As I mentioned in the previous post and in reference to the link I have shared, I did not come across any kind of flag which denotes a total end of transmission. Hence through empirical data, I set a 'for' loop with assembly instructions (__NOP) where controller just 'waits' and then turns off the transmission bit on RS485 hardware.
Thank you for following up.