Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

USB superspeed peripherals Forum Discussions

LBence91
Level 4
Level 4
10 questions asked 50 sign-ins 25 replies posted

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):

LBence91_0-1669808678045.png

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

0 Likes
1 Solution
Ajeethkumar
Moderator
Moderator
Moderator
250 sign-ins 50 solutions authored 10 likes received

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

View solution in original post

0 Likes
3 Replies
Ajeethkumar
Moderator
Moderator
Moderator
250 sign-ins 50 solutions authored 10 likes received

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

0 Likes

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

0 Likes

Sorry I rechecked the implementation and works fine. I made a mistake when initialized the sensor.

Thank you for your help.

0 Likes