Go Down

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


Thanks a lot Nick!

Since I've added this code:
Code: [Select]

int main()

I'm able to init the UART from setup() (without conflict with init() from wiring.c)
and all is working better, even millis()!

I hope I won't have a new problem soon...

Thank you very much.


Yes, well I should point out that normally 'loop' loops. That is:

Code: [Select]
while (true)
  loop ();
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Code: [Select]
    // trigger on falling edge (default), noise cancel
    // lower 3 bits is div, off,1,8,64,256,1024,extfall,extris ; CS12,11,10
    TCCR4B = _BV(ICNC1) | _BV(CS11);

    // clear and enable Input Capture interrupt
    TIFR4 |= _BV(ICF4) | _BV(TOV4) | _BV(OCF4A) | _BV(OCF4B);
    TIMSK4 = _BV(ICIE4);        // enable input capture only

If you're going to re-initialize peripherals AFTER the arduino core functions (init()) have already set them up, you'll need to assume that none of the "initial values" from the datasheet are still correct.  That means, in the worst case, that you should explicitly initialized ALL registers associated with a peripheral using "="; no assuming that certain bits are already in the correct state, no assuming that whole registers are set "right" for your application...  Here (for example) you haven't done anything with TCCR4A, and you're assuming some state in TIFR4.

So, why are you bothering to use the Arduino IDE?  Since you seem to be prepared to write your own from-scratch code, it sounds like you don't "need" the arduino libraries.  Since you ARE using different initializations, I don't think you can count on other Arduino libraries continuing to work correctly.  And I doubt that it's because of the wonderful Arduino editor!  That leaves the "upload" button - did you know that you can upload arbitrary .hex files to an arduino board (via its bootloader) using the avrdude command?


I did like this because I have taken from someone some codes done without librairy. If he would have written a lib, it would have been a lot better.

I solve the problem by adding the good inits of TIMERS to be able to still use millis()
and to start my code like this:

Code: [Select]

void loop()
{ for (;;) {

Go Up