I2C interrupts non responding anymore

bertino wrote on Tuesday, April 22, 2014:

Hi,

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)

AND

2)It gets wrapped in a function itself.

For example, my I2C function is I2C_WriteReg(Device_Address, Reg_Address, num_data, &beffer[0]);
Related TX interrupts will be generated only I do the following :

uint32_t I2C_Initialize_Register(…)
{
return I2C_WriteReg(Device_Address, Reg_Address, num_data, &beffer[0]);
}

and then I call the function from the task inititlization section :
static void LedTask( void pvParameters )
{
I2C_Initialize_Register(…);
/
if I call I2C_WriteReg(…) here it will not work */

for(;;){
/* 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 configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY (=5) and configLIBRARY_LOWEST_INTERRUPT_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 ?
Best Regards,
Adalberto

rtel wrote on Tuesday, April 22, 2014:

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[0]);

… 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[0]);
}

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).

Regards.