I have been trying to write a byte to the EEPROM 23LC32A through I2C protocol. I am using uvision 5 Keil to code my program.
When I run my code in the Termite.exe terminal window, the output seems to indicate that read function is executing. It returns 255, which is the default value of a cleared EEPROM. So the thing is that the writing of the data is not taking place.
I have configured and coded the control registers correctly as per the datasheet. What could have possibly gone wrong? And also please do help with me page writing of EEPROM too. Here is my code below:
void write8eeprom(uint8_t addr, uint8_t reghigh, uint8_t reglow, uint8_t value)
{
uint8_t bytes [3];
bytes[0] = reghigh;
bytes[1] = reglow;
bytes[2] = value;
bool success = twi_master_transfer(addr, (uint8_t*) &bytes, sizeof(bytes), TWI_ISSUE_STOP);
}
uint8_t read8(uint8_t addr, uint8_t reg)
{
uint8_t value;
uint8_t bytes [1];
bytes[0] = reg;
uint8_t regValue[1] ;
twi_master_transfer(addr, (uint8_t*) &bytes, sizeof(bytes), TWI_DONT_ISSUE_STOP);
twi_master_transfer(addr|TWI_READ_BIT, (uint8_t*) ®Value, sizeof(regValue), TWI_ISSUE_STOP);
value = regValue[0] ;
return value;
}
void eeprom_write()
{
uint8_t value;
value = 1;
write8eeprom(160, 0x1000, 0x0001, value);
printf("Data %d is written\n", value);
}
void eeprom_read()
{
uint8_t value;
value = read8(160, 0x00000001);
printf("The data %d is read\n", value);
}
int main(void)
{
nrf_drv_clock_lfclk_request();
timers_init();
application_timers_start();
nrf_delay_ms(2000);
uart_config();
gpio_config();
bool tt= twi_master_init ( ) ;
nrf_delay_ms(2000);
printf("\n\r I2C \n\r");
eeprom_write();
nrf_delay_ms(1000);
eeprom_read();
for(;;)
{
__WFE();
}
}