/* * Bit-Banged SPI routines */ //#define DEBUG_SLOW_SPI_TRAFFIC #include "spi.h" void spiInit(void) { MI_dir; MO_dir; SCK_dir; CS_dir; SCK_off; MO_off; CS_on; } uint8_t spiReadWrite(uint8_t command) { SCK_off; MO_off; uint8_t result = 0; for (uint8_t i = 0; i < 8; i++) { if (command & 0x80) { MO_on; } else { MO_off; } command = command << 1; if (MI_1) { result = (result << 1) | 0x01; } else { result = result << 1; } SCK_on; NOP(); #ifdef DEBUG_SLOW_SPI_TRAFFIC NOP(); NOP(); NOP(); NOP(); #endif SCK_off; NOP(); #ifdef DEBUG_SLOW_SPI_TRAFFIC NOP(); NOP(); NOP(); NOP(); #endif } return result; }