Hello Dialog Team,
I'm developing a solution using DA14580 sps bluetooth and it works fine without problems! Good job Dialog Team!
Now I need to add a 24AA02E48 i2c memory in my design to get a unique MAC ADDRESS.
Some weeks ago I had design a ethernet solution using another arm microcontroller and theses i2c memory without problems. I used this code to do that:
for(i=0xFA; i<=0xFF; i++)
{
i2c_write_eeprom_polled (i2c1, 0xA0, (unsigned char *)i, 1);
i2c_read_eeprom_polled (i2c1, i, buffer, 1);
mac[i-0xFA] = buffer[0];
if(i==0xFF)
{
sprintf(buffer, "\n\rMAC_ADDRESS:%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
Now I tried to do it using DA14580 and something is wrong. I'm using "i2c_eeprom_write_byte(uint32_t address, uint8_t byte)" and "i2c_eeprom_read_byte(uint32_t address, uint8_t *byte)".
void read_i2c_mac(void)
{
uint32_t i, j;
uint8_t buffer;
i2c_eeprom_init(I2C_SLAVE_ADDRESS, I2C_SPEED_MODE, I2C_ADDRESS_MODE, I2C_ADDRESS_SIZE);
for(i=0xFA; i<=0xFF; i++)
{
i2c_eeprom_write_byte( 0xA0, i);
i2c_eeprom_read_byte(i, &buffer);
mac[i-0xFA] = buffer;
if(i==0xFF)
{
sprintf(&buffer, "\n\rMAC_ADDRESS:%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
i2c_eeprom_release();
}
}
Do you have any ideia to solve my problem?
I'm using 4k7 pull up, I2C_SCL_PIN= GPIO_PIN_2, I2C_SDA_PIN = GPIO_PIN_3, I2C_SLAVE_ADDRESS 0x50.
Best regards.
Bruno
Hi bruno ferrarezi,
I am not sure what exactly you are trying to do, as far as i can tell, you release the i2c after one byte i2c read and write interaction, after the first loop of the for loop the i2c will be disabled due to the i2c_eeprom_release.
Thanks MT_dialog
Thanks for you repply.
I want to send 0xFB, 0XFC bytes to 0x0A address. After that, I need to read 0x0A address. I expect read 0x04 and 0xA3 but it did not happen.
Note: 0x04 and 0x03 mean the beginning of the mac address number (built-in this memory).
Best regards.
Bruno.
Hi bruno_ferrarezi,
As mentioned above, the code that you have will implemented will fail since you are releasing the I2C before you actually stop the SPI interaction.
Since you would like to do the above, place the i2c_eeprom_release() outside of the loop in order to release the I2C after your transaction is over, also i dont get the scenario you mention that you would like to write two different values in the same memory location and then read back the same memory location and read a 0x03 or a 0x04, if you would like to write the memory starting from 0x0A you can use the i2c_eeprom_write_data(). Anyway in order to do what you mention above one test you could try is the below:
i2c_eeprom_init(I2C_SLAVE_ADDRESS, I2C_SPEED_MODE, I2C_ADDRESS_MODE, I2C_ADDRESS_SIZE); //initialize the I2C interface
i2c_eeprom_write_byte(0x0A, 0xFB); // write one byte 0xFB to address 0x0A
i2c_eeprom_write_byte(0x0A, 0xFC); // write one byte 0xFC to address 0x0A
i2c_eeprom_read_byte(0x0A, buffer); // read back the value of 0x0A
i2c_eeprom_release(); // after the I2C transaction is over release the I2C peripheral
Please also check the i2c_eeprom example in the peripheral_examples folder in the SDK in order to check how the driver is used.
Thanks MT_dialog
Hi.
I solve the problem using:
for(i = 0xFA; i <= 0xFF; i++)
{
i2c_eeprom_read_byte(i,&buffer);
}
Thanks!