SPI demo w/W25Q32 chip
This commit is contained in:
parent
3d0aed8283
commit
6934ea564d
BIN
gpio/spi_demo/Hello-World.sal
Normal file
BIN
gpio/spi_demo/Hello-World.sal
Normal file
Binary file not shown.
20
gpio/spi_demo/README.md
Normal file
20
gpio/spi_demo/README.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# SPI_DEMO
|
||||||
|
|
||||||
|
This is Not intended to be a full demo, but a simple example of how to use the SPI interface on the Flipper Zero.
|
||||||
|
|
||||||
|
Please see [https://youtu.be/W6bGYZ5PgIc](https://youtu.be/W6bGYZ5PgIc) for a video demo.
|
||||||
|
|
||||||
|
My video this Saturday, Nov 18th 2023, will cover how to wire the device between the Flipper Zero and the chip that supports SPI, such as the W25Q32.
|
||||||
|
|
||||||
|
The connections are:
|
||||||
|
- Flipper Pin 2 - MOSI (D0 on the W25Q32)
|
||||||
|
- Flipper Pin 3 - MISO (D1 on the W25Q32)
|
||||||
|
- Flipper Pin 4 - CS (CS on the W25Q32)
|
||||||
|
- Flipper Pin 5 - SCK (SLK on the W25Q32)
|
||||||
|
- Flipper Pin 8 - GND (GND on the W25Q32)
|
||||||
|
- Flipper Pin 9 - 3V3 (VCC on the W25Q32)
|
||||||
|
|
||||||
|
|
||||||
|
The `Hellow-World.sal` file can be viewed using [https://www.saleae.com/downloads/](https://www.saleae.com/downloads/) software. This is a capture of my W25Q32 chip being read by the Flipper Zero. The commands were sent using the `SPI Mem Manager` application.
|
||||||
|
|
||||||
|
You can find the `SPI Mem Manager` application at [https://github.com/flipperdevices/flipperzero-good-faps/tree/dev/spi_mem_manager](https://github.com/flipperdevices/flipperzero-good-faps)
|
12
gpio/spi_demo/app.c
Normal file
12
gpio/spi_demo/app.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <furi.h>
|
||||||
|
#include <furi_hal.h>
|
||||||
|
|
||||||
|
void spi_demo();
|
||||||
|
void spi_demo_v2();
|
||||||
|
|
||||||
|
int32_t main_learn_spi(void* _p) {
|
||||||
|
UNUSED(_p);
|
||||||
|
spi_demo();
|
||||||
|
spi_demo_v2();
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
gpio/spi_demo/app.png
Normal file
BIN
gpio/spi_demo/app.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
14
gpio/spi_demo/application.fam
Normal file
14
gpio/spi_demo/application.fam
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
App(
|
||||||
|
appid="learn_spi_app",
|
||||||
|
name="[WIP] Learn SPI",
|
||||||
|
apptype=FlipperAppType.EXTERNAL,
|
||||||
|
entry_point="main_learn_spi",
|
||||||
|
stack_size=4 * 1024,
|
||||||
|
requires=[
|
||||||
|
"gui",
|
||||||
|
],
|
||||||
|
order=10,
|
||||||
|
fap_icon="app.png",
|
||||||
|
fap_category="GPIO",
|
||||||
|
fap_description="Demo of communicating with W25Q32 IC.",
|
||||||
|
)
|
39
gpio/spi_demo/spi.c
Normal file
39
gpio/spi_demo/spi.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Demo reading from a w25q32 chip using SPI.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <furi_hal.h>
|
||||||
|
|
||||||
|
#define TAG "LearnSPI-SPI"
|
||||||
|
|
||||||
|
static uint32_t timeout = 1000;
|
||||||
|
static FuriHalSpiBusHandle* spi = &furi_hal_spi_bus_handle_external;
|
||||||
|
|
||||||
|
void read_w25q32_spi() {
|
||||||
|
uint8_t command_read_memory[10] = {0x03, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
||||||
|
uint8_t data_response[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Extra space for NULL termination
|
||||||
|
|
||||||
|
furi_hal_spi_acquire(spi);
|
||||||
|
|
||||||
|
if(furi_hal_spi_bus_trx(spi, command_read_memory, data_response, 9, timeout)) {
|
||||||
|
char* data_response_str = (char*)data_response + 4;
|
||||||
|
FURI_LOG_E(
|
||||||
|
TAG,
|
||||||
|
"MESSAGE STORED IN CHIP AT ADDRESS 0x%02X%02X%02X IS: %s",
|
||||||
|
command_read_memory[1],
|
||||||
|
command_read_memory[2],
|
||||||
|
command_read_memory[3],
|
||||||
|
data_response_str);
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "FAILED - read_id_spi failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_hal_spi_release(spi);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spi_demo() {
|
||||||
|
furi_hal_spi_bus_handle_init(spi);
|
||||||
|
read_w25q32_spi();
|
||||||
|
furi_hal_spi_bus_handle_deinit(spi);
|
||||||
|
}
|
42
gpio/spi_demo/spi_v2.c
Normal file
42
gpio/spi_demo/spi_v2.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
Improved demo reading from a w25q32 chip using SPI.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <furi.h>
|
||||||
|
#include <furi_hal.h>
|
||||||
|
|
||||||
|
#define TAG "LearnSPI-SPI-V2"
|
||||||
|
|
||||||
|
static uint32_t timeout = 1000;
|
||||||
|
static FuriHalSpiBusHandle* spi = &furi_hal_spi_bus_handle_external;
|
||||||
|
|
||||||
|
void read_w25q32_spi_v2() {
|
||||||
|
uint8_t command_read_memory[1] = {0x03}; // Read command
|
||||||
|
uint8_t read_memory_address[3] = {0x00, 0x01, 0x00}; // Memory address is 0x000100
|
||||||
|
uint8_t data_response[6] = {0, 0, 0, 0, 0, 0}; // Read 5 bytes + NULL terminator.
|
||||||
|
|
||||||
|
furi_hal_spi_acquire(spi);
|
||||||
|
|
||||||
|
if(furi_hal_spi_bus_tx(spi, command_read_memory, 1, timeout) &&
|
||||||
|
furi_hal_spi_bus_tx(spi, read_memory_address, 3, timeout) &&
|
||||||
|
(furi_hal_spi_bus_rx(spi, data_response, 5, timeout))) {
|
||||||
|
char* data_response_str = (char*)data_response;
|
||||||
|
FURI_LOG_E(
|
||||||
|
TAG,
|
||||||
|
"MESSAGE STORED IN CHIP AT ADDRESS 0x%02X%02X%02X IS: %s",
|
||||||
|
read_memory_address[0],
|
||||||
|
read_memory_address[1],
|
||||||
|
read_memory_address[2],
|
||||||
|
data_response_str);
|
||||||
|
} else {
|
||||||
|
FURI_LOG_E(TAG, "FAILED - read_id_spi failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
furi_hal_spi_release(spi);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spi_demo_v2() {
|
||||||
|
furi_hal_spi_bus_handle_init(spi);
|
||||||
|
read_w25q32_spi_v2();
|
||||||
|
furi_hal_spi_bus_handle_deinit(spi);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user