millis() not working on DUE

Hello everyone,

I have two boards: 1. Arduino UNO R3 and 2. Arduino DUE R3-E.
I am using Arduino 1.5.7 on Windows 8.1 64 bit
My problem is with a piece of code that works fine on UNO but not on DUE.

/*Program execution time*/

unsigned long time;
unsigned long number = 1234567UL;

void setup() 
{ 
  Serial.begin(9600);  
  for(unsigned long counter = 1UL; counter != number + 1; counter++)
  {
    if(number % counter == 0)
    {
      Serial.println(counter); //Print the factors
    }
  }
  time = millis();
  Serial.print("Time: ");
  Serial.println(time / 1000); //Print time in seconds
}

void loop() 
{
 ;  
}

On the UNO the output on the serial monitor:

1
127
9721
1234567
Time: 47

But on DUE the same code generates a compile time error:

Arduino: 1.5.7 (Windows 8), Board: "Arduino Due (Programming Port)"

Build options changed, rebuilding all

Progexecutiontiming.ino:3:15: error: 'long unsigned int time' redeclared as different kind of symbol
In file included from c:\program files (x86)\arduino\hardware\tools\gcc-arm-none-eabi-4.8.3-2014q1\arm-none-eabi\include\stdlib.h:11:0,
from C:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino/Arduino.h:24,
from Progexecutiontiming.ino:3:
c:\program files (x86)\arduino\hardware\tools\gcc-arm-none-eabi-4.8.3-2014q1\arm-none-eabi\include\time.h:47:11: error: previous declaration of 'time_t time(time_t*)'
time_t _EXFUN(time, (time_t _timer));
^
Progexecutiontiming.ino: In function 'void setup()':
Progexecutiontiming.ino:16:8: error: assignment of function 'time_t time(time_t
)'
Progexecutiontiming.ino:16:8: error: cannot convert 'uint32_t {aka long unsigned int}' to 'time_t(time_t*) {aka long int(long int*)}' in assignment
Progexecutiontiming.ino:18:25: error: invalid operands of types 'time_t(time_t*) {aka long int(long int*)}' and 'int' to binary 'operator/'

Any help would be much appreciated. Thanks.

This is nothing to do with millis() as an examination of the error
message would show. The symbol "time" is predeclared on the Due,
you need to give it a different name such as "my_time".

Thank you MarkT. Changing the name of the variable worked. Just one more confusion! In your post you wrote that "time" is predeclared in DUE ( I am guessing like a keyword ). Can you please give me some detailed information on it. And what other keywords are there for DUE. A link to any reference would be nice. Thanks :slight_smile:

I just grepped the sources - there's a " time_t time ; " declared somewhere

time() is a C Standard library function, declared in c:\program files (x86)\arduino\hardware\tools\gcc-arm-none-eabi-4.8.3-2014q1\arm-none-eabi\include\time.h (like the error message says).

I don't know of a definitive list of reserved words, but a guide to C standard functions should give clues on some things to avoid http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

Thank you MarkT and bobcousins. Trying out the c reserved words and checking the header files in the arduino directory. I will try to create a list.

You'll need to grep libsam too! And then there's CMSIS

Hello polysysdelta,

can you tell us where you got the DUE R3-E? There is a problem with the DUE R3, and the DUE R3-E seems to solve this problem: Due won't start after power off-on, have to reset - Arduino Due - Arduino Forum.

Vile

MarkT:
This is nothing to do with millis() as an examination of the error
message would show. The symbol "time" is predeclared on the Due,
you need to give it a different name such as "my_time".

THANKS!!