AVR GCC and Arduino?

Hi everybody.

I am doing a special project with the arduino and I am trying to get a Nordic Semi nrf24L01 to work with the arduino.

Some very good base code exists for the 168, and I want to use that. The problem is, it is coded in AVR GCC, and I can't seem to find much documentation as to how to use it with an arduino.

Any help or recommendations would be greatly appreciated.

Thanks

http://www.tinkerer.eu/AVRLib/nRF24L01

Arduino IS AVR GCC. You shouldn't have to do much more than ensure that the arduino part of your sketch doesn't inadvertently conflict with with the non-arduino use of pins/etc.

True, I understand that. But do I still need to follow certain conventions such as void setup() and void loop()? The AVR GCC code doesn’t use that - it is more of a conventional program.

Thanks

Yes, to use the Arduino environment, you'll need to use "setup()" and "loop()". But you should be able to extract the initialistion part from the "main()" in your C code, and put that into "setup()". The rest can go into "loop()", even if it never actually loops.

The easiest thing to do is replace main() in the program you're porting with "loop()", and add a dummy setup() function. I regularly debug sketches on a host system using a construct like

#if defined(DEBUG_ON_UNIX)
/* compiling under unix, define main */
int main(int argc, char **argv)
#else
/* compiler for arduino, defined setup and loop instead */
void setup() {}
void loop()
#endif
{
   // top of sketch code goes here.
}

another solution would be to put the regular main code into the setup() function (or rename your main function to setup() )
and add an empty loop function:

void setup()
{
//YOUR CODE HERE
}

void loop()
{
//NO CODE HERE
}

but you have to rename the main() function. Don’t add a main() function to a sketch.

You can even add your .c file as an external file to your sketch… but still: you must rename the main() function to setup() then.