Hi All,
I am trying to read the value of the WHOAMI register of MPU 6050 using I2C interface. I was unable to find a function directly for register R/W. so, using the adapter, i have used this code.
eeprom_data_reader(EEPROM_24FC256, 0x75, page_buff);
Page_buff is empty and will receive the values after reading.
tatic uint16_t eeprom_data_reader(i2c_device dev, uint8_t pageAddr, uint8_t *buff)
{
uint8_t e_addr_buff[1];
/* Fill in the address bytes */
e_addr_buff[0] = pageAddr;
//e_addr_buff[1] = 0;
//e_addr_buff[1] = pageAddr >> 8;
/* Open the device */
ad_i2c_handle_t dev_hdr = ad_i2c_open((ad_i2c_controller_conf_t *)dev);
I2C_error_code = ad_i2c_write_read(dev_hdr, (const uint8_t *)e_addr_buff,
sizeof(e_addr_buff), buff, EEPROM_24LC256_PAGE_SIZE,
HW_I2C_F_ADD_STOP);
if (I2C_error_code == 0) {
/*
* When maximum data size has been reached, roll over to the starting
* address.
*/
printf("read successful\n");
// pageAddr = (pageAddr + EEPROM_24LC256_PAGE_SIZE) % EEPROM_TEST_DATA_SIZE;
} else {
printf("\n\rUnsuccessful I2C read operation with error code: %d\n\r",
I2C_error_code);
}
/* Close the device */
ad_i2c_close(dev_hdr, false);
/* Return the next EEPROM page */
return pageAddr;
}
I am not able to read the correct values from the sensor but it is consistently giving the value 0x72. If I disconnect the sensor, then the program is able to detect that.
I suspect the way the address is sent to the I2C bus. Am I missing out on something?
Thanks,
Sandeep.
Hi Sandeep,
Please can you also share the EEPROM_24FC256 instance initialization data. The EEPROM_24LC256_PAGE_SIZE, is this repurposed to your application or this is really a EEPROM page size. Can you please confirm.
And if you have another sensor in hand, can you check the 69x with a different I2C sensor or read this sensor with a different device.
Best regards,
LC_Dialog
/* EEPROM device-specific parameters */
#define EEPROM_TEST_DATA_SIZE (1)
#定义EEPROM_24LC256_PAGE_SIZE (1)
I have defined this to read 1 byte.
#define EEPROM_24FC256_I2C_ADDRESS ( 0x68 )
/**
* I2C 1 configuration
*/
#define EEPROM_24FC256_SCL_PORT ( HW_GPIO_PORT_0 )
#define EEPROM_24FC256_SCL_PIN ( HW_GPIO_PIN_30 )
#define EEPROM_24FC256_SDA_PORT ( HW_GPIO_PORT_0 )
#define EEPROM_24FC256_SDA_PIN ( HW_GPIO_PIN_31 )
The I2C address is the device address.
I am able to read this sensor values properly with Arduino.
Hi Sandeep,
Thanks for sharing the code above. However, I was asking for the structad_i2c_controller_conf_tinstance in your implementation. The device you are passing to theeeprom_data_reader()function is theEEPROM_24FC256which is an instrance for the structure that is defining all the adapter attributes. Looking at that can lead to some insight.
Also an observation in the reader function implementation, thesizeof(e_addr_buff)will give you 2 and that sould be a 1 instead, for your use case.
I am also trying to replicate the issue on my side to check for any inherent issue. Will let you know if I find something..
Best regards,
LC_Dialog