// Write a 24-bit code to the LTC2992. int8_t LTC2992_write_24_bits(uint8_t i2c_address, uint8_t adc_command, uint32_t code) // The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge. { int8_t ack; LT_union_int32_4bytes data; data.LT_int32 = code; ack = i2c_write_block_data(i2c_address, adc_command, (uint8_t) 3, data.LT_byte); return(ack); }
int ami304_i2c_write(u8 RegAddr, u8 *RegValue, u8 len) { int Ret; struct i2c_client *client = g_ami304_data->client; if (client == NULL) { printk("%s - no client initialized\n", __FUNCTION__); return -1; } Ret = i2c_write_block_data(client, DEVICE_I2C_ADDRESS_SIZE_1BYTE, len, RegAddr, RegValue); if (Ret < 0) { printk("%s - failed \n", __FUNCTION__); return -1; } return 0; }
void tb(int pi) { int h, e, b, len; char *exp; char buf[128]; printf("SMBus / I2C tests."); /* this test requires an ADXL345 on I2C bus 1 addr 0x53 */ h = i2c_open(pi, 1, 0x53, 0); CHECK(11, 1, h, 0, 0, "i2c open"); e = i2c_write_device(pi, h, "\x00", 1); /* move to known register */ CHECK(11, 2, e, 0, 0, "i2c write device"); b = i2c_read_device(pi, h, buf, 1); CHECK(11, 3, b, 1, 0, "i2c read device"); CHECK(11, 4, buf[0], 0xE5, 0, "i2c read device"); b = i2c_read_byte(pi, h); CHECK(11, 5, b, 0xE5, 0, "i2c read byte"); b = i2c_read_byte_data(pi, h, 0); CHECK(11, 6, b, 0xE5, 0, "i2c read byte data"); b = i2c_read_byte_data(pi, h, 48); CHECK(11, 7, b, 2, 0, "i2c read byte data"); exp = "\x1D[aBcDeFgHjKM]"; len = strlen(exp); e = i2c_write_device(pi, h, exp, len); CHECK(11, 8, e, 0, 0, "i2c write device"); e = i2c_write_device(pi, h, "\x1D", 1); b = i2c_read_device(pi, h, buf, len-1); CHECK(11, 9, b, len-1, 0, "i2c read device"); CHECK(11, 10, strncmp(buf, exp+1, len-1), 0, 0, "i2c read device"); if (strncmp(buf, exp+1, len-1)) printf("got [%.*s] expected [%.*s]\n", len-1, buf, len-1, exp+1); e = i2c_write_byte_data(pi, h, 0x1d, 0xAA); CHECK(11, 11, e, 0, 0, "i2c write byte data"); b = i2c_read_byte_data(pi, h, 0x1d); CHECK(11, 12, b, 0xAA, 0, "i2c read byte data"); e = i2c_write_byte_data(pi, h, 0x1d, 0x55); CHECK(11, 13, e, 0, 0, "i2c write byte data"); b = i2c_read_byte_data(pi, h, 0x1d); CHECK(11, 14, b, 0x55, 0, "i2c read byte data"); exp = "[1234567890#]"; len = strlen(exp); e = i2c_write_block_data(pi, h, 0x1C, exp, len); CHECK(11, 15, e, 0, 0, "i2c write block data"); e = i2c_write_device(pi, h, "\x1D", 1); b = i2c_read_device(pi, h, buf, len); CHECK(11, 16, b, len, 0, "i2c read device"); CHECK(11, 17, strncmp(buf, exp, len), 0, 0, "i2c read device"); if (strncmp(buf, exp, len)) printf("got [%.*s] expected [%.*s]\n", len, buf, len, exp); b = i2c_read_i2c_block_data(pi, h, 0x1D, buf, len); CHECK(11, 18, b, len, 0, "i2c read i2c block data"); CHECK(11, 19, strncmp(buf, exp, len), 0, 0, "i2c read i2c block data"); if (strncmp(buf, exp, len)) printf("got [%.*s] expected [%.*s]\n", len, buf, len, exp); exp = "(-+=;:,<>!%)"; len = strlen(exp); e = i2c_write_i2c_block_data(pi, h, 0x1D, exp, len); CHECK(11, 20, e, 0, 0, "i2c write i2c block data"); b = i2c_read_i2c_block_data(pi, h, 0x1D, buf, len); CHECK(11, 21, b, len, 0, "i2c read i2c block data"); CHECK(11, 22, strncmp(buf, exp, len), 0, 0, "i2c read i2c block data"); if (strncmp(buf, exp, len)) printf("got [%.*s] expected [%.*s]\n", len, buf, len, exp); e = i2c_close(pi, h); CHECK(11, 23, e, 0, 0, "i2c close"); }