Send an integer through USB

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Send an integer through USB

781 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andrew24 on Tue May 18 12:27:46 MST 2010
Hello, i'm curious is there a possibility to send a 32bit integer through USB using virtual com port? It works fine when sending chars (256 max) but i cannot pass integers to a PC..They are corrupted when i receive them. Can you suggest how can i make it work?

The purpuse here is to send an array of 10 integer elements.

unsigned int
   packet[10]={1111,2222,3333,4444,5555,6666,7777,8888,9999,1010},
   *DataPointer;



 
/*Code for sending data through USB*/
packet_size=sizeof(packet);
DataPointer=packet; // address of a first element of an array
LPC_USB->Ctrl = ((CDC_DEP_IN & 0x0F) << 2) | CTRL_WR_EN;
/* 3 cycles delay*/
 delay( 5 );
LPC_USB->TxPLen =packet_siz; //number of bytes to send
   while((LPC_USB->TxPLen)>0)
   {
   /*value at address ...*/
   LPC_USB->TxData = *DataPointer;
   DataPointer++; // next array element
   }
LPC_USB->Ctrl = 0;
WrCmdEP(CDC_DEP_IN, CMD_VALID_BUF);
0 Kudos
Reply
3 Replies

754 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by igorsk on Tue May 18 17:37:53 MST 2010
I have no idea what's "labwindows" but if it doesn't have a "read int" function (and I don't expect it would, since serial is a byte-oriented protocol), you'll just have to do it the hard way.
0 Kudos
Reply

754 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Andrew24 on Tue May 18 14:20:15 MST 2010

Quote: igorsk
How are you receiving the data and how is it corrupted?



Foe example, I'm sending packet =1234.
I use "Read byte" function in labwindows CVI and  get:
210.
After reading the second byte i get 4. Offcourse, i could do (210 + (4<<8))=1234, but i think there must be a nicer way to solve this
0 Kudos
Reply

754 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by igorsk on Tue May 18 13:51:45 MST 2010
How are you receiving the data and how is it corrupted?
0 Kudos
Reply