We create the "spi_test" Demo App in #NuttX ... By copying the "hello" Demo App
Fixing our "spi_test" app for #NuttX ... Rename "hello_main.c" to "spi_test_main.c"
In our #NuttX App "spi_test", change all "hello" to "spi_test" ... Remember to Preserve Case!
1️⃣ make distclean 2️⃣ configure.sh 3️⃣ make menuconfig ... Our #NuttX App "spi_test" magically appears!
#NuttX SPI Interface is defined here ... Let's call it from our "spi_test" app
Can our #NuttX App directly call the SPI Interface? Let's find out! 🤔
#NuttX SPI Interface needs an SPI Device "spi_dev_s" ... How do we get an SPI Device? 🤔
Tracing thru #NuttX Virtual File System ... We see that ioctl() maps the File Descriptor to a File Struct
#NuttX File Struct contains a Private Pointer to the SPI Driver "spi_driver_s"
#NuttX SPI Driver "spi_driver_s" contains the SPI Device "spi_dev_s" ... That we need for testing the SPI Interface! But the SPI Device is private and hidden from apps 🙁
Instead we copy an existing #NuttX SPI Device Driver to test the SPI Interface ... We pick the simplest smallest SPI Device Driver: dat-31r5-sp
We create a new #NuttX SPI Device Driver ... By copying "dat-31r5-sp.c" to "spi_test_driver.c"
In our SPI Test Driver: Change all "dat31r5sp" to "spi_test_driver" ... Remember to Preserve Case!
Do the same to create the Header File for our #NuttX Driver: spi_test_driver.h
At #NuttX Startup, register our SPI Test Driver as "/dev/spitest0"
Add our SPI Test Driver to #NuttX Kconfig
Our SPI Test Driver for #NuttX appears in "make menuconfig"!
Remember to enable "SPI0" and "SPI Character Driver" in #NuttX ... Or our SPI Test Driver won't start
Here's what happens when we make a boo-boo and #NuttX won't start
Update the Makefile "Make.defs" ... So that #NuttX will build our SPI Test Driver
Back to our #NuttX SPI Test App ... Here's how we open the SPI Test Driver and write data
This appears when we run our #NuttX SPI Test App ... Let's study our SPI Test Driver
Every #NuttX Device Driver defines the File Operations for the device ... Here are the open(), close(), read(), write() and ioctl() operations for our SPI Test Driver
In the write() operation for our #NuttX SPI Test Driver, we 1️⃣ Lock the SPI Bus 2️⃣ Config the SPI Interface 3️⃣ Select the SPI Device 4️⃣ Transfer SPI Data 5️⃣ Deselect and Unlock
Here's how we configure the #NuttX SPI Interface
We implement the Read Operation for our #NuttX SPI Driver ... So that we can fetch the SPI Response from SX1262
Our #NuttX App transmits an SPI Command to SX1262 ... And reads the SPI Response from SX1262
#BL602 SPI Chip Select has a problem ... It goes High after EVERY byte ... Which is no-no for SX1262 ... Solution: We control Chip Select via GPIO
Here's our #NuttX App controlling SPI Chip Select via GPIO
Now our #NuttX App is ready to read an SX1262 Register over SPI!
@lupyuen -- If I'm understanding this code correctly, then it is very clean and straight forward. Good job!!! 👍
QOTO: Question Others to Teach Ourselves. A STEM-oriented instance.
An inclusive free speech instance.
All cultures and opinions welcome.
Explicit hate speech and harassment strictly forbidden.
We federate with all servers: we don't block any servers.