2025-08-19 1:11 AM - last edited on 2025-08-19 1:31 AM by mƎALLEm
Bonjour à tous, cela fait une semaine que je dois développer une API pour la mémoire sécurisée at88sc12816c
De chez Atmel mais trés malheuresement j’arrive paz à établir la communication entre ma carte maitre qui est un stm32f412zgt6 et la mémoire eeprom.
De mon côté, j’ai bien compris le fonctionnement de la mémoire mais sauf que dans ce dernier les adresses sont diverses, j’explique par exemple pour faire une écriture
dans une UserZone c’est B0 et cet octet ce termine par 0 ce qui est correctement compris par la HAL pour faire de l’écriture en i2c
mais dans le cas d’une lecture aussi par exemple on l’adresse qui se termine encore 0, alros que dans un protocole i2c standard pour lire le dernier bit de l’octet d’adresse doit être
à 1. Et je pense que c’est exactement ce que la HAL ne comprend pas à son niveau. J’ai vraiment besoin d’aide pour avancer
2025-08-19 1:16 AM
Hello @Abd_karim and welcome to the ST community,
That's an international community so the language to be used is English.
Translation:
"Hello everyone, I've been developing an API for the secure at88sc12816c memory from Atmel for a week now, but unfortunately I can't establish communication between my master board, which is an STM32F412ZGT6, and the EEPROM memory.
For my part, I understand how the memory works, except that the addresses in the latter are different. I explained, for example, that to write in a UserZone, it's B0 and this byte ends with 0, which is correctly understood by the HAL for writing in i2c.
But in the case of a read, for example, the address still ends with 0, whereas in a standard i2c protocol, to read, the last bit of the address byte must be 1 and I think this is exactly what the HAL doesn't understand at its level. I really need help moving forward."
2025-08-19 1:26 AM
D’accord, dois-je traduire le texte maintenant ou est-il déjà bon tel qu’il est ?
2025-08-19 1:28 AM
@Abd_karim wrote:
D’accord, dois-je traduire le texte maintenant ou est-il déjà bon tel qu’il est ?
It was done in my previous comment. But from now on please write in English.
2025-08-19 2:01 AM
Vous avez une idée ?
2025-08-19 2:47 AM
Hello @Abd_karim
When using the STM32 HAL library for I2C communication, the read/write (R/W) bit in the address byte sent from the master to the slave is automatically managed by the HAL functions.
For example, in the function HAL_I2C_Master_Receive(), the address read is handled internally by the HAL. Specifically, the function calls I2C_MasterRequestRead(hi2c, DevAddress, Timeout, tickstart), which in turn uses the macro I2C_7BIT_ADD_READ() to set the R/W bit appropriately for a read operation.
The macro below sets the least significant bit (LSB) of the address to 1, indicating a read operation according to the I2C protocol.
#define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0))
2025-08-19 3:03 AM
Hello,
Yes, I understand that correctly and I saw the macro in question in the code on STM32CubeIDE.
Except that in my case, the slave address for reading doesn't end with a 1 but rather a 0. How do I adapt the macro so that when I send a command, for example (1101 0010) with a 0 at the end, it knows that I want to read? Thanks for your feedback.
2025-08-19 3:15 AM
Hello @Abd_karim
You need to shift left the slave adresse by 1. And then call the HAL I2C API with the shifted address.
2025-08-19 4:04 AM
We agree that to do a reading, I must first do a HAL_i2c_master_transmit then HAL_i2c_master_receive. So the offset address must be used in both functions
2025-08-19 4:12 AM
and in addition when I shift the address to the left by 1, it goes to 12 bits. Is this configuration acceptable