Hi,
I want to ask how to configure the particular register for any sensor using I2c api. I am working on a sensor where I need to configure the register first, and then perform read operation. So I need to send slave address, reg location, tx buf , tx bytes which is not possible by using following api(there is no parameter for reg location).
i2cMasterTransmitTimeout(I2CDriver *i2cp,
i2caddr_t addr,
const uint8_t *txbuf,
size_t txbytes,
uint8_t *rxbuf,
size_t rxbytes,
sysinterval_t timeout)
And should I send the Slave address directly as given in datasheet or add 1 or 0 for read and write operation respectively.
Thanks
Kalpesh
I2c Communication in chibios
- Giovanni
- Site Admin
- Posts: 14455
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: I2c Communication in chibios
Hi,
Under /os/ex there are a lot of drivers that use I2C to access registers in peripherals, you can use those as example, "reg location" is part of the TX data probably, I2C knows nothing about registers and the API is very generic.
Giovanni
Under /os/ex there are a lot of drivers that use I2C to access registers in peripherals, you can use those as example, "reg location" is part of the TX data probably, I2C knows nothing about registers and the API is very generic.
Giovanni
Re: I2c Communication in chibios
Giovanni wrote:Hi,
Under /os/ex there are a lot of drivers that use I2C to access registers in peripherals, you can use those as example, "reg location" is part of the TX data probably, I2C knows nothing about registers and the API is very generic.
Giovanni
is there any API in this format
int8_t I2C_write(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout)
where, I can mention reg address.
Thanks
- wurstnase
- Posts: 121
- Joined: Tue Oct 17, 2017 2:24 pm
- Has thanked: 43 times
- Been thanked: 30 times
- Contact:
Re: I2c Communication in chibios
There is no easy way to have a generic version for this.
Some slave needs an address with 8bit, some with 16bit. Some are MSB others LSB.
You could use a struct for your purpose.
In that case you can easy handle your address.
Keep in mind that chibios is using DMA, so sending data must be "together".
This code is untested and just written in the browser.
Some slave needs an address with 8bit, some with 16bit. Some are MSB others LSB.
You could use a struct for your purpose.
Code: Select all
struct my_data {
uint8_t address;
uint8_t data[SENDING_BUFFER_SIZE];
} __attribute__((packed));
void i2c_write(uint8_t addr, struct my_data *data) {
data->address = addr;
i2cMasterTransmit(&I2CD2, I2C_ADDR, (uint8_t*)data, sizeof(struct my_data), NULL, 0);
}
In that case you can easy handle your address.
Keep in mind that chibios is using DMA, so sending data must be "together".
This code is untested and just written in the browser.
\o/ Nico
Who is online
Users browsing this forum: No registered users and 21 guests