Raspberry Pi Pico also uses the old SPI terms
#BL602 SPI Registers are remarkably similar to I2C Registers ... So I can reuse my I2C code for SPI 🤔
https://github.com/bouffalolab/bl_docs/tree/main/BL602_RM/en
#BL602 SPI Register Fields look similar to I2C too
https://github.com/bouffalolab/bl_docs/tree/main/BL602_RM/en
Yep #BL602 SPI is copy pasta from I2C ... Even the Register Address. Very nice! 👍
https://github.com/bouffalolab/bl_docs/tree/main/BL602_RM/en
We'll let #BL602 talk simple SPI to BME280 first ... Before talking seriously to ST7789
https://cdn.sparkfun.com/assets/learn_tutorials/4/1/9/BST-BME280_DS001-10.pdf
#BL602 SPI DMA ... Lets you specify a Linked List of Transmit / Receive operations ... That will be executed by the DMA Controller
https://github.com/lupyuen/bl_iot_sdk/blob/master/components/hal_drv/bl602_hal/hal_spi.c#L115
#BL602 SPI DMA uses simple Interrupt Handlers .... Simpler than I2C! Let's experiment with SPI DMA on BME280
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L749-L794
#BL602 SPI DMA is used by AliOS VFS file system ... Which is bundled with the BL602 IoT SDK
https://pine64.github.io/bl602-docs/Components/Middleware/vfs/vfs.html
But if AliOS is really a complete Embedded Operating System ... Why does #BL602 IoT SDK still need FreeRTOS? 🤔
#BL602 SPI Functions are the same as AliOS ... Time to practice my Chinese reading skills
https://help.aliyun.com/document_detail/161063.html?spm=a2c4g.11186623.6.576.391045c4bGoNKS
...But #BL602 SPI HAL doesn't implement all AliOS SPI Functions 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L368
Init the #BL602 SPI Port ... Looks easy
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L41-L58
Nope #BL602 it's a trap! Should call "vfs_spi_init_fullname" to init the SPI port
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L504-L571
Another #BL602 trap! "vfs_spi_init_fullname" doesn't return the SPI Device ... It passes the SPI Device to AliOS! Let's create our own function to init the SPI Port without AliOS 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L504-L571
Init #BL602 SPI Port ... No more traps!
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L42-L69
#BL602 SPI Data Transfer needs a "void *" parameter ... Which is cast to an "spi_ioc_transfer_t" ... That belongs to AliOS 😭
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L464-L502
Good Sunday Morning #PineCone #BL602 @PINE64 ... And #BME280 on SPI! Yep this looks right 👍
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L49-L70
#BL602 SPI Transmit and Receive ... Hope this works 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L72-L102
Our #BL602 SPI program hangs when doing data transfer 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c
#BL602 SPI DMA Transfer is hanging inside "hal_spi_dma_trans" ... According to the debug log 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L472-L510
"hal_spi_dma_trans" hangs while doing #BL602 SPI DMA transfer because it's waiting for a FreeRTOS Event Group ... Which is supposed to be signalled by the DMA Interrupt Handler. Let's comment out the waiting and see what happens...
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L285-L348
Commented out the waiting for #BL602 SPI DMA ... Yep no more hanging ... But no SPI Data received. Interrupt Counters show that DMA Interrupts weren't triggered.
The plot thickens ... Just like my chicken soup 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L285-L353
These 2 #BL602 SPI Functions are begging me to call them ... Phew this SPI HAL is confusing 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L405
#BL602 SPI Transmit seems OK but not SPI Receive ... After calling "hal_spi_init" 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L826-L876
#BL602 SPI DMA uses a Linked List of DMA requests ... Let's dump the DMA Linked List and verify the SPI Transmit and Receive requests
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L160-L199
Aha #BL602 SPI DMA is now Transmitting AND Receiving! The SPI Mode was incorrect ... Got confused between the AliOS docs and the BL602 implementation 🙁
Received SPI Data is garbage though 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L49-L67
Contemplating my Life Choices ... Erm whether I should use #BusPirate to sniff the #BL602 SPI Bus 🤔
...Or use a real Logic Analyser ... To debug the #BL602 SPI Bus? 🤔
https://www.seeedstudio.com/LA2016-Logic-Analyzer-p-2218.html
#PineCone and #Pinenut #BL602 recommended SPI Pins ... Let's try them
https://wiki.pine64.org/wiki/Nutcracker#Pinenut-12S_Module_information
Testing the Recommended SPI Pins for #BL602 #PineCone @ThePine64
https://wiki.pine64.org/wiki/Nutcracker#Pinenut-12S_Module_information
Nope Recommended SPI Pins for #PineCone #BL602 also don't work
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L49-L67
Logic Analyser captures SPI Data between #BusPirate and #BME280 ... So cool! 🤩 Now to capture #BL602 + BME280 and compare
#BL602 SPI Data Pins seem to be flipped ... Based on SPI data sniffed by Logic Analyser 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L49-L67
Let's try 2 #BL602 SPI Transfers instead of 1 ... First SPI Transfer transmits Register ID ... Second SPI Transfer receives the result from BME280
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L70-L114
Nope #BL602 still receiving garbage from BME280 ... Let's do the #SPI Logic Analyser!
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L70-L114
Ugh #BL602 is disrupting the two SPI Transfers ... By setting the Chip Enable Pin high ... Let's control Chip Enable Pin ourselves with GPIO
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L70-L114
Thankfully #BL602 SPI HAL lets us use GPIO to control the Chip Select Pin ... But we have already configured the pin for SPI Function ... Will this conflict with the GPIO Function? 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L479-L519
Nope #BL602 #SPI HAL can't control Chip Select Pin by #GPIO ... Because it has already configured the pin for SPI Port earlier ... Let's control the pin ourselves 👋
https://github.com/lupyuen/bl_iot_sdk/blob/spi/components/hal_drv/bl602_hal/hal_spi.c#L98-L122
Here's how we control #BL602 #SPI Chip Select Pin ourselves ... Using plain old BL602 GPIO
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L47-L128
#PineCone #BL602 #SPI Unsolved Mysteries ... 1️⃣ Why are the SPI Data Pins flipped? 2️⃣ Why does Pin 0 light up the WiFi LED? 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L54-L115
Getting desperate with #BL602 SPI ... Let's try to dump all BME280 Registers ... And see what works
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L129-L182
#PineCone #BL602 SPI works OK yay @PINE64 ! Had to change SPI Phase from 0 to 1 ... Which doesn't sound logical 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L129-L182
#PineCone #BL602 @ThePine64 tested OK with #BME280 over #SPI ... Here's the wiring that doesn't light up the WiFi LED 💡
https://github.com/lupyuen/bl_iot_sdk/blob/spi/customer_app/sdk_app_spi/sdk_app_spi/demo.c#L76
@lupyuen MISO MOSI behavior is defined by the clock polarity and phase parameters. You probably have them set differently in both cases.
https://www.analog.com/media/en/analog-dialogue/volume-52/number-3/introduction-to-spi-interface.pdf
@jeancf Thanks lemme go check...
So I can get into your system wirelessly {;-)
Logic Analyser connected to #BusPirate and #BME280 ... Hope this works 🤔
http://www.qdkingst.com/en/download