I'm trying to convert this to direct port manipulation for the ATMEGA1280 and have the following:
Arduino IDE using spi.h:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3);
SPI.setClockDivider(SPI_CLOCK_DIV16); // 1mhz
This is the equivalent of direct port manipulation. Did I do it right?
// SPI.begin();
DDRB |= (1<<PB1); //pinMode2(SCK, OUTPUT);
DDRB |= (1<<PB2); //pinMode2(MOSI, OUTPUT);
DDRB |= (1<<PB0); //pinMode2(SS, OUTPUT);
PORTB |= (1<<PB0); // SS HIGH
PORTB &= ~(1<<PB1); // SCK LOW
PORTB &= ~(1<<PB2); // MOSI LOW
SPCR |= _BV(MSTR);
SPCR |= _BV(SPE);
//
SPCR &= ~(_BV(DORD)); //SPI.setBitOrder(MSBFIRST);
SPCR = (SPCR & ~SPI_MODE_MASK) | SPI_MODE3; //SPI.setDataMode(SPI_MODE3);
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (SPI_CLOCK_DIV16 & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((SPI_CLOCK_DIV16 >> 2) & SPI_2XCLOCK_MASK); //SPI.setClockDivider(SP