STM32G0 MCU as I2C Master and Slave on the same peripheral
Is it possible to use the same I2C peripheral to be used as both a master and a slave?
I made use of an STM32G0 MCU and using examples from CubeMX, I got the peripheral I2C2 to work as a slave and a master separately where I am using interrupts for the slave mode and polling for the master.
I am trying to combine it and make it work in both modes. Here is how I am trying to do it:
HAL_I2C_DisableListen_IT(&hi2c2);
result = HAL_I2C_Master_Receive(&hi2c2, (uint16_t) (0x69 << 1), rcvd_data, 3, HAL_MAX_DELAY);
adc_result = rcvd_data[0];
adc_result = (adc_result << 4) + rcvd_data[1];
HAL_I2C_EnableListen_IT(&hi2c2);My code works some of the time but hangs up pretty quick and needs a reset. I don't have a logic analyzer to study the behavior.
Am I doing this right? Is there an example I could follow?
Any help is appreciated.
