How doi use the stm32f207vgt6 HAL Library to write and read the EEPROM using I2C.
void MX_I2C1_Init(void)
{ HAL_I2C_MspInit(&hi2c1);hi2c1.Instance = I2C1;
hi2c1.Init.ClockSpeed = 100000; hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; hi2c1.Mode = HAL_I2C_MODE_MASTER; if (HAL_I2C_Init(&hi2c1) != HAL_OK) { xprintf_temp('I2c1 Init error'); Error_Handler(); }/* Enable the selected I2C peripheral */
I2C1->CR1 |= I2C_CR1_PE;}void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
{GPIO_InitTypeDef GPIO_InitStruct;
if(i2cHandle->Instance==I2C1) { /* USER CODE BEGIN I2C1_MspInit 0 *//* USER CODE END I2C1_MspInit 0 */
/**I2C1 GPIO Configuration PB6 ------> I2C1_SCL PB7 ------> I2C1_SDA */ GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);/* Peripheral clock enable */
__HAL_RCC_I2C1_CLK_ENABLE(); /* USER CODE BEGIN I2C1_MspInit 1 *//* USER CODE END I2C1_MspInit 1 */
}}char temp[15],val = 0;
val = HAL_I2C_Master_Transmit(&hi2c1,0x18,'EEPROM TEST',15,100000);HAL_I2C_Master_Transmit it retuns 1(i.e HAL_ERROR)
val = HAL_I2C_Master_Receive(&hi2c1,0x18,temp,15,100000);
HAL_I2C_Master_Receive it retuns 1(i.e
HAL_ERROR)
while am receiving the data (i.e temp data) . am not getting original data.
thanks