I just built the Arduino 1.0 core as a static library in Eclipse and using Windows 7. One thing you didn't mention is that you have to get pins_arduino.h from somewhere as well. For the Uno, which uses the ATMega328P, I believe, I think you want the "standard" variant.
- I copied into the static library project all of the files from:
hardware\arduino\cores\arduino
- I also copied into the static library project the pins_arduino.h file from:
hardware\arduino\variants\standard
Could it be you just got the wrong pins_arduino.h file for your target chip? Also are you sure you have the right chip and clock speed selected under Project Settings => AVR => Target Hardware?
I would delete your Arduino Core static library project, start over by downloading the Arduino 1.0 zip file from arduino.cc, and make a new project from scratch. I just redid the process a couple times to make sure there were no problems and it's pretty quick to apply the project settings once you've done it once (took me < 5 minutes the second time).
Edit
WProgram.h is deprecated in Arduino 1.0. It has been replaced by Arduino.h. Arduino libraries need to support both through #defines on the ARDUINO constant as described here. You need to define ARDUINO for the compiler as well in your main project, which you would do under Project Settings => AVR Compiler => Symbols and Project Settings => AVR C++ Compiler => Symbols respectively. You're going to want add a new Define Syms (-D) named ARDUINO with value 100 in both places I believe (ARDUINO=100).
Edit 2
I also had to explicitly include Arduino.h at the top of my blink.cpp source file (where setup and loop are defined), not sure how to do avoid compiler errors without it.
Edit 3
If you need to use Arduino Libraries, then you need to put the cpp and h files from the Arduino Library root folder into the arduinolib source folder, and any cpp and h files from the Arduino Library utility folder in an arduinolib/utility folder and include both arduinolib and arduinolib/utility in the project directory include paths (ala Project Settings => C/C++ Build => Settings => Tool Settings => AVR Compiler => Directories and Project Settings => C/C++ Build => Settings => Tool Settings => AVR C++ Compiler => Directories). You should only include those libraries in this folder that you actually use or the image will be bloated, presumably by way of each library's global variable declarations. A better way to go is probably to have separate static library projects for each Arduino library you want to use and place a project dependency on them from your main project, but that's a bit more work (could pay off in the long run though).
Although I am not very familiar with the Arduino, your sketch looks fine to me. But, there is something you are missing. ATMega328 is a microcontroller, just like your ATMega2560 on the Arduino. It is not an IC that is purposed to be controlled via SPI.
However, this does not mean that you cannot control this IC via SPI. Just like you did for your ATMega2560, you have to write code for ATMega328 to make it act like an "SPI Slave". Then, you will be able to make two microcontrollers speak SPI and they will communicate.
You have already configured ATMega2560 as an SPI Master, so your mission is half way complete. Now, you have to write code for ATMega328 and make it act like an SPI Slave. Then, on the slave side, you will check if master sends anything. And when master sends something to the slave, slave will check the bytes that you are sending, in this case 0x11 and 0x00 (and 0xFF for LED ON).
Learn how to write a sketch that configures ATMega328 as an SPI Slave, and learn how to receive data when it is configured as an SPI Slave. Then, you will check the data and act accordingly; for example, you will light up the LED when there is 0x11 and 0xFF code received.
Best Answer
The
delay()
function does not return until the requsted interval has expired. During that time it constantly reads the clock, watching for the end of the interval. This means that your program can't do anything else during that time.An alternative is to for your program set a timer that will interrupt whatever the program is doing when the time expires by calling a function to (in this case) toggle the LED state. Meanwhile, once the timer is set, your program can continue on to do something more useful.
In a blinky program, where blinking an LED is the whole point, there isn't anything else needing doing, but in general, you'll want your programs to be able to maintain a display, react to buttons or a keyboard, and read a few sensors, for example, and appear to do them simultaneously.
Update:
A clock or timer is a hardware register the program can read, which is automatically counted up or down at a fixed rate, such as once every millisecond. This counting is done by the hardware without the program having to do anything. To delay for say, 2 seconds, the
delay()
function will read the clock register, add 2000 to it (the number of milliseconds of the required delay) to find the ending time, then keep reading the clock register until it equals or exceeds that time.In the second case, above, a timer register would be set to 2000 (again, the number of milliseconds to delay), but in this case the hardware decrements that register every millisecond, and will interrupt the program when the timer register gets to 0.