FlexIO UART Modbus RTU RS485

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FlexIO UART Modbus RTU RS485

1,374 Views
dvalerio
Contributor II

Hi!

Can anyone helpe me to fix a problem i am having with FlexIO UART Modbus RTU RS485?

I have problems with the transmit routine. After writting all characters with FLEXIO_UART_WriteByte, I disable the Tx interrupt using FLEXIO_UART_DisableInterrupts. After that, I clear the control pin for the RS485. But this action makes my response frame gets 0xFF or 0xFE in the last transmitted byte, instead the correct value.

Hope somebody could help me.

Thanks.

0 Kudos
3 Replies

1,130 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Diego Valerio,

    If you don't add the RS485 enable pin, just use the FlexIO UART, whether you have the problems or not?

   Could you also share some test code, and the correct transmitted byte and the wrong transmitted frame?

    BTW, please let me know your kinetis partnumber, then I can help you to check the details.

  


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,130 Views
dvalerio
Contributor II

Hi Kerry.

Without the RS485, Modbus works fine, without problem. The problem appears when I clear the pin after finishing the transmition.

Here is the interruption code for the transmition:

void Slave_TxChar_ISRF(void) {

if(contadorTX != 0) {                   //¿Is there data to transmit?
*bufferTX_ptr++ = 0;                   
contadorTX--;

FLEXIO_UART_WriteByte(&uartDev, bufferTX_ptr);          //Sends next byte
}

else if (contadorTX == 0) {            //¿Was all the data transmited?
*bufferTX_ptr++ = 0;
bufferTX_ptr = &bufferTX[0];

FLEXIO_UART_DisableInterrupts(&uartDev, kFLEXIO_UART_TxDataRegEmptyInterruptEnable);

GPIO_PortClear(FLEXIO_Control_RS485_GPIO, 1<<FLEXIO_Control_RS485_PIN);             //Clear RS485 Control Pin

}
}

Here are the correct transmitted frame and the wrong transmitted frame:

01 03 02 00 00 B8 44         --> Correct

01 03 02 00 00 B8 FE        --> Incorrect

The kinetis part number is : MKE14F512VLH16.

Good day,

Diego.

0 Kudos

1,130 Views
mjbcswitzerland
Specialist V

Diego

Have you measured when the last Tx interrupt arrives? Usually it is when there is space in the output FIFO but still data in the output register and so if you remove the RTS line then it will stop the last byte being sent onto the RS485 bus correctly - this may well then look like 0xfe or 0xff because only the start and possibly first data bit are sent out.

In comparison to the UARTs in the Kinetis, there are the TX buffer empty interrupt and the transmit complete interrupts. The first is used to transfer the next data byte and cannot be used to control a RS485 direction output because it is too early. The second (firing when the stop bit of the last byte has been sent) is suitable for this control.

Regards

Mark