Hello,
I'm unable to make master mode SPI working on my ATmega644.
Useful information: I program in c (with WINAVR) on an ATmega644 clocked at 20Mhz. I use an oscilloscope to visualize the signal.
On the oscilloscope, I only observe the PB4 pin going from 1 to 0. Nothing else happens ... even no clock!
The hardware part is correct (i've checked several times before posting).
Here is the code reduced to the essential :
#include <avr/io.h>#define F_CPU 20000000UL
int main (void)
{// make the MOSI, SCK, and SS pins outputs DDRB |= ( 1 << PB5 ) | ( 1 << PB7 ) | ( 1 << PB4 ); PORTB |= (1 << PB4); // SS high // make sure the MISO pin is input DDRB &= ~( 1 << PB6 ); // set up the SPI module: SPI enabled, MSB first, master mode, // clock polarity and phase = 0, F_osc/8 SPCR = 0b01010001; SPSR = 0b00000001; // set double SPI speed for F_osc/8 //------------------------------------------------------------------------ PORTB &= ~( 1 << PB4); //PB4 low SPDR = 10; while ( ! ( SPSR & ( 1 << SPIF ))); PORTB |= (1 << PB4); //PB4 high while (1) { } return 1;
}
Any idea ? Thank you!