Go Down

Topic: Getting a strange error (Read 660 times) previous topic - next topic

efas

I wrote this code for the Uno but switched over to the Due. It compiles and runs fine on the Uno but for the Due it gives me this error:  

Quote
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/Arduino.h:203,
                from arduino_DAC.ino:10:
C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/USB/USBCore.h:208: error: expected unqualified-id before numeric constant


Here is the code:

Code: [Select]
#define d1 1
#define d2 2
#define d3 3
#define d4 4
#define d5 5
#define d6 6
#define d7 7
#define d8 8

void setup()
{
 pinMode(d1, OUTPUT);
 pinMode(d2, OUTPUT);
 pinMode(d3, OUTPUT);
 pinMode(d4, OUTPUT);
 pinMode(d5, OUTPUT);
 pinMode(d6, OUTPUT);
 pinMode(d7, OUTPUT);
 pinMode(d8, OUTPUT);
}


void loop(){
 for(int i = 0; i < 256; i++){
   
   if( (i%2) == 0){
     digitalWrite(d1, LOW);
   }
   if((i%2) == 1){
     digitalWrite(d1, HIGH);
   }
   if( (i/2)%2 == 0){
     digitalWrite(d2, LOW);
   }
   if( (i/2)%2 == 1){
     digitalWrite(d2, HIGH);
   }
   if( (i/4)%2 == 0){
     digitalWrite(d3, LOW);
   }
   if( (i/4)%2 == 1){
     digitalWrite(d3, HIGH);
   }
   if( (i/8)%2 == 0){
     digitalWrite(d4, LOW);
   }
   if( (i/8)%2 == 1){
     digitalWrite(d4, HIGH);
   }
   if( (i/16)%2 == 0){
     digitalWrite(d5, LOW);
   }
   if( (i/16)%2 == 1){
     digitalWrite(d5, HIGH);
   }
   if( (i/32)%2 == 0){
     digitalWrite(d6, LOW);
   }
   if( (i/32)%2 == 1){
     digitalWrite(d6, HIGH);
   }
   if( (i/64)%2 == 0){
     digitalWrite(d7, LOW);
   }
   if( (i/64)%2 == 1){
     digitalWrite(d7, HIGH);
   }
   if( (i/128)%2 == 0){
     digitalWrite(d8, LOW);
   }
   if( (i/128)%2 == 1){
     digitalWrite(d8, HIGH);
   }
   delay(1);
 }
 for(int i = 254; i >= 0; i--){
   
   if( (i%2) == 0){
     digitalWrite(d1, LOW);
   }
   if((i%2) == 1){
     digitalWrite(d1, HIGH);
   }
   if( (i/2)%2 == 0){
     digitalWrite(d2, LOW);
   }
   if( (i/2)%2 == 1){
     digitalWrite(d2, HIGH);
   }
   if( (i/4)%2 == 0){
     digitalWrite(d3, LOW);
   }
   if( (i/4)%2 == 1){
     digitalWrite(d3, HIGH);
   }
   if( (i/8)%2 == 0){
     digitalWrite(d4, LOW);
   }
   if( (i/8)%2 == 1){
     digitalWrite(d4, HIGH);
   }
   if( (i/16)%2 == 0){
     digitalWrite(d5, LOW);
   }
   if( (i/16)%2 == 1){
     digitalWrite(d5, HIGH);
   }
   if( (i/32)%2 == 0){
     digitalWrite(d6, LOW);
   }
   if( (i/32)%2 == 1){
     digitalWrite(d6, HIGH);
   }
   if( (i/64)%2 == 0){
     digitalWrite(d7, LOW);
   }
   if( (i/64)%2 == 1){
     digitalWrite(d7, HIGH);
   }
   if( (i/128)%2 == 0){
     digitalWrite(d8, LOW);
   }
   if( (i/128)%2 == 1){
     digitalWrite(d8, HIGH);
   }
   delay(1);
 }
}


Does anyone know whats wrong? Is it the mod?

michinyon

It is complaining about line 208 in the h file,  supposedly.

Look at the h file in an editor which has some way of counting lines.

michinyon

And that is pretty cretinous code.   Does the keyword "else"  not work in DUE C++ ?

efas

I know its ugly but it works and does what I need it to do. This is header file generating the error:

Code: [Select]
uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
{
    uint32_t n;
int r = len;
const uint8_t* data = (const uint8_t*)d;

    if (!_usbConfiguration)
    {
    TRACE_CORE(printf("pb conf\n\r");)
return -1;
    }

while (len)
{
        if(ep==0) n = EP0_SIZE;
        else n =  EPX_SIZE;
if (n > len)
n = len;
len -= n;

UDD_Send(ep & 0xF, data, n);
data += n;
    }
//TXLED1; // light the TX LED
//TxLEDPulse = TX_RX_LED_PULSE_MS;
return r;
}


line 208 is the "return r" line. This is incomprehensible to me, I dont understand what the problem is.

econjack

No, the original post is not the code because there is no #include preprocessor directive in it. When I compile the header file you posted, the compiler tells me _usbConfiguration is not defined, so where is its definition?

holmes4

You seem to be using a third party lib which is intended for the AVR processors AND HAS NOT BEEN rewriten for the due. Have your question moved to the due forum!.

Mark

efas

The problem was the #define. Switched it to int and it works fine

Go Up