diff --git a/drivers/sram.c b/drivers/sram.c new file mode 100644 index 0000000..66fb27f --- /dev/null +++ b/drivers/sram.c @@ -0,0 +1,32 @@ +#include "sram.h" + +// 23LCV512 64kB SPI SRAM + +uint8_t sram_status() { + uint8_t v; + PORTB &= ~(1 << 2); + spi_transfer(0x05); + v = spi_transfer(0x00); + PORTB |= (1 << 2); + return v; +} + +uint8_t sram_read(uint16_t addr) { + uint8_t v; + PORTB &= ~(1 << 2); + spi_transfer(0x03); + spi_transfer(addr & 0xFF); + spi_transfer(addr > 8); + v = spi_transfer(0x00); + PORTB |= (1 << 2); + return v; +} + +void sram_write(uint16_t addr, uint8_t v) { + PORTB &= ~(1 << 2); + spi_transfer(0x02); + spi_transfer(addr & 0xFF); + spi_transfer(addr > 8); + spi_transfer(v); + PORTB |= (1 << 2); +} diff --git a/drivers/sram.h b/drivers/sram.h new file mode 100644 index 0000000..d3150a2 --- /dev/null +++ b/drivers/sram.h @@ -0,0 +1,6 @@ +#include +#include + +uint8_t sram_status(); +uint8_t sram_read(uint16_t addr); +void sram_write(uint16_t addr, uint8_t v);