Author Topic: how to Send multiple bytes to USB Port  (Read 7681 times)

starir

  • Member
  • ***
  • Posts: 3
how to Send multiple bytes to USB Port
« on: December 18, 2013, 08:45:10 am »
Hi,

I'm working on a project with AT91SAM7X256 that has USB communications too. in the first step I built the hardware and written the codes for the chip with usage of Keil uVision compilers headers. now the program works and the PC detects my device.
my main problem is this that only can send one byte in a time and with my custom function to avoid repeat or packet loss.
how can I send multiple bytes or my custom strings to PC ?

Thanks,
Best Regards.   

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: how to Send multiple bytes to USB Port
« Reply #1 on: December 18, 2013, 11:52:13 am »
What firmware are you using? Is it working example code from Keil? What device class? What transfer type? Post a code sample.

starir

  • Member
  • ***
  • Posts: 3
Re: how to Send multiple bytes to USB Port
« Reply #2 on: December 19, 2013, 12:27:21 am »

What firmware are you using? Is it working example code from Keil? What device class? What transfer type? Post a code sample.


I use headers of Keil's HID example that send status of joystick to PC via USB and controls LEDs from PC via USB. what are you meaning from device class and transfer type?

here is the demo example of Keil :

Code: [Select]

#include <AT91SAM7X256.H>                /* AT91SAM7X256 definitions         */
#include "../../AT91SAM7X-EK.h"

#include "type.h"

#include "usb.h"
#include "usbcfg.h"
#include "usbhw.h"

#include "demo.h"


AT91S_PIO * pPIO_Led = AT91D_BASE_PIO_LED;  /* Global Pointer to PIO */
AT91S_PIO * pPIO_Sw  = AT91D_BASE_PIO_SW;   /* Global Pointer to PIO */


U8 InReport;                                /* HID Input Report */
                                            /*   Bit0..4: Buttons */
                                            /*   Bit5..7: Reserved */

U8 OutReport;                               /* HID Out Report */
                                            /*   Bit0..3: LEDs */
                                            /*   Bit4..7: Reserved */


/*
 *  Get HID Input Report -> InReport
 */

void GetInReport (void) {
  U32 key;

  key = pPIO_Sw->PIO_PDSR;                        /* Read Pin Data */
  InReport = 0x00;
  if ((key & AT91B_SW1) == 0) InReport |= 0x01;   /* Check if SW1 is pressed */
  if ((key & AT91B_SW2) == 0) InReport |= 0x02;   /* Check if SW2 is pressed */
  if ((key & AT91B_SW3) == 0) InReport |= 0x04;   /* Check if SW3 is pressed */
  if ((key & AT91B_SW4) == 0) InReport |= 0x08;   /* Check if SW4 is pressed */
  if ((key & AT91B_SW5) == 0) InReport |= 0x10;   /* Check if SW5 is pressed */
}


/*
 *  Set HID Output Report <- OutReport
 */

void SetOutReport (void) {

  if (OutReport & 0x01) pPIO_Led->PIO_CODR = AT91B_LED1; else pPIO_Led->PIO_SODR = AT91B_LED1;
  if (OutReport & 0x02) pPIO_Led->PIO_CODR = AT91B_LED2; else pPIO_Led->PIO_SODR = AT91B_LED2;
  if (OutReport & 0x04) pPIO_Led->PIO_CODR = AT91B_LED3; else pPIO_Led->PIO_SODR = AT91B_LED3;
  if (OutReport & 0x08) pPIO_Led->PIO_CODR = AT91B_LED4; else pPIO_Led->PIO_SODR = AT91B_LED4;
}


/* Main Program */

int main (void) {

  /* Enable Clock for PIO */
  AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOA);         /* Joystick */
  AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_PIOB);         /* LEDs     */

  pPIO_Led->PIO_PER  = AT91B_LED_MASK;      /* Enable PIO for LED1..4  */
  pPIO_Led->PIO_OER  = AT91B_LED_MASK;      /* LED1..4 are Outputs     */
  pPIO_Led->PIO_SODR = AT91B_LED_MASK;      /* Turn off LED's ("1")    */

  USB_Init();                               /* USB Initialization */
  USB_Connect(__TRUE);                      /* USB Connect */

  while (1);                                /* Loop forever */
}


and this is my code (I only done my work with giving values to InReport variable, for this reason I can only send one byte and can't send strings or arrays of data ):

Code: [Select]

U8 InReport;                              
U8 OutReport;
U32 SendFlag;

void GetInReport (void)
{


}
void SetOutReport (void)
{


}

    USB_Connect(__TRUE);
 delay_ms(1000);

       do{
if((SendFlag == 1)&&(SCounter == 0))
{
InReport = '*';
SendFlag = 0;
SCounter = 1;
}
if((SendFlag == 1)&&(SCounter == 1))
{
InReport = 'A';
SendFlag = 0;
SCounter = 2;
}
if((SendFlag == 1)&&(SCounter == 2))
{
InReport = 'V';
SendFlag = 0;
SCounter = 3;
}
if((SendFlag == 1)&&(SCounter == 3))
{
InReport = 'A';
SendFlag = 0;
SCounter = 4;
}
if((SendFlag == 1)&&(SCounter == 4))
{
InReport = '*';
SendFlag = 0;
SCounter = 5;
}
if((SendFlag == 1)&&(SCounter == 5))
{
InReport = '\n';
SendFlag = 0;
SCounter = 6;
}
if((SendFlag == 1)&&(SCounter == 6))
{
InReport = NULL;
SendFlag = 0;
SCounter = 7;
}
if(SCounter == 7)
{
                                                               SCounter = 0;
break;
}
   }while(1);


Thanks.
« Last Edit: December 19, 2013, 12:34:31 am by starir »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: how to Send multiple bytes to USB Port
« Reply #3 on: December 19, 2013, 11:25:26 am »
The device class is HID. The transfer type is interrupt or control.

HID-class devices send data in reports, which are data structures defined by the report descriptor that the device returns during enumeration.

Each report has a defined size.

If the Input report is one byte, the device can send only one byte in each report.

To send larger amounts of data, edit the report descriptor to support it. 

starir

  • Member
  • ***
  • Posts: 3
Re: how to Send multiple bytes to USB Port
« Reply #4 on: December 21, 2013, 04:31:40 am »
Very Thanks Jan. I go to find and edit the report descriptor in the Header files.
Thanks again,
Best Regards.