cancel
Showing results for 
Search instead for 
Did you mean: 

Fram write/read error, with stm3wb55?

A Bravos
Associate III

Good afternoon to all forum members. I have a problem with stm32wb55 and i2c protocol. I use i2c (hi2c3) with the connected peripherals Ad7746, adxl345, mcp9808 and they work fine, but if I join fram MB85RC256v, with the write/read in the routine I write above, the result is always 0. On Mcu stm32f4 and stm32f103 works fine, but on stm32wb family it doesn't. Where is the error?

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

#define AD7746_address 0x90  //AD7746 ok work

#define Adxl345_address 0x53<<1 // Adxl345 ok work

#define MB85RC256v_Fram_address 0x50  or  0x50<<1  // Fram MB85RC256v not work

#define T9808_address 0x18<<1 // MCP9808 work

/* USER CODE END PD */

I2C_HandleTypeDef hi2c3;

/*..

*/

static void MX_I2C3_Init(void);

//---

void write_fram8(uint16_t addr,uint8_t wdatafram_8)

{

HAL_I2C_Mem_Write(&hi2c3, MB85RC256v_Fram_address,addr,0xFF,&wdatafram_8,1,10);

}

uint8_t read_fram8(uint16_t addr)

{

HAL_I2C_Mem_Read(&hi2c3, MB85RC256v_Fram_address,addr,0xFF,& rdatafram_8,1,10);

return rdatafram_8;

}

//...

int main(void)

HAL_Init();

SystemClock_Config();

 MX_GPIO_Init();

 MX_USART1_UART_Init();

 MX_USB_PCD_Init();

 MX_I2C3_Init();

MCP9808_Init();

AD7746_Init();

adxl_Init();

for (int i=0; i<100; i++)

{

write_fram8(i,i);

HAL_Delay(50);

printf(" position: %d value: %X \r\n ", i, le_fram8(i));

}

RESULT

position: 0 value 0;

position: 1 value 0;

position: 2 value 0;

position: 3 value 0;

position: 4 value 0;

...

position: 99 value 0;

static void MX_I2C3_Init(void)

{

 /* USER CODE BEGIN I2C3_Init 0 */

 /* USER CODE END I2C3_Init 0 */

 /* USER CODE BEGIN I2C3_Init 1 */

 /* USER CODE END I2C3_Init 1 */

 hi2c3.Instance = I2C3;

 hi2c3.Init.Timing = 0x00707CBB;

 hi2c3.Init.OwnAddress1 = 0;

 hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

 hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

 hi2c3.Init.OwnAddress2 = 0;

 hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;

 hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

 hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

 if (HAL_I2C_Init(&hi2c3) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Analogue filter

 */

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

 {

  Error_Handler();

 }

 /** Configure Digital filter

 */

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

 {

  Error_Handler();

 }

 /* USER CODE BEGIN I2C3_Init 2 */

 /* USER CODE END I2C3_Init 2 */

}

2 REPLIES 2
A Bravos
Associate III

Hello everybody.

I experimented with the code on a stm32f103 and it works, as it writes and reads the eeprom/fram. The same code written in stm32wb, doesn't work.

Don't want to think it's a bug!?

I would appreciate if anyone had the same problem and would like to share a solution.

Thanks

//---code--//

void write_fram8(uint16_t addr,uint8_t wdatafram_8)

{

HAL_I2C_Mem_Write(&hi2c3, MB85RC256v_Fram_address,addr,0xFF,&wdatafram_8,1,10);

}

uint8_t read_fram8(uint16_t addr)

{

HAL_I2C_Mem_Read(&hi2c3, MB85RC256v_Fram_address,addr,0xFF,&rdatafram_8,1,10);

return rdatafram_8;

}

//------------------------------------------

for (int i=0; i<100; i++)

{

write_fram8(i,i);

HAL_Delay(50);

printf(" position: %d value: %X \r\n ", i, read_fram8(i));

}

A Bravos
Associate III

From the research I did, I noticed that the problem with i2c in the stm32wb family is not new. Happens with HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout) for write in e2prom and HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout) for read a eeprom

As I don't see a solution to this bug yet, as a matter of urgency, I am forced to abandon the project I had in mind, for another microcontroller with low consumption/BLE, and that has no problems with the i2c protocol.

To everyone, my thanks for your help that was possible.