cancel
Showing results for 
Search instead for 
Did you mean: 

Using USB CDC to send float data

love-peace2001
Associate II
Posted on February 21, 2014 at 22:37

Hi,

I'working with USB to send data from my F3 Discovery to the PC. For that i used the CDC class. I managed to send few bytes of data using the routine below:

uint8_t TabInt[6]={80,90,88,99,10,13}; 

 

uint8_t  *ptr_int=TabInt;  

 

uint16_t Lentgh_int=sizeof(TabInt);

 

CDC_Send_DATA(ptr_int, sizeof(Lentgh_int)); 

 

 

/*--------- CDC Definition-------------*/

uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length)

{

  /*if max buffer is Not reached*/

  if(Send_length < VIRTUAL_COM_PORT_DATA_SIZE)

  {

    /*Sent flag*/

    packet_sent = 0;

    /* send  packet to PMA*/

    UserToPMABufferCopy((unsigned char*)ptrBuffer, ENDP1_TXADDR, Send_length);

    SetEPTxCount(ENDP1, Send_length);

    SetEPTxValid(ENDP1);

  }

  else

  {

    return 0;

  }

  return 1;

}

As we can see the  data to be sent is declared as u8. It  Tried to do the same for the data but with no success. 

float_t TabKs[2]={1.215,1.245}; 

uint8_t  *ptr_Ks=(uint8_t*)&TabKs; 

uint8_t Lentgh_Ks=sizeof(TabKs);

CDC_Send_DATA(ptr_Ks, Lentgh_Ks); 

 

Unfortunately that didn't work for me,The problem i think is that my float value is being sent as one byte and i have to reconstitute it correctly but i don'k know how. If you have an idea how can i resolve my issue, i would be grateful.

Thanks in advance.

3 REPLIES 3
love-peace2001
Associate II
Posted on February 22, 2014 at 21:25

I resolved the problem. It was in the C# interface that i made for that purpose.

idealsim
Associate II
Posted on March 01, 2014 at 09:54

Hi, i already have this board and i'm trying to communicate with my pc by cdc (to send gyroscope angle, i posted a [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/Newbie%20on%20stm32%20%28USB%20HID%20or%20CDC%20on%20f3%20discovery%29&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https%3a//my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx&currentviews=8]message about it on this forum). I 'm newbie on stm and your code can interrest me to progress and understand the logic. It's possible that you send me your code (specialy for cdc communication ...) ?

Thanks in advance

love-peace2001
Associate II
Posted on March 04, 2014 at 22:23

This link can help you : http://www.pezzino.ch/stm32f3-discovery-usb-virtual-com-port/

If you have problem let me know.