Problem with I2C-OLED interfacing
I am trying to interface an I2C OLED display with an STM32L053C8 board. However, instead of using STM32CubeMX to initialize my different pins, I had to manually assign them, because the example programs which come along with the board, do not open on CubeMX. I think I have made some error in the initialization. When I run the program in the initialization of the oled( i.e SSD1306_Init() ) part, when it checks whether the device is ready, i.e
if (HAL_I2C_IsDeviceReady(&hi2c1, SSD1306_I2C_ADDR, 1, 20000) != HAL_OK)
it goes into this particular function and gets stuck in an infinite while loop. The part which causes it to get stuck is highlighted in the code.
((HAL_GetTick() - tickstart) > Timeout)) never satisfies.
If someone tells me what I have done wrong, it would be of great help.
HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
{ uint32_t tickstart = 0U;__IO uint32_t I2C_Trials = 0U;
if (hi2c->State == HAL_I2C_STATE_READY)
{ if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) == SET) { return HAL_BUSY; }/* Process Locked */
__HAL_LOCK(hi2c);hi2c->State = HAL_I2C_STATE_BUSY;
hi2c->ErrorCode = HAL_I2C_ERROR_NONE;do
{ /* Generate Start */ hi2c->Instance->CR2 = I2C_GENERATE_START(hi2c->Init.AddressingMode, DevAddress);/* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
/* Wait until STOPF flag is set or a NACK flag is set*/ tickstart = HAL_GetTick(); while ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET) && (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF) == RESET) && (hi2c->State != HAL_I2C_STATE_TIMEOUT)) { if (Timeout != HAL_MAX_DELAY) { if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) { /* Device is ready */ hi2c->State = HAL_I2C_STATE_READY; /* Process Unlocked */ __HAL_UNLOCK(hi2c); return HAL_TIMEOUT; } } }