Skip to main content
Explorer
August 19, 2025
Question

Communication between stm32f412zgt6 and a secure memory ATMEL AT88SC1216C over I2C

  • August 19, 2025
  • 9 replies
  • 730 views

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

Abd_karim_0-1755591014953.pngAbd_karim_1-1755591044404.png

 

    This topic has been closed for replies.

    9 replies

    Technical Moderator
    August 19, 2025

    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."

    Abd_karimAuthor
    Explorer
    August 19, 2025
     

     D’accord, dois-je traduire le texte maintenant ou est-il déjà bon tel qu’il est ?

    Technical Moderator
    August 19, 2025

    @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.

    Abd_karimAuthor
    Explorer
    August 19, 2025

    Vous avez une idée ?

    Technical Moderator
    August 19, 2025

    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))

     

    Abd_karimAuthor
    Explorer
    August 19, 2025
    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.
    Technical Moderator
    August 19, 2025

    Hello @Abd_karim 

    You need to shift left the slave adresse by 1. And then call the HAL I2C API with the shifted address. 

     

    Abd_karimAuthor
    Explorer
    August 19, 2025
    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
    Technical Moderator
    August 19, 2025

    Hello @Abd_karim 

    Since there is no stop or restart condition between sending the command and reading the data, so you may use the sequential HAL I2C API

    HAL_I2C_Master_Seq_Transmit_IT(&hi2c1, DEVICE_ADDR << 1, cmd, 4, I2C_FIRST_FRAME);
    
    // Wait for transmit complete (implement callback or polling as needed)
    
    // Start receive (with stop)
    HAL_I2C_Master_Seq_Receive_IT(&hi2c1, DEVICE_ADDR << 1, data, 16, I2C_LAST_FRAME);

     

    Abd_karimAuthor
    Explorer
    August 19, 2025

    and in addition when I shift the address to the left by 1, it goes to 12 bits. Is this configuration acceptable

    Abd_karimAuthor
    Explorer
    August 19, 2025
    Do you think I can modify the HAL_I2C_Master_Transmit function so that it does a transmit_receive, if so how?
    Abd_karimAuthor
    Explorer
    August 26, 2025

    I am working on a stm32f412zgt6, when I use the HAL_I2C_Master_Transmit function I have a HAL_BUSY type error due to the following function, do you have any idea why?

    Abd_karim_0-1756191090964.png