I'm setting up a FreeRTOS v8.0.0 application on an STM32L1xxB (Cortex M3) based. I have a strange issue when calling I2C functions within my tasks :
whenever I call a function to write some I2C data it will trigger corresponding interrupts only if :
1) it gets called in the task initializazion section (before the inifinite for loop)
2)It gets wrapped in a function itself.
For example, my I2C function is I2CWriteReg(DeviceAddress, RegAddress, numdata, &beffer);
Related TX interrupts will be generated only I do the following :
return I2CWriteReg(DeviceAddress, RegAddress, num_data, &beffer);
and then I call the function from the task inititlization section :
static void LedTask( void pvParameters )
/ if I call I2C_WriteReg(...) here it will not work */
/* if I call I2C_WriteReg(...) here it will not work */
Same thing holds for I2C RX interrupts when I use I2C_ReadReg(...)
I've taken precautions on NVICPriorityGroup = 4 and tested the I2C interrupts with priority 0 (maximum) and then 12 that is between configLIBRARYMAXSYSCALLINTERRUPTPRIORITY (=5) and configLIBRARYLOWESTINTERRUPT_PRIORITY(=15) since in later developments I'm planning to use xSemaphoreGiveFromISR(...) functions within I2C interrupt context to wake up tasks waiting for I2C operations.
Do you have any suggestion on what my problem might be related to ?
If I understand your post correctly it would seem rather bizarre, which of course it can't really be, there must be some logical explanation. If I understand you correctly then calling:
ReturnedValue = I2C_WriteReg(Device_Address, Reg_Address, num_data, &beffer);
... does not result in the expected value in the ReturnedValue variable, but calling
uint32_t AnOtherFunction( void )
return I2C_WriteReg(Device_Address, Reg_Address, num_data, &beffer);
ReturnedValue = AnOtherFunction();
does result in the expected value in the ReturnedValue variable.
What is the expected value, and why do you say the first case is not working? Can you step through the assembly code in each case to see what the differences are? The value returned from the function should be returned in R0 (the register R0).
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.