From 1c8e8805d82db1081c3abd2dbd32aada19fafe2c Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Tue, 31 Dec 2019 23:09:11 +0000 Subject: [PATCH] wip sram driver --- drivers/sram.c | 32 ++++++++++++++++++++++++++++++++ drivers/sram.h | 6 ++++++ 2 files changed, 38 insertions(+) create mode 100644 drivers/sram.c create mode 100644 drivers/sram.h 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);