Go Down

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

syrinx

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.
Code: [Select]
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:

Quote
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 function `init':
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.

Code: [Select]
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);
}


Code: [Select]

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.

PaulS

Quote
Do you how to solve this?

Rename your init() function. The Arduino provides one. You shouldn't.

syrinx

It's what I did: I rename it into hwsetup(). I call it from main() or even setup(), I don't have compiling error, but the Arduino is not working well.

(sorry, I didn't write correctly the hwsetup(), I've just changed)

PaulS

Quote
but the Arduino is not working well.

Oh, well, that's a real shame.

If you showed some code, and explained what "is not working well" means, perhaps we could do more than sympathize.


syrinx

#4
Jan 20, 2013, 07:46 am Last Edit: Jan 20, 2013, 07:55 am by syrinx Reason: 1
Main .ino file:
Code: [Select]
#include "bluevmega.cpp"

void setup()
{

Serial.begin(57600);
delay(1000);
}

void loop()
{  
hwsetup(); [b]// GLOW: added beacuse I've renamed init() into hwsetup() !!!!!!!!!!!![/b]

int ret;
   unsigned char lastdisp[12];
Serial.println("V1MegaTool");
   for (;;) {
for (;;) {
ret = readpkt(respget); [b]// FX: STAY BLOCKED HERE !!! (GLOW)[/b]
if (ret < 5)
               continue;
           if (respget[3] == INFDISPLAYDATA)
               break;
       }
       if(legacy > 32)
           printser(pullp(PSTR("LEGACY! only V works\r\n")));  
inbuf[inhead++] = Serial.read();
           printser(pullp(PSTR("Mute (ESP)Hold systemUp mainDisp Euro Custom\r\n")));
           lastdisp[0] = 0;
           while (1) {
ret = readpkt(respget);
               if (ret < 5) {
                   continue;
}
               if (respget[3] == INFDISPLAYDATA && memcmp(lastdisp, respget, 12)) {
showinfdisp();
                   memcpy(lastdisp, respget, 12);
               }
if (Serial.available() >= 1 ) {
inbuf[inhead++] = Serial.read();
}
   }
           break;
       }
}

Go Up