0

I' m working in team on a project using stm32 f100 series board. I should use an external I2C eeprom to storage some data, the eeprom is the following: CAT24C512WI-GT3 and I also have the init code for this I2C eeprom:

void io_ee_scl(char s)
{
    if(s)
        GPIOB->BSRR=GPIO_PIN_6;
    else
        GPIOB->BRR=GPIO_PIN_6;
}

void io_ee_sda(char s)
{
    if(s)
        GPIOB->BSRR=GPIO_PIN_7;
    else
        GPIOB->BRR=GPIO_PIN_7;

}

void io_ee_wp(char s)
{
    if(s)
        GPIOB->BSRR=GPIO_PIN_5;
    else
        GPIOB->BRR=GPIO_PIN_5;
}
char read_eeprom()  //read eeprom function
{
    return ( (GPIOB->IDR&GPIO_PIN_7) ? 1 : 0 );
}

On internet the most guide talk about HAL library but as you can see my colleague doesn't use the HAL library and considering I am new in stm32 I don't know how to read and write data on the eeprom. Some suggestions?

1 Answers1

2

This is no init code, but a part of the system-specific code for a software-only (a.k.a. bit-banging) I2C driver.

in addition to this, you have to

  • enable the GPIOB peripheral clock in RCC->APB2ENR
  • put both pins in open-drain, general purpose output mode in GPIOB->CRL
  • have a delay function for 1/2 of the I2C clock cycle time, i.e. if it should be running at 100 kHz, a single cycle takes 10 μs, you'd need a delay of 5 μs.

Then it's possible to use general I2C code to communicate with the EEPROM. The communication protocol is described in detail in the EEPROM datasheet.

It is also possible to use the built in I2C peripheral of the STM32F1, but it'd be quite challenging as the first task on this platform for a beginner. Nevertheless, if you'd like to do it, you can study the relevant HAL source code to see how it is done there.