// // spi.c // // System headers #include // Project headers #include "spi.h" // In this file, you will need to write the contents of the SPI communication routines. // You need to setup SPI communication in SPI_MasterInit() and // transmit data in SPI_MasterTransmit(...). // // HINT: Check out the defines in the file defines.h to see defines // such as data direction registers and bit positions, and as always: // RTFD #define MOSI_bm (1 << 4) //on port A #define SCK_bm (1 << 6) //on port A #define SPI_PORT PORTA // #define CS_bm (1 << 6) //on port C #define CS_PORT PORTC // #define SPI_IF_ENABLE_bp 0 void SPI_MasterInit() { // Initialize the SPI port as master // You will need to set MOSI, SCK, CS (slave select) as outputs SPI_PORT.DIRSET = (MOSI_bm) | (SCK_bm); //Set pins as output CS_PORT.DIRSET = (CS_bm); CS_PORT.OUTSET = (CS_bm); //Set CS high -> OLED inactive // Now enable SPI, Master and set clock rate SPI0.CTRLA |= (SPI_ENABLE_bm) | (SPI_MASTER_bm); //Default clock divisor of 4 is fine //Make sure CS does not disable master mode SPI0.CTRLB |= (SPI_SSD_bm); SPI0.INTCTRL |= (1<