Hello Dialog,
I am working on I2C interface of the sensor with DA14585. As there is no generic i2c example I am referring to the i2c_eeprom example. Actually, from my sensor, I want to read one byte of data from its output register. For that, I have defined #define I2C_ADDRESS_SIZE I2C_1BYTE_ADDR in i2c_eeprom.h file. But there is no description of this command in i2c_eeprom.c.
But in i2c_eeprom example, as it is using 2BYTES-ADDR for that the description is defined in i2c_eeprom.c used switch case as
static void i2c_send_address(uint32_t address)
{
switch(mem_address_size)
{
case I2C_2BYTES_ADDR:
SetWord16(I2C_ENABLE_REG, 0x0);
//SetWord16(I2C_TAR_REG, i2c_dev_address | ((address & 0x10000) >> 16)); // Set Slave device address
SetWord16(I2C_TAR_REG, i2c_dev_address); // Set Slave device address
SetWord16(I2C_ENABLE_REG, 0x1);
WAIT_UNTIL_NO_MASTER_ACTIVITY(); // Wait until no master activity
SEND_I2C_COMMAND(地址> >8) & 0xFF); // Set address MSB, write access
break;
case I2C_3BYTES_ADDR:
SEND_I2C_COMMAND(地址> >16) & 0xFF); // Set address MSB, write access
SEND_I2C_COMMAND(地址> >8) & 0xFF); // Set address MSB, write access
break;
}
SEND_I2C_COMMAND(address & 0xFF); // Set address LSB, write access
}
If I use 1BYTE_ADDR in my case controller takes as default or should we need to change the code in i2c_eeprom.c.
Thank you
D.vishnu
Hi vishnuatdialog,
The I2C_1BYTE_ADDR isn't a command, its just a #define that will instruct the amount bytes send when you send the address over the bus, if your sensor require 1 byte address then it should be set to I2C_1BYTE_ADDR. The switch case in the i2c_send_address() function goes to the proper case depending on the mem_address_size variable. This variable is set in the i2c_eeprom_init() function and obtaines the value from the I2C_ADDRESS_SIZE definition which is defined in the user_periph_setup.h file. So in order to change that you will have to define the I2C_ADDRESS_SIZE as I2C_1BYTE_ADDR and not as I2C_2BYTES_ADDR which is the default value of the example.
Thanks MT_dialog