Can i communicate rs485 via UART with FRDM-k64F?

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

Can i communicate rs485 via UART with FRDM-k64F?

2,856 Views
pauferrer
Contributor II

Hello guys,
I've been trying to communicate with a slave device using FRDM-k64F via UART2, i have already configured the pins so they act like tx/rx , also configured the baud rate and have MX485 beetwen the board and the slave.

136317_136317.pngpastedImage_2.png

 

I'm really new using these kind of boards and software, i've done the tutorial like 2 days ago.
I'm attaching my project so you can have a look at it. Please if you see i'm doing it wrong a little advice or guidance would be much appreciated
If it is not possible to do a No will do it.

Original Attachment has been moved to: Prova.rar

0 Kudos
6 Replies

1,491 Views
mjbcswitzerland
Specialist V

Hi

The K64 supports automatic RTS control for RS485.

This requires the TXRTSE bit to be set in the UARTx_MODEM register and the polarity of the output can also be controlled by TXRTSPOL bit.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html

UARTs: http://www.utasker.com/docs/uTasker/uTaskerUART.PDF

K64: http://www.utasker.com/kinetis/FRDM-K64F.html / http://www.utasker.com/kinetis/TWR-K64F120M.html / http://www.utasker.com/kinetis/TWR-K65F180M.html

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

1,491 Views
pauferrer
Contributor II

Thanks for your reply Mark :smileyhappy:

As i said before i'm really new a this, can you please tell me where i have to go to set those bits?

0 Kudos

1,491 Views
isaacavila
NXP Employee
NXP Employee

Hello Pau,

As Mark already told you, K64F has its own hardware control over these signals (RTS and CTS), so you only need to configure UARTx_MODEM register as you need.

If you are using PEx, you can use UART_HAL_xxx functions to enable/disable RTS and CTS functionality. In your fsl_uart component, you can find HAL functions and there are some related to RTS and CTS:

UART.jpg

These functions allows to configure MODEM register. For example, if you desire to configure RTS with high polarity, you can call:

  UART_HAL_SetTransmitterRtsPolarityMode(UART2_BASE_PTR,true); /* true = high polarity , false = low polarity*/

  UART_HAL_SetTransmitterRtsCmd(UART2_BASE_PTR, true);

Also, you can enable Clear-to-Send functionality on transmitter and/or RTS on receiver.

You can also check fsl_uart_hal.h file for more reference on this HAL functions.

I hope this can help you!

Best Regards,

Isaac

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------

1,491 Views
pauferrer
Contributor II

Hi Isaac,


That was quite helpful, I feel closer to get it working now :smileyhappy:


Can i ask for some advice on how to use the UART_DRV_SendData() and UART_DRV_ReceiveData()? I tried to send an order to my slave by sending one by one the bytes of the chain with these commands but didn't get any response. (I was looking for the response at the terminal)

0 Kudos

1,491 Views
isaacavila
NXP Employee
NXP Employee

Hello Pau,

If you look at KSDK examples, you will see some uart examples for FRDM-K64F (C:\Freescale\KSDK_1.3.0\examples\frdmk64f\driver_examples\uart) and in every example, you can see how these uart functions are used in order to achieve blocking communication, non-blocking or also using DMA.

For example, in uart_non_blocking project, you can see that UART_DRV_SendData is used to write data to terminal:

    const uint8_t bufferData1[] = "\r\nType characters from keyboard, the board will receive and then echo them to terminal screen\r\n";  

    // Inform user of what to do

    byteCountBuff = sizeof(bufferData1);

    UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, bufferData1, byteCountBuff);

    // Wait until transmission is finished

    while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}

And for receiving data, it is used:

     // Call received API

     UART_DRV_ReceiveData(BOARD_DEBUG_UART_INSTANCE, &rxChar, 1u);

while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}

    

For more details, you can analyze further these examples.

I hope this can help you!

Best Regards,

Isaac

1,491 Views
mjbcswitzerland
Specialist V

Hi Pau

In the uTasker K64 project you can do it like this:

SerialHandle = fnOpen(TYPE_TTY, FOR_I_O, &tInterfaceParameters); // configure and open the serial interface
fnDriver(SerialHandle, (TX_ON | RX_ON), 0);                      // enable rx and tx
fnDriver(SerialHandle, (MODIFY_CONTROL | CONFIG_RTS_PIN | SET_RS485_MODE | SET_RTS), 0); // configure positive RS485 mode with RTS initially at 0

If you need to use PE you will need to work out whether it supports RS485 mode or add the hardware access in your own code by following 52.3.14 in the K64 user's manual.

Regards

Mark

0 Kudos