Simple USB to UART

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

cross mob
MiHe_282546
Level 3
Level 3
5 sign-ins 10 questions asked 10 replies posted

 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.

0 Likes
8 Replies
Anonymous
Not applicable

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".

0 Likes
Anonymous
Not applicable

 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.

0 Likes
MiHe_282546
Level 3
Level 3
5 sign-ins 10 questions asked 10 replies posted

 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 

0 Likes
MiHe_282546
Level 3
Level 3
5 sign-ins 10 questions asked 10 replies posted

 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.

0 Likes
Anonymous
Not applicable

 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.

   
0 Likes
MiHe_282546
Level 3
Level 3
5 sign-ins 10 questions asked 10 replies posted

 OK, I will try to do that. Thanks!

0 Likes
MiHe_282546
Level 3
Level 3
5 sign-ins 10 questions asked 10 replies posted

 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

0 Likes
Anonymous
Not applicable

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

0 Likes