Go Down

Topic: Tutorial - How to change firmware on 8u2 (Read 116 times) previous topic - next topic

Blue_Boy

I tried to implement the state machine you suggested Stimmer.
However, I get the "adress out of range" error in Flip.
I assume this is because I ran out of program space.
My main loop now looks like this.

Code: [Select]
int main(void)
{
     SetupHardware();
     
     LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
     sei();
     
     for (;;)
     {
           HID_Device_USBTask(&Joystick_HID_Interface);
           USB_USBTask();
           
           if (Serial_IsCharReceived())
                 {
                 sensorIdentification =Serial_RxByte();
                 dataReceived = true;
                 }
           
           if (Serial_IsCharReceived() && dataReceived)
                 {
                 if             (sensorIdentification == "a") {sensorA =  Serial_RxByte();}
                 else if (sensorIdentification == "b") {sensorB =  Serial_RxByte();}
                 else if (sensorIdentification == "c") {sensorC =  Serial_RxByte();}
                 else if (sensorIdentification == "d") {sensorD =  Serial_RxByte();}
                 else    {Serial_RxByte();}
                 
                 dataReceived = false;
                 }

     }
}


The "create hid report" like this:

Code: [Select]
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
                                        uint8_t* const ReportID,
                                        const uint8_t ReportType,
                                        void* ReportData,
                                        uint16_t* const ReportSize)
{
USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;

JoystickReport->X  =  sensorA;
JoystickReport->Y  =  sensorB;
JoystickReport->Z  =  sensorC;
JoystickReport->Rz =  sensorD;


*ReportSize = sizeof(USB_JoystickReport_Data_t);
     return false;
}


As it stands right now, nonfunctional.
Even when I try to only transmit the data for sensor A with the X-axis, so I'm doing a few things wrong I think.

stimmer

#26
Dec 07, 2010, 07:57 pm Last Edit: Dec 07, 2010, 07:58 pm by stimmer Reason: 1
You're on the right lines. The first if should be

if (Serial_IsCharReceived() && !dataReceived)

Serial_IsCharReceived and Serial_RxByte are inlines, so you can try to save space by only calling them once. Other ways to save space include removing the LED code, and shortening the product strings in Descriptors.c.




ant.b

#27
Dec 07, 2010, 08:11 pm Last Edit: Dec 07, 2010, 08:13 pm by ant.b Reason: 1
The memory is full as 98%. To get free space you can disable all the functions that use LEDs.

I'have emulated a joystick with uno:

I send 5 byte on serial to 8u2.

You can create this data:
uint8_t tampon;
uint8_t c;
uint8_t tempi[8];

And  modify the code:
Code: [Select]
for (;;)
     {
           HID_Device_USBTask(&Joystick_HID_Interface);
           USB_USBTask();

           if (c==8)
                 c=0;
           if (Serial_IsCharReceived())
       {
                 tampon=Serial_RxByte();
                 if (tampon==0xFF)
                       c=0;
                 tempi[c]=tampon;
                 c+=1;
           }      
           


And add that in the call back function

Code: [Select]
     JoystickReport->X=tempi[1];
     JoystickReport->Y=tempi[2];
     JoystickReport->Z=tempi[3];      
     JoystickReport->Rz=tempi[4];
     JoystickReport->Button1 =tempi[5];
     JoystickReport->Button2 =tempi[6];
     JoystickReport->Button3 =tempi[7];



The arduino has to send only bytes.
You have to use print function, not println that is sending others bytes after your data.
You can use a logic analyser to follow the data that are exchanged.

In this example, Uno has to send 0xFF as first byte (tempi[0]). However you can't send 0xFF as a data value or it will reset the c value.

Blue_Boy

My code now looks like this:

Code: [Select]
for (;;)
     {
           HID_Device_USBTask(&Joystick_HID_Interface);
           USB_USBTask();
           
           if (Serial_IsCharReceived() && !dataReceived)
                 {
                 sensorIdentification =Serial_RxByte();
                 dataReceived = true;
                 }
           
           if (Serial_IsCharReceived() && dataReceived)
                 {
                 uint8_t data = Serial_RxByte();
                 
                 if             (sensorIdentification == "a") {sensorA =  data;}
                 else if (sensorIdentification == "b") {sensorB =  data;}
                 else if (sensorIdentification == "c") {sensorC =  data;}
                 else if (sensorIdentification == "d") {sensorD =  data;}
                 
                 dataReceived = false;
                 }

     }



In the callback

Code: [Select]
USB_JoystickReport_Data_t* JoystickReport = (USB_JoystickReport_Data_t*)ReportData;

JoystickReport->X  =  sensorA;
JoystickReport->Y  =  sensorB;
JoystickReport->Z  =  sensorC;
JoystickReport->Rz =  sensorD;


*ReportSize = sizeof(USB_JoystickReport_Data_t);
     return false;
}


But the values don't update in any way.
When I run make, I get some warnings though.

Quote
warning: comparison with string literal results in unspecified behavior
warning: comparison between pointer and integer


Could this be the source of my problems?

Blue_Boy

#29
Dec 08, 2010, 01:09 pm Last Edit: Dec 08, 2010, 01:09 pm by Blue_Boy Reason: 1
I'm trying to implement your code ant.
How do you send bytes out of the Arduino (atmega).

Code: [Select]
Serial.print(data, BYTE)
or just

Code: [Select]
Serial.print(data)
data ranging from 0-254?

Go Up