Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f_bool i2c_send_data(t_i2c_bus bus_addr,
- f_uint8 addr, f_uint16 offset, f_uint8 *data, f_uint16 len)
- {
- volatile t_i2c *bus = (volatile t_i2c *)bus_addr;
- int i = 0;
- i2c_start(bus_addr);
- /* send address byte, write mode */
- bus->ibdr = ((addr << 1) | I2C_WRITE);
- if (!i2c_wait_eot_ack(bus_addr)) {
- i2c_stop(bus_addr);
- return I2C_SEND_ERROR;
- }
- /* offset field */
- if (offset > 0xff) {
- /* it is a 16 bit address, first H then L */
- bus->ibdr = (offset >> 8);
- if (!i2c_wait_eot_ack(bus_addr)) {
- i2c_stop(bus_addr);
- return I2C_SEND_ERROR;
- }
- }
- bus->ibdr = (offset & 0xff);
- if (!i2c_wait_eot_ack(bus_addr)) {
- i2c_stop(bus_addr);
- return I2C_SEND_ERROR;
- }
- /* single address byte sent ? */
- if (!len || !data) {
- i2c_stop(bus_addr);
- return I2C_SEND_SUCCESS;
- }
- /* send data block, if any */
- while (len--) {
- bus->ibdr = 0x44; //data[i++];
- if (!i2c_wait_eot_ack(bus_addr)) {
- i2c_stop(bus_addr);
- return I2C_SEND_ERROR;
- }
- }
- i2c_stop(bus_addr);
- /* wait twr now */
- msleep(10);
- return I2C_SEND_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement