I am trying to estalish SPI between ATMEGA256RFR2(master) and ARDUINO DUE(slave). I guess I did not understand the clock settings of the AVR proprerly. My understanding about clock is:
a. The FUSE CKDIV8 - when programmed divides the clock by 8 (If I connect it to 16mhz external one it makes it 2)
b. The LOW.CKSEL_SUT can choose between different clock sources. I chose Internal RC oscillator ,which is 16mhz as per datasheet .
Until I have read , these are the two points through which the sstem clock can be set/changed.
c.The clock rate of the SPI register is programmed with SPCR register SPR0 and SPR1 pins.
1. The CKDIV8 is programmed. So, now , the general clock is at 2 mhz . Am I right ? But to the SPI the clock signal is 2mhz / 4 ? Is it so ?
2. I know the F_CPU is just a software reference for delay and it is not changing the hardware clock.
For now ,I have configured ATMEGA as master , DUE as slave. I sent a value and the DUE receives it , but with a very huge delay.
1. I defined clock with the given above settings and included #define F_CPU 2000000UL this in my code . I obviosly get delay.
2. I chose the Internal clock ; I unprogrammed the CKDIV8 assuming that 16 mhz is the clock frequency of the ATMEGA. SPCR is same 00 , expected that SPI would receive 4 mhz. But still the data receiving on the DUE receives with huge delay. #define F_CPU 16000000UL was included in the code
How can I make the hardware ATMEGA to run at 4mhz and be in sync? I want 4mhz because the DUE default is 4 mhz,as stated here : https://www.arduino.cc/en/Refere.... I would also like to establish duplex communicaton but my "unclear knowledge" of clock seems to be a barrier . Can somebody put me on the right track?