- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I am interfacing the IIS2DH sensor, and I can configure its registers and can read most of them. I have a pair of registers where I should read 2 registers one after another. For that I have to alter the lower register's address to put the IC into the auto address incrementing mode. I configured the IC and the registers based on the datasheet based on the conversation with the manufacturer I did it in a proper way. The IC's datasheet mention the proper I2C communication for the case of multiple byte read (attached that part):
I am using the FX3 based I2C communication functions:
CyU3PReturnStatus_t acc_i2c_readInc(uint8_t slave_addr, uint8_t reg_addr, uint8_t *buff)
{
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
CyU3PI2cPreamble_t preamble;
if ((slave_addr != ACCEL_ADDR_RD) && (slave_addr != I2C_MEMORY_ADDR_RD))
{
CyU3PDebugPrint (4, "I2C Slave address is not valid!\n");
return 1;
}
preamble.length = 3;
preamble.buffer[0] = slave_addr & I2C_SLAVEADDR_MASK; /* Mask out the transfer type bit. */
preamble.buffer[1] = reg_addr;
preamble.buffer[2] = slave_addr ;
preamble.ctrlMask = 1<<1; /* Send start bit after second byte of preamble. */
CyU3PDebugPrint (4, "Reg address%d\n",reg_addr);
apiRetStatus = CyU3PI2cReceiveBytes (&preamble, buff, 2, 0);
SensorI2CAccessDelay (apiRetStatus);
return apiRetStatus;
}
I modified the CyU3PI2cReceiveBytes function byteCount variable 1 to 2. Is this implementation is capable to read 2 bytes in an address auto incrementing situation? The buff pointer points to an array, so if I receive 2 bytes I can store it.
Best regards,
Bence
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bence,
I believe the I2C_SLAVEADDR_MASK value is 0xFE. Also, the slave_addr byte will have bit0 filled with the Read operation(b'1). If not please set these values.
Also, As per the IIS2DH datasheet, reg_addr bit 7 should be 1. Please set it appropriately.
As per your implementation, if all the above-said values are set appropriately, your code will read only 2 bytes from the IIS2DH sensor. Also, if you have a for loop and call this function, reg_addr will be sent every time you call this function. If you want to read more than two bytes, allocate enough memory for the buff and give the transfer byte appropriately.
Thanks,
Ajeeth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bence,
I believe the I2C_SLAVEADDR_MASK value is 0xFE. Also, the slave_addr byte will have bit0 filled with the Read operation(b'1). If not please set these values.
Also, As per the IIS2DH datasheet, reg_addr bit 7 should be 1. Please set it appropriately.
As per your implementation, if all the above-said values are set appropriately, your code will read only 2 bytes from the IIS2DH sensor. Also, if you have a for loop and call this function, reg_addr will be sent every time you call this function. If you want to read more than two bytes, allocate enough memory for the buff and give the transfer byte appropriately.
Thanks,
Ajeeth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ajeeth,
Thank you for your response. I set the Msb bit of the register address to 1 as the datasheet asked, and checked it by reading back. So you think this i2c implementation should work, and I have to search the solution somewhere else? I thought a there could be a problem with the MAK(Master acknowledge ) signals. Because the IIS2Dh datasheet mention that in the case of multiple byte read a MAK signal needed after every byte, and I was not sure the default CyU3PI2cReceiveBytes and control mask handle this.
Thanks,
Bence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry I rechecked the implementation and works fine. I made a mistake when initialized the sensor.
Thank you for your help.