10 Replies Latest reply on Sep 14, 2017 1:00 AM by peter.de.nijs_2719976

    USB_UART to multiple UARTs


      I'm working on an application that requires control of multiple devices from a single USB_UART/hyperterminal connection.


      My solution was to use the CY8C5888 devices used on the CY8CKIT-059 as it has worked in a similar prototype application.  


      I've designed a custom board that uses three (3) CY8C5888LTI-LP097 PSOCs.  One PSOC uses the USB_UART component to interface to a PC to allow hyperterminal control of two switches to turn on supply voltage to the other two separate PSOC devices.  Once powered, these secondary devices may then be used to communicate via UART to the main USB_UART device.  I decided to play with the MUX components and just use a single UART whose external connections are selected based on hyperterminal commands.  When sending UART commands to the secondary devices, they are programmed to reply with an acknowledgement message. 


      So far, the main USB_UART controller device appears to be working well for just hyperterminal communications back to the PC.  The UART/MUX switch part seems to work fine, and enabling power to the other two PSOC devices works ok as well.  However, when I try to talk to the other devices over UART, I get mixed results.  Mostly, I am getting incomplete messages and/or the acknowledgement messages from the remote devices seem to be delayed by 1 message.  


      I'm sure there is something I'm doing wrong either with buffer sizes, or how I'm reading the UART messages back from the secondary PSOC devices, or something else.  Since I will ultimately need to send and receive more than 4 bytes at a time I have been setting the UART TX and RX buffers to numbers greater than 4 which I have read generates an internal interrupt, which is hopefully being handled by the while (UART_GetRxBufferSize() ) loop... My concern is that there is another USB_UART device that is also generating interrupts that I might not be handling correctly.   


      For completeness, I've had something similar to this working with just the CY8CKIT-059... where the kitprog device was ONLY relaying hyperterminal commands to the single CY8C5888 target device over UART and it seemed to work ok.. with the target sending full messages back as expected.  Right now, I'm just turning LEDs on and off via GPIO on the secondary PSOC devices... which is currently working. Since that part worked, I strongly suspect that my "problem" code is on the USB_UART side.  I've read through the UART data sheet as well as the following forum posts, but am still a bit confused how to get this working correctly.    










      I'm uploading the project for the USB_UART side in hopes that someone can shed some light on what I might be doing wrong.


      Thanks in advance.

        • 1. Re: USB_UART to multiple UARTs

          Since you are multiplexing between two UART Rx externally, you should flush all the received data when you switch the lines. For example, you should do UART_ClearRxBuffer whenever you switch the lines using UART_ClearRxBuffer. 

          • 2. Re: USB_UART to multiple UARTs

            Thanks for the advice.  I will certainly incorporate that.  Do you have a suggestion as to where the UART_ClearRxBuffer() should be placed in the code?  Maybe within the IF structure to check if the switch has toggled?


            Unfortunately, I don't think your suggestion will fix the issue I'm seeing... as I've seen the problem even when only communicating to one UART channel.   Is there something I should be doing differently with regard to the UART loop?  

            • 3. Re: USB_UART to multiple UARTs

              Just a quick update, I tried playing around with the interrupt priority (mainly bumping the UART interrupts to higher priority) with no improvement in the issue.

              • 4. Re: USB_UART to multiple UARTs

                I've been playing with this off and on for the last several weeks... and it appears to be entirely an issue with the interaction between the USBUART and the UART in the referenced (posted) code.  Even if the UART line is disconnected from the second PSOC device, the USBUART will lock up (i.e. will not accept inputs from the PC serial port) after transferring a few commands.   This does not seem to happen in the USBUART example code... in that case, the data from the PC is just sent back to the PC and not transferred to UART... but never locks up.   


                I've tried changing baud rates, changing to half duplex, changed the buffer sizes, all to no avail.  Any one willing to take a look?   Any suggestions are welcome and appreciated. 

                • 5. Re: USB_UART to multiple UARTs

                  I always feel creepy when someone asks "Where to put the ClearRxBuffer()". This is needed only in case of errors detected. Different baud rate usually have nothing to do with not-working UARTs. So, when multiplexing Rx/Tx lines is used the remaining issues have to do with stopping/aborting current transmissions. How do you stop transmissions and how do you make sure that all bits of the current one have been shifted out of the transmitter.


                  Can you please upload the current project with detailed comments of what works and what not?





                  1 of 1 people found this helpful
                  • 6. Re: USB_UART to multiple UARTs

                    Thanks for responding.  The project hasn't changed much from the original post on Dec 28th.  I am noticing that having any delay between when I send commands over UART to the second PSOC has a big influence on whether the USBUART loctks up.  But the problem (commented in the main.c file) is the piece where a command (in this case, either the character "M" or "?") has been detected and is being sent to the second PSOC device.  As far as stopping/aborting,... I was thinking that the UART receive loop will stop once it detects that there are no incoming bytes.  I can see where this might be a problem... Do you have suggestions on how to deal with starting/stopping transmission?


                    Thanks again for the help.

                    • 7. Re: USB_UART to multiple UARTs

                      Your delay functions are not sufficient. Look into USBUART datasheet for PutString()


                      The USBUART_CDCIsReady() function should be called before sending data with a new call to USBUART_PutString(), to be sure that the previous data has finished sending.





                      • 8. Re: USB_UART to multiple UARTs

                        Ok, I've tried using the " USBUART_CDCIsReady()  " similar to the way it was implemented in the USBUART example code in a couple different ways.  Maybe there are suggestions on how to use this function to send data back to the PC.  However, I'm still not able to get this to work.   


                        Maybe I can come at this from a different direction.  Is there any example code that shows how the Kitprog USBUART functionality is implemented to send/receive UART commands to/from the target device on the dev board? Ultimately, this is really what I'm after.   A USB based serial com port on one side and a UART interface on the other.  


                        I'm hoping someone can shed some light on how Cypress performs this function within the Kitprog device.

                        • 9. Re: USB_UART to multiple UARTs

                          Why don't you use the USBUART example project? right click on the component and select  "Find code example", the USBFS_UART project is what you need.





                          1 of 1 people found this helpful
                          • 10. Re: USB_UART to multiple UARTs

                            Thanks.  It looks like that example is used to communicate to an LCD.  So, it is only a 1 way communication scheme.  Are there any examples like this that use a UART instead of an LCD?

                            • 11. Re: USB_UART to multiple UARTs

                              Ok,  I think it's finally working now.  It took a local colleague more experienced in embedded coding the myself to point out where things were going wrong.  Actually BOTH the previous suggestions (in the correct locations) were required to completely fix the problem.  


                              Thanks a bunch for all the good suggestions!

                              • 12. Re: USB_UART to multiple UARTs

                                Can you upload the final project. It would save me some time