#define FW_WREN 0x06 #define FW_WRDI 0x04 #define FW_RDID 0x9F #define FW_RDSR 0x05 #define FW_READ 0x03 #define FW_FAST_READ 0x0B #define FW_PW 0x0A #define FW_PP 0x02 #define FW_PE 0xDB #define FW_SE 0xD8 #define FW_DP 0xB9 #define FW_RDP 0xAB int getID(void) { int result; //REG_IME = 0; // disable interrupts (critical section) // Get ID while (SERIAL_CR & SPI_BUSY); SERIAL_CR = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_FIRMWARE; SERIAL_DATA = FW_RDID; while (SERIAL_CR & SPI_BUSY); result = 0; for (int i = 0; i < 3; i++) { SERIAL_DATA = 0; while (SERIAL_CR & SPI_BUSY); result = (SERIAL_DATA & 0xFF) | (result<<8); } // Get status while (SERIAL_CR & SPI_BUSY); SERIAL_CR = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_FIRMWARE; SERIAL_DATA = FW_RDSR; while (SERIAL_CR & SPI_BUSY); SERIAL_DATA = 0; while (SERIAL_CR & SPI_BUSY); result = ((SERIAL_DATA & 0xFF) << 24) | result; //REG_IME = 1; // enable interrupts return result; }