i2c_master_write.ino
Illustrates I2C bus management for non-volatile storage, useful for system configuration.
Enable an I2C master in Efinity. Connect a standard EEPROM (e.g., AT24C02). Control registers depend heavily on the specific IP used in your Efinity design. Test with an oscilloscope to validate timing.
i2c_master_write.ino
#include <stdint.h>
#define I2C_BASE 0x80003000
#define I2C_CTRL (*(volatile uint32_t *)(I2C_BASE + 0x00))
#define I2C_DATA (*(volatile uint32_t *)(I2C_BASE + 0x04))
#define I2C_STAT (*(volatile uint32_t *)(I2C_BASE + 0x08))
void i2c_start() { I2C_CTRL |= 0x01; while(!(I2C_STAT & 0x01)); }
void i2c_stop() { I2C_CTRL |= 0x02; while(!(I2C_STAT & 0x02)); }
void i2c_write(uint8_t data) { I2C_DATA = data; while(!(I2C_STAT & 0x04)); }
int main() {
uint8_t addr = 0x50 << 1; // Adresse EEPROM
uint8_t data = 0xAA;
while(1) {
i2c_start();
i2c_write(addr);
i2c_write(0x00); // Adresse mémoire
i2c_write(data);
i2c_stop();
// Délai avant réécriture
for(volatile int i=0; i<1000000; i++);
}
return 0;
}