Weird values of USB packets, strcmp not triggering commands

Thread Starter

GoExtreme

Joined Mar 4, 2018
52
Hello,

I'm working with custom pcb measuring current and want to send the data trough usb to display in windows. EFM8ub10 is the mcu.

I got it to ping pong values. I send "1" trough windows app, MCU sends back "1".

The problem is I want to send current data. Not sure how to implement data into transmit data. When sending value = 1 to mcu I though I can read it from Rx_Packet[0] buffer.
But that's not the case. Sent value = buffer[0]
1 = 12580
2 = 12834
3 = 13092

When I check buffer[0] [1] etc values change, but they don't make sense.
I also tried strcmp, but doesn't recognize command buffers.

Code:
char Data;
volatile uint8 res2[2]={0};

Data = RX_Packet[0];
sprintf(res2,"%d",Data);

for (i=0; i<InCount;i++)                        // Copy received packet to output buffer
         {
        TX_Packet[i] = RX_Packet[i];
        }
 

Attachments

MrChips

Joined Oct 2, 2009
34,829
It is difficult to follow what you are trying to convey.
Forget about strcmp for the moment.

What data are you transmitting?
What data are you receiving?
 

MrChips

Joined Oct 2, 2009
34,829
I want MCU to send voltage and current float values. I want host to be able to send "start" command etc.
Sorry, still not clear.
What do you mean by "voltage and current float values"?.

What is a "host"?

What do you mean by "start" and "command etc."?

Give us concrete examples. For example, what is the "start" command?
What is sending it? What is receiving it?
 

Thread Starter

GoExtreme

Joined Mar 4, 2018
52
Ok I will try my best.

I have I2C current sensor that MCU is getting voltage and current from. MCU has built in USB.
Here is usb part:

Code:
VCPXpress_API_CALLBACK(myAPICallback)
{
   uint32_t INTVAL = Get_Callback_Source();
   uint8_t i;


   if (INTVAL & DEVICE_OPEN)
   {
      Block_Read(RX_Packet, PACKET_SIZE, &InCount);   // Start first USB Read
   }

   if (INTVAL & RX_COMPLETE)                          // USB Read complete
   {
      for (i=0; i<InCount;i++)                        // Copy received packet to output buffer
      {
         TX_Packet[i] = RX_Packet[i];
      }
      Block_Write(TX_Packet, InCount, &OutCount);     // Start USB Write
   }

   if (INTVAL & TX_COMPLETE)                          // USB Write complete
   {
      Block_Read(RX_Packet, PACKET_SIZE, &InCount);   // Start next USB Read
   }

}

}
I attached picture of Host app. On left send message on the right what comes out of MCU.
I would like the Windows app to send request for Voltage ( lets say char vbus[] ="vbus") and for current as well. Commands then load float values into Transmit buffer.

I guess im not sure how to interpret usb buffer.

When send "1" trough windows app to MCU. On board LCD shows 2 packets received.
When I read the received data buffer I get these values displayed:
buffer = 258
buffer[0] =12546
buffer[1] = 2562

So this doesn't make sense to me.
 

Attachments

MrChips

Joined Oct 2, 2009
34,829
Ok. Let's try one thing at a time.

Your "host" is a PC running Windows 10. On the PC is a Windows app written in ???.
The app sends TX_Packet[ ] = "vbus" to MCU EFM8ub10 via USB.
MCU EFM8ub10 responds and the response is in RX_Packet[ ].

How many bytes were received in RX_Packet[ ]?
What are the actual raw bytes received in RX_Packet[ ] without any formatting?
What was the expected response from the MCU?
 

Thread Starter

GoExtreme

Joined Mar 4, 2018
52
Windows 10, made in visual basic 2017 in C#.

2 packets received.But I'm not sure if there is formatting. It's part of VCPXpress library from Silabs.

MCU once gets read Voltage from host, should send voltage value to host.
Its also displays results on onboard oled.

I wonder why these numbers are so big? Shouldn't the go up to only 255?
 

MrChips

Joined Oct 2, 2009
34,829
Windows 10, made in visual basic 2017 in C#.

2 packets received.But I'm not sure if there is formatting. It's part of VCPXpress library from Silabs.

MCU once gets read Voltage from host, should send voltage value to host.
Its also displays results on onboard oled.

I wonder why these numbers are so big? Shouldn't the go up to only 255?
No. The data could be formatted in some way. Show us the raw bytes and we may be able to decode it for you.
 

Thread Starter

GoExtreme

Joined Mar 4, 2018
52
Ok I figured it out. It was sprintf in decimal instead of character. Host sends "1" in ascii therefore it wasn't reading right.
 
Last edited:
Top