Hi this is my question, I'm wondering have I got it right, close or am I completely wrong?
Write a fragment of code in C to write to the SPCR and SPSR registers of the ATMega328P microcontroller to set it up for the following operation:
You may also assume the existence of the macro sei() to enable global interrupts. Include this in your program fragment in the correct place.
My answer:
SPCR = 0b11110110;
SPSR = 0;
sei();
Write a fragment of code in C to write to the SPCR and SPSR registers of the ATMega328P microcontroller to set it up for the following operation:
- SPI Enabled
- LSB transmitted first
- Master SPI Mode selected
- Rising edge is the Leading edge
- Setup on the Leading Edge, sample on the Trailing Edge
- SPI2X disabled, SCK frequency = fosc/64.
- SPI Interrupt Enable selected
You may also assume the existence of the macro sei() to enable global interrupts. Include this in your program fragment in the correct place.
My answer:
SPCR = 0b11110110;
SPSR = 0;
sei();