Skip to main content
STM32L0Fan
Associate II
July 6, 2021
Question

Have I to use an I2C pin to write into EEPROM ?

  • July 6, 2021
  • 6 replies
  • 2535 views

I ask this question because I am already using all the i2c pins for my lcd screen and I need to write in EEPROM and it seems that I need to configure a I2C to use the hal function to write ...

This topic has been closed for replies.

6 replies

Mike_ST
Technical Moderator
July 6, 2021

Hello,

If you have an I2C EEPROM in your design, you'll have to configure an I2C instance to communicate with it.

STM32L0Fan
Associate II
July 6, 2021

I saw that it was maybe possible to use a SPI pin, do you know if it is possible to write/read eeprom with SPI ?

(thank you for your first answer btw)

Andrew Neil
Super User
July 6, 2021

@STM32L0Fan​ : "do you know if it is possible to write/read eeprom with SPI ?"

That depends on the EEPROM:

  • if it's an I2C EEPROM, then you can only read it with I2C;
  • if it's an SPI EEPROM, then you can only read it with SPI;
  • some EEPROMs can work with both SPI and I2C

You will have to study the documentation for your EEPROM to find which applies ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Mike_ST
Technical Moderator
July 6, 2021

1) SPI is not I2C.

2) There is solution to simulate I2C using 2 GPIO. google "STM32 software I2C", hopefully you'll find something.

LMI2
Senior III
July 6, 2021

Besides, an I2C bus can be connected to more than one devices/slaves. I2C devices have addresses, so that it is possible to know what device you are currently using.

Andrew Neil
Super User
July 6, 2021

As @LMI2​ said, I2C is a bus - the whole point of a bus is that multiple devices can share it. That's why it has addresses.

You don't need a separate I2C for each peripheral:

0693W00000BcwrDQAR.pnghttps://en.wikipedia.org/wiki/I%C2%B2C

https://learn.sparkfun.com/tutorials/i2c/all

https://learn.adafruit.com/i2c-addresses

https://www.i2c-bus.org/

https://www.nxp.com/docs/en/user-guide/UM10204.pdf

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
STM32L0Fan
Associate II
July 6, 2021

Ok thank you for your answer, the answer to my issue is that with the hal function : HAL_FLASHEx_DATAEEPROM_Program() you can do what I wanted to do.

Tesla DeLorean
Guru
July 6, 2021

That would suggest you're using an STM32L0 part, with an Internal EEPROM, not an external one using I2C or SPI

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