HAL_I2C_Slave_Receive fails to read data from ESP32 waiting for I2C_FLAG_RXNE
Hi!
I am having trouble using HAL_I2C_Slave_Receive for receiving data. Troubleshooting, I am finding that HAL_I2C_Slave_Receive times out or gets a I2C_FLAG_STOPF flag in I2C_WaitOnRXNEFlagUntilTimeout.
I know that the I2C network and pull-ups work, because:
- The STM32 is successfully communicating with ESP32s as a master, both writing and reading.
- The ESP32s are successfully communicating in between themselves in both roles
- If I tell HAL_I2C_Slave_Receive the exact number of bytes to read, in this case 14, I then see that the correct data ends up in the buffer, even though the HAL_I2C_Slave_Receive returns an error. Like:
HAL_I2C_Slave_Receive(&I2cHandle, data, 14, 5000);However, there seems to be some incompatibility, and as the ESP32:s are happy with what HAL_I2C_Master_Transmit sends them, so I am suspecting that the problem is on the STM32 side.
I have tried with:
- I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_ENABLED and *DISABLED
- Different speeds (10000-400000)
- Changing the duty cycles
- Different stuff on the ESP32 side
My config:
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// GPIO_InitStruct.Alternate = GPIO_AF1_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Peripheral clock enable */
__HAL_RCC_I2C1_CLK_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
HAL_Init();
I2cHandle.Instance = I2C1;
I2cHandle.Init.OwnAddress1 = CONFIG_I2C_ADDR << 1; // This needs to be left-shifted.
I2cHandle.Init.ClockSpeed = 100000;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
I2cHandle.Init.OwnAddress2 = 0;
//I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
int init_ret = HAL_I2C_Init(&I2cHandle);Versions:
I am using the current ststm32-platform (https://github.com/platformio/platform-ststm32) for PlatformIO, specifically, stm32f1xx_hal_i2c.c. However it seems to me that this might not be a distribution issue.