When the #BL602 I2C HAL looks dubious ... Refer to the BL602 Reference Manual!
https://github.com/bouffalolab/bl_docs/tree/main/BL602_RM/en
How we hack #PineCone #BL602 #RISCV on Saturday Night @PINE64
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c#L216-L308
#BL602 I2C program doesn't crash now ... But it doesn't read any data from the BME280 Sensor 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c#L216-L308
Found the bug in my #BL602 I2C program ... There are two levels of BL602 I2C API: 1️⃣ High Level (which calls FreeRTOS) 2️⃣ Low Level (which doesn't call FreeRTOS) ... I'm using the Low Level API, so I shouldn't call "hal_i2c_init" in the High Level API
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/main.c#L187-L190
Let's hunt for MEPC (Machine Exception Program Counter) 0x2300 8fe2 in the #RISCV Disassembly ... Yep my buggy code crashed in the #BL602 I2C Interrupt Handler 🤔
https://github.com/lupyuen/bl_iot_sdk/releases/download/v1.0.1/sdk_app_i2c.S
600 Views of my Buggy C Code for #BL602 I2C ... Time to Hyperventilate 😲
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c#L234-L308
Oops #BL602 needs to trigger an #I2C Receive Interrupt before we read the I2C FIFO Input ... So we should call the BL602 I2C Functions in two steps
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c#L271-L299
#BL602 has an I2C queue of 4 bytes ... So we'll send/receive I2C data 4 bytes at a time with interrupts
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c#L238-L263
#BL602 reading #I2C Register on BME280 ... Hope this works 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c#L234-L277
6 undocumented #BL602 I2C Functions ... Let's figure out how to call them 🤔
https://github.com/lupyuen/bl_iot_sdk/blob/i2c/customer_app/sdk_app_i2c/sdk_app_i2c/demo.c
Connect #PineCone #BL602 to BME280 ... Temperature, humidity and air pressure over I2C
https://learn.sparkfun.com/tutorials/sparkfun-bme280-breakout-hookup-guide/all
#BL602 IoT SDK tries to init pins 3 and 4 for I2C ... Guess what happens when "i2cx" is NOT "I2C0" ? 🤔
https://github.com/bouffalolab/bl_iot_sdk/blob/master/components/hal_drv/bl602_hal/bl_i2c.c#L57-L69
IoT Techie and Educator / Apache NuttX PMC