summaryrefslogtreecommitdiff
path: root/code_refs/scratchpad.c
diff options
context:
space:
mode:
Diffstat (limited to 'code_refs/scratchpad.c')
-rw-r--r--code_refs/scratchpad.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/code_refs/scratchpad.c b/code_refs/scratchpad.c
new file mode 100644
index 0000000..0fc1cfa
--- /dev/null
+++ b/code_refs/scratchpad.c
@@ -0,0 +1,37 @@
+ W25Q_STATE s = W25Q_Init(); // init the chip
+ s = W25Q_EraseSector(0); // erase 4K sector - required before recording
+
+ // make test data
+ u8_t byte = 0x6D;
+ u8_t byte_read = 0;
+ u8_t in_page_shift = 0;
+ u8_t page_number = 0;
+ // write data
+ s= W25Q_ProgramByte(byte, in_page_shift, page_number);
+ // read data
+ s = W25Q_ReadByte(&byte_read, in_page_shift, page_number);
+ s = W25Q_Sleep();
+ char str[10];
+ sprintf(str, "read: %i", byte_read);
+ SHARPMEM_write(&lcd, str, 0, 0, 51, true, false);
+ SHARPMEM_refresh_display(&lcd);
+
+ if(!HAL_I2C_IsDeviceReady(&hi2c1, 0x32, 3, 1000)) {
+ SHARPMEM_write(&lcd, "I2C works", 0, 0, 17, true, false);
+ SHARPMEM_refresh_display(&lcd);
+ uint8_t whoami[1] = {0};
+ char whoami_str[10];
+ HAL_StatusTypeDef e = HAL_I2C_Mem_Read(&hi2c1, 0x3C, 0x22, 1, whoami, 1, 1000);
+ if(!e){
+ sprintf(whoami_str, "%i", byte_read);
+ SHARPMEM_write(&lcd, whoami_str, 0, 0, 34, true, false);
+ SHARPMEM_refresh_display(&lcd);
+ } else {
+ sprintf(whoami_str, "err: %x", (uint8_t)e);
+ SHARPMEM_write(&lcd, whoami_str, 0, 0, 34, true, false);
+ SHARPMEM_refresh_display(&lcd);
+ }
+ } else {
+ SHARPMEM_write(&lcd, "I2C doesn't work", 0, 0, 17, true, false);
+ SHARPMEM_refresh_display(&lcd);
+ }