Skip to main content
Pawan Kumar sharma
Associate II
April 10, 2018
Solved

I want to write and read data from M24M01-RMN6TP (EEPROM) by using STM32F427ZITx processor, please help me?

  • April 10, 2018
  • 2 replies
  • 1603 views
Posted on April 10, 2018 at 12:49

I DON'T KNOW ADDRESS OF M24M01-RMN6TP slave.

if((HAL_I2C_Master_Transmit(&hi2c1,(devAddess),(uint8_t *)&buffer,3,100))==HAL_OK)

{

HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_4);

HAL_Delay(200);

}

if((HAL_I2C_Master_Receive(&hi2c1,(devAddress),(uint8_t *)&buffer,3,100))==HAL_OK)

{

HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_3);

HAL_Delay(200);

}

}

#m24m #m24m02 #eeprom-memory #hal #i2c
This topic has been closed for replies.
Best answer by john doe
Posted on April 10, 2018 at 15:02

HAL wants a 16 bit address shifted to the left.  try (uint16_t)(devAddress << 1) instead of (devAddress)

on the premise your EEPROM is configured to read at 0x50, the shifted address is 0xA0  - 0x50 << 1 is 0xA0

The code is very well commented.  Look in STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c 

here's a code snippet to scan the I2C bus of a HAL project:

  printf('Scanning I2C bus:\r\n');

  HAL_StatusTypeDef result;

  uint8_t i;

  for (i=1; i<128; i++)

  {

    /*

     * the HAL wants a left aligned i2c address

     * &hi2c1 is the handle

     * (uint16_t)(i<<1) is the i2c address left aligned

     * retries 2

     * timeout 2

     */

    result = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 2, 2);

    if (result != HAL_OK) // HAL_ERROR or HAL_BUSY or HAL_TIMEOUT

    {

            printf('.'); // No ACK received at that address

    }

    if (result == HAL_OK)

    {

            printf(' 0x%X ', i); // Received an ACK at that address

    }

  }

  printf('\r\n');

2 replies

john doe
john doeBest answer
Senior III
April 10, 2018
Posted on April 10, 2018 at 15:02

HAL wants a 16 bit address shifted to the left.  try (uint16_t)(devAddress << 1) instead of (devAddress)

on the premise your EEPROM is configured to read at 0x50, the shifted address is 0xA0  - 0x50 << 1 is 0xA0

The code is very well commented.  Look in STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c 

here's a code snippet to scan the I2C bus of a HAL project:

  printf('Scanning I2C bus:\r\n');

  HAL_StatusTypeDef result;

  uint8_t i;

  for (i=1; i<128; i++)

  {

    /*

     * the HAL wants a left aligned i2c address

     * &hi2c1 is the handle

     * (uint16_t)(i<<1) is the i2c address left aligned

     * retries 2

     * timeout 2

     */

    result = HAL_I2C_IsDeviceReady(&hi2c1, (uint16_t)(i<<1), 2, 2);

    if (result != HAL_OK) // HAL_ERROR or HAL_BUSY or HAL_TIMEOUT

    {

            printf('.'); // No ACK received at that address

    }

    if (result == HAL_OK)

    {

            printf(' 0x%X ', i); // Received an ACK at that address

    }

  }

  printf('\r\n');
Pawan Kumar sharma
Associate II
April 11, 2018
Posted on April 11, 2018 at 08:39

Hi

doe.john.016

Thanks for your quick reply,It was very helpful for me.

pawan sharma

india