CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

USB transmission must do it in "int8"?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cenadius



Joined: 13 Mar 2010
Posts: 11

View user's profile Send private message

USB transmission must do it in "int8"?
PostPosted: Sat Mar 27, 2010 10:40 pm     Reply with quote

Hi, I want to send a string and a float through usb to my computer GUI, and I find out that usb_put_packet() function must transmit data in int8.
Below is my code:
Code:

include <18F4550.h>
#fuses HSPLL,USBDIV,PLL5,CPUDIV1,VREGEN,NOWDT,NOPROTECT,NOLVP,NODEBUG
#use delay(clock=48000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define USB_HID_DEVICE     FALSE             
#define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE    2                 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE    33                //size to allocate for the rx endpoint 1 buffer

// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <fypusb.h>     //USB configuration and descriptors
#include <usb.c>           //handles usb setup tokens and get descriptor reports
#define  modeo    dataout[0]
#define  conv     dataout[1]
void main(void)

   int8  datain[33];
   int8  dataout[33];
   

 usb_init();                      //init USB

   usb_task();                      //usb  interrupt
   usb_wait_for_enumeration();      //wait from host PC

while (TRUE)

   {
       
      if(usb_enumerated())          //usb config
      {
         if (usb_kbhit(1))          //
         {
            usb_get_packet(1, datain, 64); //
               modeo = 0;                 
                  conv=111.99;
                  usb_put_packet(1, dataout, 2, USB_DTS_TOGGLE);
}
}
}

For my GUI, I will receive 111 only, I can't get 111.99. I realise that the problem might be cause by the "int8 dataout[33]" declaration. I had tried to declare it with "float dataout[33];", but the transmission failed.
Can someone guide me in how to make the usb transmit a float or string to computer?

Thank you.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Mar 28, 2010 3:20 am     Reply with quote

The problem hasn't to do with USB at all. You just have to learn some C-programming basics. The first point to consider
is that float has a length of four byte. So if you need an int8 array to represent a float variable, it must have a
length of 4 at least.

There are various methods to copy the content of a float variable to an int8[4] array. It's a serial topic at ccs forum,
because it's needed for different purposes, e.g. transmitting the data on RS232, storing to an EEPROM and much more. A
generic C method is by using unions, CCS C has the make8() and make32() built-in functions to copy larger data
units to int8 and vice versa.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group