diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-26 22:39:09 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-26 22:40:49 -0500 |
commit | 523a5d2f0b3f0d79b16784470870935313dd5775 (patch) | |
tree | b7631b071432bba90eb14aa9540f97c01c5503ac /apps/spi-test/app.c | |
parent | b2dbc4feeb48697fbbdbb7740b6db552a45b3c02 (diff) | |
download | Sensor-Watch-523a5d2f0b3f0d79b16784470870935313dd5775.tar.gz Sensor-Watch-523a5d2f0b3f0d79b16784470870935313dd5775.tar.bz2 Sensor-Watch-523a5d2f0b3f0d79b16784470870935313dd5775.zip |
implement SPI flash chip
Diffstat (limited to 'apps/spi-test/app.c')
-rw-r--r-- | apps/spi-test/app.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/apps/spi-test/app.c b/apps/spi-test/app.c index 54b484ad..2ce2c1f7 100644 --- a/apps/spi-test/app.c +++ b/apps/spi-test/app.c @@ -2,11 +2,20 @@ #include <string.h> #include <peripheral_clk_config.h> #include "watch.h" +#include "spiflash.h" // this is a very basic app to confirm that SPI is working, tested with board OSO-MISC-21-017 and a GD25Q16C Flash chip. void app_init(void) { - watch_enable_spi(); + spi_flash_init(); + + uint8_t buf[3] = {1, 2, 3}; + flash_enable(); + spi_flash_command(CMD_ENABLE_WRITE); + // note that you will need to erase the sector to write different values later: + // spi_flash_sector_command(CMD_SECTOR_ERASE, 0); + spi_flash_write_data(0, buf, 3); + flash_disable(); } void app_wake_from_backup(void) { @@ -23,20 +32,13 @@ void app_wake_from_standby(void) { bool app_loop(void) { - uint8_t get_id_command[1] = {0x9F}; uint8_t buf[3] = {0}; - watch_set_pin_level(A3, false); - - // should print 0, 0, 0 - watch_spi_send(get_id_command, 1); - printf("blank: %x, %x, %x\n", buf[0], buf[1], buf[2]); - - // should print c8, 40, 15 - watch_spi_receive(buf, 3); - printf("ident: %x, %x, %x\n", buf[0], buf[1], buf[2]); - - watch_set_pin_level(A3, true); + flash_enable(); + // should print 1, 2, 3 + spi_flash_read_data(0, buf, 3); + printf("data: %x, %x, %x\n", buf[0], buf[1], buf[2]); + flash_disable(); delay_ms(100); |