Pages: 1 [2]   Go Down
Author Topic: Problem with init() (in wiring.c) when my init of the UART (unsolved)  (Read 1323 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot Nick!

Since I've added this code:
Code:
int main()
{
setup();
loop();
}

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.
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 506
Posts: 19118
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
while (true)
  loop ();
Logged


SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6792
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
    // 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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
void loop()
{ for (;;) {
}
Logged

Pages: 1 [2]   Go Up
Jump to: