Referencing ATmega328p manual, I only can send 1 byte at time. However MCP4802 specs say that MCP4802 wish to get 2 bytes (4 info bits + 8 data bits + 4 don't care bits).
I have written Arduino code that should send this data to MCP4802, however it doesn't work - output on oscilloscope is noise :(
What is wrong with my SPI interfacing with MCP4802?? How do I send data to it?
Code:
byte counter = 0;
void setup() {
DDRB |= (1 << DDB5) | (1 << DDB3) | (1 << DDB2); // SPI.begin();
PORTB |= (1 << PORTB2); // CS goes ON
SPCR = (1 << SPE) | (1 << MSTR) | (0 << CPOL) | (0 << CPHA) | (8 << SPR0); // SPI init
}
void loop() {
PORTB &= ~(1 << PORTB2); // CS LOW
SPDR = 0b00010000;
SPDR = sine_wave[counter];
SPDR = 0b00000000;
while (!(SPSR & (1<<SPIF)));
PORTB |= (1 << PORTB2); // CS BACK HIGH
counter++;
}