cancel
Showing results for 
Search instead for 
Did you mean: 

My Read/Write data EEPROM not valid

ANapa
Associate III

Hi All.

Please help me!

Platform/Configurations:

stm32F746IGT6

EEPROM 24AA025E48T

PB7(165)  SDA

PB8(167) SCL

1. Code generated from STM32CubeMx:

static void MX_I2C1_Init(void)

{

 hi2c1.Instance = I2C1;

 hi2c1.Init.Timing = 0x00303D5B;

 hi2c1.Init.OwnAddress1 = 0;

 hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

 hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 hi2c1.Init.OwnAddress2 = 0;

 hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;

 hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

 if (HAL_I2C_Init(&hi2c1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Analogue filter

 */

 if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Digital filter

 */

 if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)

 {

  Error_Handler();

 }

}

2. My Functions for validate read/write:

uint16_t devAddr = (0x50 << 1); // 0xA0

uint16_t memAddr = 0x0100;

HAL_StatusTypeDef status;

void init() {

  const char wmsg[] = "Some data";

  char rmsg[sizeof(wmsg)];

  // HAL expects address to be shifted one bit to the left

   

   

  // Hint: try to comment this line

  HAL_I2C_Mem_Write(&hi2c1, devAddr, memAddr, I2C_MEMADD_SIZE_16BIT,

    (uint8_t*)wmsg, sizeof(wmsg), HAL_MAX_DELAY);

  for(;;) { // wait...

    status = HAL_I2C_IsDeviceReady(&hi2c1, devAddr, 1,

                    HAL_MAX_DELAY);

    if(status == HAL_OK)

      break;

  }

memset(rmsg, 0, sizeof(rmsg));

  HAL_I2C_Mem_Read(&hi2c1, devAddr, memAddr, I2C_MEMADD_SIZE_16BIT,

    (uint8_t*)rmsg, sizeof(rmsg), HAL_MAX_DELAY);

  if(memcmp(rmsg, wmsg, sizeof(rmsg)) == 0) {

    const char result[] = "Test passed!\r\n";

    funcOk();

  } else {

    funcFail();      

  }

}

void funcOk()

{

while(1)

{

}

}

void funcFail()

{

while(1)

{

}

}

3. Result:

Write data to i2c EEPROM

uint16_t devAddr = (0x50 << 1);// 0xA0

uint16_t memAddr = 0x0100;

wmsg = "Some data"

wmsg[0]=0x53;'S'

wmsg[1]=0x6F;'o'

wmsg[2]=0x6D;'m'

wmsg[3]=0x65;'e'

wmsg[4]=0x20;' '

wmsg[5]=0x64;'d'

wmsg[6]=0x61;'a'

wmsg[7]=0x74;'d'

wmsg[8]=0x61;'a'

wmsg[9]=0x00;

HAL_I2C_Mem_Write(&hi2c1, devAddr, memAddr, I2C_MEMADD_SIZE_16BIT, (uint8_t*)wmsg, sizeof(wmsg), HAL_MAX_DELAY);

Read data to i2c EEPROM

memset(rmsg, 0, sizeof(rmsg));

HAL_I2C_Mem_Read(&hi2c1, devAddr, memAddr, I2C_MEMADD_SIZE_16BIT, (uint8_t*)rmsg, sizeof(rmsg), HAL_MAX_DELAY);

rmsg[0]=0x61;'a'

rmsg[1]=0x00;

rmsg[2]=0x6D;'m'

rmsg[3]=0x65;'e'

rmsg[4]=0x20;' '

rmsg[5]=0x64;'d'

rmsg[6]=0x00;

rmsg[7]=0x1E;

rmsg[8]=0x10;

rmsg[9]=0x00;

1 REPLY 1

So how exactly does a 2Kbit (256-Byte) memory use a 16-bit address?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..