- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SensorWrite (
uint8_t slaveAddr,
uint8_t highAddr,
uint8_t lowAddr,
uint8_t count,
uint8_t *buf)
{
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
CyU3PI2cPreamble_t preamble; /* Validate the I2C slave address. */
if ((slaveAddr != SENSOR_ADDR_WR) && (slaveAddr != I2C_MEMORY_ADDR_WR))
{
CyU3PDebugPrint (4, "I2C Slave address is not valid!\n");
return 1;
} if (count > 64)
{
CyU3PDebugPrint (4, "ERROR: SensorWrite count > 64\n");
return 1;
} /* Set up the I2C control parameters and invoke the write API. */
preamble.buffer[0] = slaveAddr;
preamble.buffer[1] = highAddr;
//preamble.buffer[2] = lowAddr;
preamble.length = 2;
preamble.ctrlMask = 0x0000; apiRetStatus = CyU3PI2cTransmitBytes (&preamble, buf, count, 0);
SensorI2CAccessDelay (apiRetStatus); return apiRetStatus;
}
SensorRead (
uint8_t slaveAddr,
uint8_t highAddr,
uint8_t lowAddr,
uint8_t count,
uint8_t *buf)
{
CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
CyU3PI2cPreamble_t preamble; /* Validate the parameters. */
if ((slaveAddr != SENSOR_ADDR_RD) && (slaveAddr != I2C_MEMORY_ADDR_RD))
{
CyU3PDebugPrint (4, "I2C Slave address is not valid!\n");
return 1;
}
if ( count > 64 )
{
CyU3PDebugPrint (4, "ERROR: SensorWrite count > 64\n");
return 1;
} preamble.buffer[0] = slaveAddr & I2C_SLAVEADDR_MASK; /* Mask out the transfer type bit. */
preamble.buffer[1] = highAddr;
//preamble.buffer[2] = lowAddr;
preamble.buffer[2] = slaveAddr;
preamble.length = 3;
preamble.ctrlMask = 0x0002; /* Send start bit after third byte of preamble. */ apiRetStatus = CyU3PI2cReceiveBytes (&preamble, buf, count, 0);
SensorI2CAccessDelay (apiRetStatus); return apiRetStatus;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
In each of the functions above, based on slave address you can use CyU3PI2cTransmitBytes/ CyU3PI2cReceiveBytes separately.
i.e, for ex: SensorWrite() can be as follows
CyU3PReturnStatus_t
SensorWrite (
uint8_t slaveAddr,
uint8_t highAddr,
uint8_t lowAddr,
uint8_t count,
uint8_t *buf)
{
...
...
if(slaveAddr == SENSOR_ADDR_WR)
{
..
}
else if(slaveAddr == I2C_MEMORY_ADDR_WR)
{
..
}
...
...
}
Regards,
Hemanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
In each of the functions above, based on slave address you can use CyU3PI2cTransmitBytes/ CyU3PI2cReceiveBytes separately.
i.e, for ex: SensorWrite() can be as follows
CyU3PReturnStatus_t
SensorWrite (
uint8_t slaveAddr,
uint8_t highAddr,
uint8_t lowAddr,
uint8_t count,
uint8_t *buf)
{
...
...
if(slaveAddr == SENSOR_ADDR_WR)
{
..
}
else if(slaveAddr == I2C_MEMORY_ADDR_WR)
{
..
}
...
...
}
Regards,
Hemanth