Hello.
I have a conflict with the ini() from wiring.c and my own init of the UARTs.
This is working well. The Arduino is doing what it should be.
void init()
{
cli();
v1state = inmsgstate = inmsglen = polarity = bitcnt = 0;
DDRB = _BV(PB7); // PB7/LED
// UART init
#include <util/setbaud.h>
UBRR3H = UBRR0H = UBRRH_VALUE;
UBRR3L = UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR3A = UCSR0A = _BV(U2X3);
#endif
UCSR3C = UCSR0C = _BV(UCSZ30) | _BV(UCSZ31); // 8N1
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); // Enable TX and RX
// Timer init
GTCCR = 0; //_BV(PSR10); /* reset prescaler */
// 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
sei(); // enable interrupts
// and sleep between events
set_sleep_mode(SLEEP_MODE_IDLE);
}
When I want to add this code in py own project, I get a conflict with init() of wiring.c.
This error:
C:\Users\syrinx\AppData\Local\Temp\build6135219376461108096.tmp\core.a -LC:\Users\syrinx\AppData\Local\Temp\build6135219376461108096.tmp -lm
core.a(wiring.c.o): In functioninit': C:\Portable\Arduino\arduino-1.0.3\hardware\arduino\cores\arduino/wiring.c:193: multiple definition of
init'
bluevirq.c.o:C:\Users\syrinx\AppData\Local\Temp\build6135219376461108096.tmp/bluevirq.c:347: first defined here
Then I've started to change the function and to rename is hwsetup() and to call it from setup(), or even from main(). I don't have compiling error, but the Arduino is not doing its job. I guess the UARTs are not well set. But as I change almost nothing, I think the UARTs are set too late or there is a conflict with init() from wiring.c
But I don't have any error during compiling.
void hwsetup()
{
cli();
v1state = inmsgstate = inmsglen = polarity = bitcnt = 0;
DDRB = _BV(PB7); // PB7/LED
// UART init
#include <util/setbaud.h>
UBRR3H = UBRR0H = UBRRH_VALUE;
UBRR3L = UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR3A = UCSR0A = _BV(U2X3);
#endif
UCSR3C = UCSR0C = _BV(UCSZ30) | _BV(UCSZ31); // 8N1
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0); // Enable TX and RX
// Timer init
GTCCR = 0; //_BV(PSR10); /* reset prescaler */
// 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
sei(); // enable interrupts
// and sleep between events
set_sleep_mode(SLEEP_MODE_IDLE);
}
void loop()
{ hwsetup();
....
}
I should add that all is in 2 different files but it's working well before to add some codes of my own. I use <EEPROM.h> and "XBee.h".
Do you how to solve this? Should I create a library which, I guess, will be called before setup()?
Thank you.