2024-03-11 08:56 AM
Hello.
Recently I received an B-WL5M-SUBG1 board and started to develop a LoRa application
based on the LoRaWAN_End_Node example that I got from STM32Cube_FW_WL_V1.3.0 archive.
I managed to get the example running and sending LoRa packets.
My objective now is to integrate the on-board ISM330DHCX accelerometer to the application.
For that, I've created a file with the functions AccelApp_Init() AccelApp_Run(), platform_write() and platform_read().
In the same file I also declared two other functions "OnAccelData" and "ProcessAccelData"
I followed this file as an example on how to integrate the ISM330DHCX: ism330dhcx_STdC/examples/ism330dhcx_read_data_polling.c
I'm able to retrieve the ISM330DHCX ID by reading the WHO_AM_I register of the device, and to set-up other registers by calling the ISM330 driver functions from AccelApp_Init().
To create a new task, I first changed "utilities_def.h" and created "CFG_SEQ_Task_ProcessAccelData" Id.
"OnAccelData" is a callback for a UTIL_TIMER, that expires every 5 seconds. From the callback, I set the task "CFG_SEQ_Task_ProcessAccelData" to be run.
"ProcessAccelData" is the callback for the "CFG_SEQ_Task_ProcessAccelData" task. In this callback, I then call the I2C functions to check for new data on the ISM330DHCX and retrieve it.
From the "main.c" file, in the main function, I'm calling AccelApp_Init() and AccelApp_Run() like:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LoRaWAN_Init();
/* USER CODE BEGIN 2 */
AccelApp_Init();
AccelApp_Run();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_LoRaWAN_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Unfortnatly, every call from within the "ProcessAccelData" to the I2C bus returns with a HAL_I2C_ERROR_TIMEOUT error.
I have attached the complete code for the accel_app.c file.
The idea is to have the LoRa lmhadler task running together with the accelerometer task, polling for new data.
Is there any other example where I2C communication is performed using the sequencer utility?
Should this be working? Am I missing any other detail?
Thanks in advance!
C. Scherma.
Solved! Go to Solution.
2024-03-15 11:03 AM
After a lot of debugging and recreating the LoRaWAN_End_Node application without the sequencer, I've narrowed it down to the Low Power Mode, which I wasn't using on my custom application.
Back to the original LoRaWAN_End_Node application, in the sys_conf.h file, I changed as below on line 84:
/**
* @brief Disable Low Power mode
* @note 0: LowPowerMode enabled. MCU enters stop2 mode, 1: LowPowerMode disabled. MCU enters sleep mode only
*/
#define LOW_POWER_DISABLE 1
This disables the Low Power Mode and the application work as expected, retrieving new data from sensors throught the I2C bus, before sending the LoRa Message.
2024-03-11 12:51 PM
Further investigating, I reverted the code back to be the same as in the LoRaWAN_End_Node example. Using a oscilloscope I'm monitoring the SDA and SCL pins. The only moment that data is exchanged in the I2C bus, is during the board initialization.
After that, when the TX timer expires and the SendTxData function is called, althou the function EnvSensors_Read is called, no data is exchanged on the I2C bus, and LoRa payload is transmited with default values.
To verify that default values are sent, I changed the default value for temperature from 18.0f to 38.0f on the "sys_sensors.c" file, line 55, and the log now shows:
266s316:VDDA: 254␍␊
266s316:temp: 38␍␊
266s320:TX on freq 916600000 Hz at DR 2␍␊
266s322:SEND REQUEST␍␊
266s693:MAC txDone␍␊
267s675:RX_1 on freq 927500000 Hz at DR 10␍␊
267s726:IRQ_RX_TX_TIMEOUT␍␊
267s726:MAC rxTimeOut␍␊
268s687:RX_2 on freq 923300000 Hz at DR 8␍␊
268s754:IRQ_RX_TX_TIMEOUT␍␊
268s754:MAC rxTimeOut␍␊
␍␊
###### ========== MCPS-Confirm =============␍␊
295s856:VDDA: 254␍␊
295s856:temp: 38␍␊
295s860:TX on freq 916200000 Hz at DR 2␍␊
295s862:SEND REQUEST␍␊
296s233:MAC txDone␍␊
297s215:RX_1 on freq 926300000 Hz at DR 10␍␊
297s266:IRQ_RX_TX_TIMEOUT␍␊
297s266:MAC rxTimeOut␍␊
298s227:RX_2 on freq 923300000 Hz at DR 8␍␊
298s294:IRQ_RX_TX_TIMEOUT␍␊
298s294:MAC rxTimeOut␍␊
␍␊
###### ========== MCPS-Confirm =============␍␊
Another thing I found is that, in any of the files of the LoRaWAN_End_Node project for the STM32CubeIDE, the "UTIL_SEQ_Init()" function is called. I've read the wiki for the sequencer and understood that the function must be called prior to the declaration of the tasks. Managed to edit "sys_app.c" and called "UTIL_SEQ_Init()" right after the default call to "UTIL_TIMER_Init()".
But even with these changes, no data is exchanged on the I2C bus when the call happens from the sequencer callback.
Any info on this, would be of grate help.
BR.
C. Scherma.
2024-03-15 11:03 AM
After a lot of debugging and recreating the LoRaWAN_End_Node application without the sequencer, I've narrowed it down to the Low Power Mode, which I wasn't using on my custom application.
Back to the original LoRaWAN_End_Node application, in the sys_conf.h file, I changed as below on line 84:
/**
* @brief Disable Low Power mode
* @note 0: LowPowerMode enabled. MCU enters stop2 mode, 1: LowPowerMode disabled. MCU enters sleep mode only
*/
#define LOW_POWER_DISABLE 1
This disables the Low Power Mode and the application work as expected, retrieving new data from sensors throught the I2C bus, before sending the LoRa Message.