Go Down

Topic: Problem with init() (in wiring.c) when my init of the UART (unsolved) (Read 1 time) previous topic - next topic

syrinx

#10
Jan 20, 2013, 11:33 am Last Edit: Jan 20, 2013, 11:49 am by syrinx Reason: 1
I did:
- I have deleted #include "bluevmega.cpp"
- renamed the 3 files with .ino extension
- moved all the variables at the beginning of the main .ino file

Still not working when the UART init is not named init().

syrinx

#11
Jan 20, 2013, 01:21 pm Last Edit: Jan 20, 2013, 01:31 pm by syrinx Reason: 1
It seems that it works if hwsetup() is launched from main()

Then inside main(), I call loop().

syrinx

#12
Jan 20, 2013, 08:09 pm Last Edit: Jan 20, 2013, 08:11 pm by syrinx Reason: 1
I still have a problem: millis() gives always 0.

It's probably related to interrupts or ini of wiring.c.

Any idea how to solve this?

Thanks.

syrinx

millis() was always at zero. Now it's OK.

I was obliged to add this:

Code: [Select]

int main()
// Syrinx was: #else
// Syrinx was: void init()
// Syrinx was: #endif
{
    hwsetup();
// Enable TIMER0 ( used by millis() )
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
sbi(TCCR0B, CS01);
sbi(TCCR0B, CS00);
sbi(TIMSK0, TOIE0);
setup();
loop();
}


Now millis() is working a gain. As my code is not changing TIMER0 somewhere, it means that init() is not well built. I don't know why.

Nick Gammon

You shouldn't really have a main. The "real" main calls init, setup, and then loop repeatedly. Why not put your setting up in setup?

Go Up