AnsweredAssumed Answered

I2C setup with Hal libraries

Question asked by robber on Dec 2, 2015
Latest reply on Dec 2, 2015 by Amel N
Hello everyone,
I am new to this forum and to ST microcontrollers and need some help..
Trying to inialize and pick the right functions for Read and Write from the cube(HAL) libraries, to connect with an external Eeprom.
I have to make a function that will have as inputs the Memory address of the eeprom and the data to put in, if we assume that we will be always writing the same size of data. will it be like this?
/* I2C1 init function */

void MX_I2C1_Init(void)
{


  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_DISABLED;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
  HAL_I2C_Init(&hi2c1);


}
/////////////////////
/////////////////////
void EEPromWrite(... Memory_Adress, ... aTxBuffer )
{
   
   
  while (HAL_I2C_Mem_Write(&I2cHandle , (uint16_t)EEPROM_ADDRESS, Memory_Address, I2C_MEMADD_SIZE_16BIT, (uint8_t*)(aTxBuffer + Memory_Address), TXBUFFERSIZE, 10000)!= HAL_OK)
  {
     
    if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
    {
      Error_Handler();
    }
  }
   
}

I dont understand why sum the aTxBuffer with Memory_Address ?
If you can point out some similar examples would be very helpful. Thank you


Outcomes