millis() function not working properly? [SOLVED]


hello, come seeking because of weird behaviour of millis() function whenever use in self-made function.

i trying create function make life easier working mirf libraries (using nrf24l01 2.4ghz transceivers)

code: [select]
///// data reception function //////  
unsigned long receive_data(int target){
 int time = millis();
 unsigned long received;
 switch(target){
   case 1: // watering_probe
   mirf.settaddr((byte*)"watr1");
   mirf.config();
   break;
   
   case 2: // rc_light
   mirf.settaddr((byte*)"rcli1");
   mirf.config();
   break;
   }
while(!mirf.dataready()){
if((millis() - time) > 1500){
 serial.println("failed receive anything");
 return null;
 }  
}
mirf.getdata((byte*)&received);
return (received);
}


everything seem fine in code if((millis() - time) > 1500) part in reality doesn't work. oh sure work first few times after sketch has been uploaded (rebooting won't make work again) afterwards straight ignores wait - , when make output values millis() , time in attempt figure out problem outputs nonsense (it says difference between time and millis() -5xxxxx)

i spent few hours on i'm stuck, tried many workarounds (with limited knowledge) , fails - it's if time stops being recorded in functions no matter do.

am doing wrong? there workaround if bug?





edit: burned bootloader again in case "outdated factory firmware" problem - nope - still works couple first seconds after upload stops.

serial:
watering probe => check if device available
establishing connection...
device available!

... 5s later ...

watering probe => check if device available
establishing connection...
failed receive anything




the final word:
not going post reply otherwise it'll bump thread - in fact problem due mirf.config() function, works if add 1ms delay after function reasons, not going question inner workings low level of knowledge ^^".

thanks =)

try changing declaration to:

code: [select]
unsigned long time = millis();


Arduino Forum > Using Arduino > Programming Questions > millis() function not working properly? [SOLVED]


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support