cancel
Showing results for 
Search instead for 
Did you mean: 

I2C communication halted in HAL_GPIO_EXTI_Falling_Callback

MMish.2
Associate

I'm a biginner on embedded programing and facing an I2C communication halt issue when I put HAL_I2C_Master_Seq_Transmit_IT() in HAL_GPIO_EXTI_Falling_Callback().

STM32CubeIDE: Version: 1.6.0, Build: 9614_20210223_1703 (UTC)

Target board: NUCLEO-G031K8 , Device name : STM32G03x/STM32G04x

Peripheral device : a sensor with I2C + IRQ , Vdd=3.3 from Nucleo

My situation is I've used a NUCLEO-G031K8 board connecting a sensor through I2C + IRQ signal. I2C R/W commnication itself worked well when just polling used, NO IRQ handling. Read-out data can be monitored on Tera term through USB.

Then I wanted to conduct I2C R/W when IRQ event occur. So I wrote "void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)" function by myself. And put the same I2C write function into the Callback function like below.

Then IRQ went low the callback function called correctly I think(checked with printf() msgs). But I2C communcation was halted just after slave address sent.( I've checked with oscilloscope.) Then No response from G0 chip afterwards even IRQ signal went low again.

One more info. I've removed the I2C function in callback function then put GPIO_Pin_toggle function instaed. Thsi GPIO control worked correctly and synced with IRQ.

So I think I'm missing something basic to make I2C start working. But I don't know.

Could you give me any advice on this sitaution?

/Mitsuru

// Code:

I've added "EXTI4_15_IRQHandler();" in main.c.

>>stm32g0xx_it.c:

void EXTI4_15_IRQHandler(void)

{

 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_15);

}

void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)

{

uint8_t rx_data[I2C_MAXSIZE];

if (GPIO_Pin == GPIO_PIN_15)

{

printf("HAL_GPIO_EXIT_Falling_callback: happened!\n");

I2Cdevice_Write_1byte3(ADD_dv25, dv25_reg1, 0x2F);

// converted into HAL_I2C_Master_Seq_Transmit_IT() in this func.

//HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_6);

printf("HAL_GPIO_EXIT_Falling_callback: Done!\n");

}

}

2 REPLIES 2
TDK
Guru

Try to get it working without the interrupt first to verify things works correctly.

Get it working with HAL functions and monitor their return value to ensure they worked okay.

If you feel a post has answered your question, please click "Accept as Solution".
MMish.2
Associate

Hi TDK, Thank you for the reply and advice.

Now it's working. I've changed I2C API from HAL_I2C_Master_Transmit_IT() to HAL_I2C_Master_Transmit() under IRQHandler(). I don't know why it worked. But maybe there is a rule NOT to put "an API with interrupt" under HAL_GPIO_EXTI_IRQHandler() or something like this.

Thank you.