Fx3 uart half-duplex

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
E_521156
Level 4
Level 4
100 sign-ins 50 replies posted 50 sign-ins

Hi,
Is there any example for using uart FX3 in half-duplex mode?
I am trying to use cyfxuartlpregmode example  for RS485 interface. so I had to add a gpio to control the this half duplex  communication. I set this gpio to True,  at first of while "in UartLpAppThread_Entry and set it false at the end of  that.
Also, I tested different places, but it doesn't work for me. 
Is there any clue for me to make it working?

I wrote another code without interrupt for send and receive only one byte. But I doesn't work . 
Is there any command to realize that UART received a whole byte completely?

for (;;)
{
       CyU3PGpioSetValue (gpio_half, CyFalse);
      // Receive 1 byte
       actualCount = CyU3PUartReceiveBytes(&rxTxByte, 1, &apiRetStatus);
 if (actualCount != 0 )
 {
       CyU3PGpioSetValue (gpio_half, CyTrue);
      //Send the byte

      CyU3PUartTransmitBytes (&rxTxByte, 1, &apiRetStatus); //actualCount =
      CyU3PGpioSetValue (gpio_half, CyFalse);
}


Thanks

0 Likes
1 Solution
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

I tried programing the firmware you shared on FX3 explorer kit.

I am calling CYU3PDeviceReset (CyFalse) on receiving CY_U3P_UART_EVENT_RX_DATA. But the device doesn't reset when nothing is connected to device i.e. no data is being sent.

My hardware is somehow that RX pin (gpio49) is low by default. Does it make this error?

>> It seems that there is some problem on the UART. The default state on lines should be High and a High to Low transition will indicate a Start bit and low to high transition will be Stop bit. As you mentioned that the RX is always low the stop bit is not seen by the receiver that is why the error CY_U3P_UART_ERROR_NAK_BYTE_0 is seen.The TX line driven by FX3 is HIGH initially. Please probe the RX and TX lines from FX3 side and share the traces.

Regards,
Rashi

View solution in original post

0 Likes
12 Replies
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

FX3  UART supports  full duplex communication

Is there any command to realize that UART received a whole byte completely?

>> Please let me know if you checked for CY_U3P_UART_EVENT_RX_DONE and CY_U3P_UART_EVENT_TX_DONE in the event callback. These events are triggered when UART receive/transmit operations are completed.

If you want to check that 1 byte of data is received by the UART, CY_U3P_UART_EVENT_RX_DONE can be checked in the callback function (like CyFxUartLpApplnCallback)

If this doesn't help, please let me know the requirements in detail so that I can help you better

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

Hi Rashi,
I connected FX3 to a RS485 driver. FX3 provides a UART and a GPIO to enable/disable the RS485 drivers for RX and TX. I want that F3 be RX by default and only be TX after receiving some amount of data and again back to RX(each time be RX or TX and a gpio shows the direction). (gpio=0 --> RX and gpio=1-->TX)

I used register mode example(cyfxuartlpregmode ) and added these lines to code for enabling TX _done and RX_done:
uvint32_t *uart_config = (uvint32_t*)0xE0000800;
uvint32_t *uart_int_mask = (uvint32_t*)0xE000080C;

Also, added these code lines after CyU3PUartSetConfig:
*uart_config &= ~((1u << 31));
*uart_int_mask |= (1u << 3); // Tx_Done
*uart_int_mask |= (1u << 0); // RX_Done
*uart_config |= ((1u << 31));

In CyFxUartLpApplnCallback, I did the changes in the attached image.


By these changes, I expected when FX3 received CY_FX_UARTLT_BUF_SIZE bytes  (UartDataCount==CY_FX_UARTLT_BUF_SIZE), gpio pin(gpio_half) sets to 1 and an event issue. and TX process starts. But this doesn't happen and it never goes high. I don't know what is my mistake.

when I use CY_U3P_UART_EVENT_RX_DATA instead of RX_DONE,  that gpio always goes high, even I don't send anything by Teraterm.

Thanks in advance

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Please let me know the value of UartDataCount or check if the program execution enters the if condition where the Gpio is set high.

Also, check if the status (return value of CyU3PUartReceiveBytes) is always CY_U3P_SUCCESS.

The timeout value for CyU3PUartReceiveBytes is 1 in the default firmware configured using CyU3PUartSetTimeout API. You can try increasing this timeout value if status returned by CyU3PUartReceiveBytes is CY_U3P_ERROR_TIMEOUT.

Also, let me know if you can share the complete  firmware for us to check

Regards,
Rashi
0 Likes
lock attach
Attachments are accessible only for community members.

Hi,
Thanks for your reply.
It seems that  RX_DONE condition doesn't happen but if condition with RX_DATA  happens.
I am not sure that RX_Done, works in Register mode or not. I set its register(uart_intr_mask), but I think it doesn't work.
However, I can see the data on RX pin on oscilloscope, when I send from teraterm. (I sent some character by keyboard, not continuous data). 
I did change the timeout, but nothing change.
I set CY_FX_UARTLT_BUF_SIZE =8.
I attached the complete firmware.
Thanks in advance

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

The firmware seems fine but please change the event to CY_U3P_UART_EVENT_RX_DATA and do not register for CY_U3P_UART_EVENT_RX_DONE using uart_config and let me know how much data (UartDataCount) is received by FX3.

Also check the status of CyU3PUartReceiveBytes API and let me know if it fails.

Regards,
Rashi
0 Likes

Hi,
I noticed when I use CY_U3P_UART_EVENT_RX_DATA , without sending anything from teraterm, UartDataCount become full. and I got CY_U3P_UART_ERROR_NAK_BYTE_0.
It goes to if condition and UartDataCount increases at the first(without sending anything on teraterm)

My hardware is somehow that RX pin (gpio49) is low by default. Does it make this error?



Thanks

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

I tried programing the firmware you shared on FX3 explorer kit.

I am calling CYU3PDeviceReset (CyFalse) on receiving CY_U3P_UART_EVENT_RX_DATA. But the device doesn't reset when nothing is connected to device i.e. no data is being sent.

My hardware is somehow that RX pin (gpio49) is low by default. Does it make this error?

>> It seems that there is some problem on the UART. The default state on lines should be High and a High to Low transition will indicate a Start bit and low to high transition will be Stop bit. As you mentioned that the RX is always low the stop bit is not seen by the receiver that is why the error CY_U3P_UART_ERROR_NAK_BYTE_0 is seen.The TX line driven by FX3 is HIGH initially. Please probe the RX and TX lines from FX3 side and share the traces.

Regards,
Rashi
0 Likes

Hi,
1- Did you try with CY_U3P_IO_MATRIX_LPP_DEFAULT or CY_U3P_IO_MATRIX_LPP_UART_ONLY?

I did the same test(adding CyU3PDeviceReset(CyFalse)),
with CY_U3P_IO_MATRIX_LPP_UART_ONLY : device doesn't reset,  but 
with CY_U3P_IO_MATRIX_LPP_DEFAULT       :  it takes FX3 to Bootloader mode after programming.
I did this test again with the example of cyfxuartlpregmode provided by cypress without any changes(except lppMode), it also has the same problem in CY_U3P_IO_MATRIX_LPP_DEFAULT.

I tested with CY_U3P_IO_MATRIX_LPP_UART_ONLY (gpio 55, 56 ) Tx is high and Rx is low.
The interesting thing is that in this mode(UART_only), when I connect debugger port(usb 2) and then power up the board,  both Tx and Rx are high.

For CY_U3P_IO_MATRIX_LPP_DEFAULT (gpio 48, 49) Tx(DQ30) is high and Rx is low (not depends on usb 2)
and I need to use from gpio 48 , 49(As I need 55 , 56 for SPI purpose).

2- I have another request, Is there any Uart dma example(not loop back), that I could access on rx/tx data? I want to receive data and change it in FX3, then send it.

Regards,


0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

1- Did you try with CY_U3P_IO_MATRIX_LPP_DEFAULT or CY_U3P_IO_MATRIX_LPP_UART_ONLY?

>> Yes, I tried for both on SuperSpeed Explorer Kit.

The CYUSB3KIT-003 has a debugger on UART pins GPIO [53] - [56], so when CY_U3P_IO_MATRIX_LPP_UART_ONLY is used the RX line is always pulled high but for CY_U3P_IO_MATRIX_LPP_DEFAULT the UART pins are GPIO[46] - [49]. As no communication device is present on these pins the UART - RX is low.

If you re using CY_U3P_IO_MATRIX_LPP_DEFAULT, then please confirm is if the UART communication device is present on GPIO [46] - [49] and RX is pulled high by the transmitter of communication device.

2- I have another request, Is there any Uart dma example(not loop back), that I could access on rx/tx data? I want to receive data and change it in FX3, then send it.

>> We do not have an example that meets your requirement. But you can used the UART DMA LP Mode example and modify the channel to UART > CPU ( MANUAL IN) and another channel CPU > UART (MANUAL OUT) with this the requirement can be met.

Regards,
Rashi
0 Likes

Hi,
Thanks for your reply.
Please don't close this thread, I am trying to change my hardware. I will check it and let you know for sure.
Thanks

0 Likes

Hi Rashi,
Thanks for your help.
The problem was the Rx line which was not high by default. I change the hardware config, now it works fine.
Thanks

 

0 Likes
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

Glad to hear that the problem was resolved.

Regards,
Rashi
0 Likes