4 Replies Latest reply on Sep 30, 2015 1:06 PM by user_342122993

    USBUART data missing

    user_77989180

      Hi everyone,

         

      I am using USBUARTwith PSoC 5LP. I would like to send "unsigned int" to my computer. 

         

      If I use 

         

      sprintf(buf, "%d\t%d\t%d\t%d\n\r",data[0],data[1],data[2],data[3],data[4]);
      while(USBUART_1_CDCIsReady() == 0u);
      USBUART_1_PutString(buf); 

         

      It works well if I use PutString, but i want to send my data into an interface so I have to use PutChar. But when try   

         

                          for(j=0;j<4;j++){
                          while(USBUART_1_CDCIsReady() == 0u);    
                          USBUART_1_PutChar((data[j]>>8)) ;
                          while(USBUART_1_CDCIsReady() == 0u);    
                          USBUART_1_PutChar((data[j]&0xFF)) ; 
                          }             
      Everytime there are datas missing. I don't understand why instead of receive 8 chars i receiv sometine 6, 7...

         

       

         

      Thank you very much

         

       

         

      btw I made the initialization  of the USB like this:

         

      USBUART_1_Start(0u, USBUART_1_3V_OPERATION);
          while(!USBUART_1_GetConfiguration());
          USBUART_1_CDC_Init(); 

         

          while(USBUART_1_CDCIsReady() == 0u) ;

        • 1. Re: USBUART data missing
          user_342122993

          alex934,

             

          use USBUART_PutData(buf, buffer_size) to send all data at once like this:

             

           

             

           

             

          // send four uint16 values using UART-USB

             

          void SendDataPacket(uint16 Data0, uint16 Data1, uint16 Data2, uint16 Data3)

             

          {

             

               static uint8 buff[8];

             

               const uint8 BUFF_SIZE = sizeof(buff);

             

           

             

              //Fill in output buffer->

             

               buff[0] = Data0>>8; // Send debug data in MSB first fashion

             

               buff[1] = Data0;

             

               buff[2] = Data1>>8;

             

               buff[3] = Data1;

             

               buff[4] = Data2>>8;

             

               buff[5] = Data2;

             

               buff[6] = Data3>>8;

             

               buff[7] = Data3;

             

           

             

               if(USBUART_1_GetConfiguration() != 0u) // Service USB CDC when device configured

             

              {

             

                    while(USBUART_1_CDCIsReady() == 0u); // Wait for USB-UART is ready to send more data to the PC

             

                    USBUART_1_PutData(buff, BUFF_SIZE); // Send data to PC

             

                }

             

          }

             

           

             

           

             

          Attached PSoC5LP  example of sending sine wave to Multichart (PC) application using USB-UART, and Multichart program.

          • 2. Re: USBUART data missing
            user_77989180

            Thank you for your help

               

            But I still got a problem, I put 254 in buff0 and buff5 to visualize my data;

               

                 buff[0] = 254;
                 buff[1] = Data0>>8; // Send debug data in MSB first fashion
                 buff[2] = Data0;
                 buff[3] = Data1>>8;
                 buff[4] = Data1;
                 buff[5] = 254;
                 if(USBUART_1_GetConfiguration() != 0u) // Service USB CDC when device configured
                {
                      while(USBUART_1_CDCIsReady() == 0u); // Wait for USB-UART is ready to send more data to the PC

               

                      USBUART_1_PutData(buff, BUFF_SIZE); // Send data to PC
                  }

               

             

               

            And I my TeraTerm (virtual port) it display that :

               

               

            As you can see between my square (254) data are sometime 2, sometime 4?!

               

            • 3. Re: USBUART data missing
              user_77989180

              Well no I think its just because my Data>>8 = 0 so it s a Null char in ASCII Code, am right?

              • 4. Re: USBUART data missing
                user_342122993

                Looks like it. In early days (PDP11 etc.) some characters were used for serving the "terminal" (monitor screen), as communication was done using 9kBd RS232. Some caused beeping, some clearing screen, some deleting entire row, etc.

                   

                Please take a look on previously attached USBUART demo, particularly on USBUART initialization and polling its status in the main loop.