Hi
I am interfacing a sensor using I2C protocol using TI- RTOS driver libraries,
I want to define a I2C read and write function in the prescribed format-
i2c_read(unsigned char slave_addr, unsigned char reg_addr, unsigned char length, unsigned char *data) i2c_write(unsigned char slave_addr, unsigned char reg_addr, unsigned char length, unsigned char const *data)
but the TI RTOS I2C libraries use
I2C_Transaction i2cTransaction; UChar writeBuffer[3]; UChar readBuffer[2]; Bool transferOK; i2cTransaction.slaveAddress = 0x50; /* 7-bit peripheral slave address */ i2cTransaction.writeBuf = writeBuffer; /* Buffer to be written */ i2cTransaction.writeCount = 3; /* Number of bytes to be written */ i2cTransaction.readBuf = NULL; /* Buffer to be read */ i2cTransaction.readCount = 0; /* Number of bytes to be read */ transferOK = I2C_transfer(i2c, &i2cTransaction); /* Perform I2C transfer */ if (!transferOK) { /* I2C bus fault */ }
and for write operation
I2C_Transaction i2cTransaction;
UChar writeBuffer[3];
UChar readBuffer[2];
Bool transferOK;
i2cTransaction.slaveAddress = 0x50; /* 7-bit peripheral slave address */
i2cTransaction.writeBuf = NULL; /* Buffer to be written */
i2cTransaction.writeCount = 0; /* Number of bytes to be written */
i2cTransaction.readBuf = readBuffer; /* Buffer to be read */
i2cTransaction.readCount = 2; /* Number of bytes to be read */
transferOK = I2C_transfer(i2c, &i2cTransaction); /* Perform I2C transfer */
if (!transferOK) {
/* I2C bus fault */
}
As you can see that in the expected function there are 4 parameters,
1. slave address (no problem with TI driver)
2. reg_addr (? in TI drivers )
3. length (is it i2cTransaction.writeCount?)
4. *data (is it read/write buffer)
As the API is a structure and the requirement is in function, as it is suggested that I must use TI-RTOS drivers for implementing I2C protocol.
I am using a cc2650.
Thanks