Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > Simple USB to UART

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Simple USB to UART
Moderator:
ANCY

Post Reply
Follow this topic



Simple USB to UART

mike.hersh posted on 11 Apr 2012 1:48 AM PST
Top Contributor
21 Forum Posts

 Hi,

Can anyone please help me how to transfer UART to USB interface using the PSoC5: I have TX,RX,RTS,CTS connected to the PSoC5 pins and I want to transfer them into USB interface like the FTDI chip. I looked in all the examples I can find in the Creator2.0 and still don't understand how to make this simple...

Thanks,

Michael H.




Re: Simple USB to UART

U2 posted on 11 Apr 2012 03:25 AM PST
Cypress Employee
589 Forum Posts

From your statment I understand that, you have an FTDI connected to your PC via USB and you want to interface PSoC to FTDI via UART RX TX, correct ? If that is the case, may be you should simply place an UART component on the TopDesign, configure it, assign proper pins and put some additional code to initialise the component and to transfer data. You can get a very basic UART code example by right click on your UART component and selecting "Find Example Project".



Re: Simple USB to UART

U2 posted on 11 Apr 2012 03:27 AM PST
Cypress Employee
589 Forum Posts

 You can as well drag and drop the USBUART Macro component available in the component catalog on to your TopDesign. In this case you can connect PSoC to PC directly and use the USBUART inetrface provided by PSoC.



Re: Simple USB to UART

mike.hersh posted on 11 Apr 2012 03:30 AM PST
Top Contributor
21 Forum Posts

 NO, I don't have ftdi chip on my board. I have TX, RX, CTS, RTS connected to the PSoC5 and I want to convert them to the USB Interfave (pins P15_6 and P15_7). In another words I need a module that can do that: UART -> PSoC5 -> USB 



Re: Simple USB to UART

mike.hersh posted on 11 Apr 2012 03:45 AM PST
Top Contributor
21 Forum Posts

 To make my question even simpler, what I need to change in the following USBUART example code in order to do what I asked above: 

  /* Start USBFS Operation with 3V operation */

    USBUART_1_Start(0, USBUART_1_3V_OPERATION);

/* Wait for Device to enumerate */

    while(!USBUART_1_GetConfiguration());

    /* Enumeration is done, enable OUT endpoint for receive data from Host */

    USBUART_1_CDC_Init();

for(;;)

    {

        if(USBUART_1_DataIsReady() != 0u)                /* Check for input data from PC */

        {   

            count = USBUART_1_GetAll(buffer);           /* Read received data and re-enable OUT endpoint */

            if(count != 0u)

            {

                while(USBUART_1_CDCIsReady() == 0u);    /* Wait till component is ready to send more data to the PC */ 

                USBUART_1_PutData(buffer, count);        /* Send data back to PC */

            }

        }  

        

        state = USBUART_1_IsLineChanged();              /* Check for Line settings changed */

        if(state != 0u)

        {  

            if(state & USBUART_1_LINE_CODING_CHANGED)   /* Show new settings */

            {

                sprintf(lineStr,"BR:%4ld,DB:%d",USBUART_1_GetDTERate(),(uint16)USBUART_1_GetDataBits());

                //LCD_Position(0,0);

                //LCD_PrintString("                    ");

                //LCD_Position(0,0);

                //LCD_PrintString(lineStr);

                //sprintf(lineStr,"SB:%s,Parity:%s", stop[(uint16)USBUART_1_GetCharFormat()], \

                //                                     parity[(uint16)USBUART_1_GetParityType()]);

                //LCD_Position(1,0);

                //LCD_PrintString("                    ");

                //LCD_Position(1,0);

                //LCD_PrintString(lineStr);

            }

            if(state & USBUART_1_LINE_CONTROL_CHANGED)  /* Show new settings */

            {   

                state = USBUART_1_GetLineControl();

                sprintf(lineStr,"DTR:%s,RTS:%s",  (state & USBUART_1_LINE_CONTROL_DTR) ? "ON" : "OFF", \

                                                    (state & USBUART_1_LINE_CONTROL_RTS) ? "ON" : "OFF");

                //LCD_Position(1,0);

                //LCD_PrintString("                    ");

                //LCD_Position(1,0);

                //LCD_PrintString(lineStr);

            

            }

        }

    }   

Thanks,

Michael H.



Re: Simple USB to UART

U2 posted on 11 Apr 2012 05:15 AM PST
Cypress Employee
589 Forum Posts

 Michael, I understand that you have data coming in from UART over to PSoC5 and you need to throw this out of PSoC via USB correct ?

 

If that is the case you need have a UART interface to first receive data over UART as shown above. Configure the UART for necessry BAUD RATE. And make Pin connections as necessary. Assign RX and TX pin in the CYDWR file to Pins of your choice. First intiliase your UART component in the code you pasted above by calling, UART_Start(); Remove all the code from the for loop. Use the API UART_GetByte(), and use the API. Copy the data read from UART in to a buffer. Then use the API 

                USBUART_1_PutData(buffer, count);

 

to transfer data over USBUART to PC. However note that you need to have the handshaking and status check code around this simple code to get a relibly working code. I hope this should atleast get you going.




Re: Simple USB to UART

mike.hersh posted on 11 Apr 2012 05:22 AM PST
Top Contributor
21 Forum Posts

 OK, I will try to do that. Thanks!



Re: Simple USB to UART

mike.hersh posted on 11 Apr 2012 08:04 AM PST
Top Contributor
21 Forum Posts

 OK, the code is working great now. This is the working code for simple USB to UART:

// Before you copy this code make sure to copy and paste the USBUART_1 module from the USB_UART example 

void main()

{

    char8 buffer[1]; //buffer array

   /* Enable Global Interrupts */

    CyGlobalIntEnable;  

/* Start UART */

    UART_Start(); 

    UART_ClearTxBuffer();

/* Start USBFS Operation with 3V operation */

USBUART_1_Start(0, USBUART_1_3V_OPERATION);

/* Wait for Device to enumerate */

while(!USBUART_1_GetConfiguration());

   /* Enumeration is done, enable OUT endpoint for receive data from Host */

USBUART_1_CDC_Init();

// ---- USB Interface Starts---- //

    while(1)

    {

buffer[0]=UART_GetChar();

if (buffer[0]>0) //If byte received 

{

while(USBUART_1_CDCIsReady() == 0u); //Wait till component is ready to send more data to the PC 

USBUART_1_PutData(buffer,1);

}

if(USBUART_1_DataIsReady() != 0u) //Check for input data from PC  

{

USBUART_1_GetData(buffer, 1);

UART_PutChar(buffer[0]);

}

}// End While(1)

// ---- USB Interface Ends---- //

}// End Main



Re: Simple USB to UART

kmmankad posted on 20 Apr 2012 07:42 AM PST
Top Contributor
268 Forum Posts

Shows how simple the PSoC is to use! .. if only it were that cheap.. :-P






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20