STM32L0C8T6 failed to communicate with M24C02 through IIC
STM32L0C8T6 failed to communicate with M24C02 through IIC,iic uses cubemx default configuration,The relevant code show as below:
#define ADDR_24LCxx_Write 0xA0
#define ADDR_24LCxx_Read 0xA1
#define IIC_BufferSize 256
uint8_t IIC_WriteBuffer[IIC_BufferSize],IIC_ReadBuffer[IIC_BufferSize];
uint8_t IIC_flag = 0;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET); //eeprom power on
IIC_WriteBuffer[0] = 0x01;
IIC_WriteBuffer[1] = 0x02;
IIC_flag = HAL_I2C_Mem_Write(&hi2c1, ADDR_24LCxx_Write, 0, I2C_MEMADD_SIZE_8BIT,IIC_WriteBuffer,8, 1000);
if(IIC_flag == HAL_OK)
{
sprintf(string,"IIC write succeed!\r\n");
HAL_UART_Transmit(&huart1,(uint8_t*)string,strlen((char *)string),1000);
}
else
{
sprintf(string,"IIC write falsed!IIC_flag: %d\r\n",IIC_flag);
HAL_UART_Transmit(&huart1,(uint8_t*)string,strlen((char *)string),1000);
}
Online debugging code stops here:
/* Send Slave Address and Memory Address */
if (I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)
{
if (hi2c->ErrorCode == HAL_I2C_ERROR_AF)
{
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
return HAL_ERROR;
}
else
{
/* Process Unlocked */
__HAL_UNLOCK(hi2c);
return HAL_TIMEOUT;
}
}
sch:
