コード例 #1
0
// Write an 8-bit code to the LTC2943.
int8_t LTC2943_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
  int32_t ack;

  ack = i2c_write_byte_data(i2c_address, adc_command, code);
  return(ack);
}
コード例 #2
0
ファイル: Gsensor_DA380.c プロジェクト: magic-gjh/NT96650_K12
int mir3da_register_write( unsigned char addr, unsigned char data) {
    int     res = 0;

    res = i2c_write_byte_data(addr, data);
    if(res != 0) {
        return res;
    }

    return res;
}
コード例 #3
0
ファイル: ecmd.c プロジェクト: Wiiilmaa/ethersex
int16_t parse_cmd_i2c_write_byte_data(char *cmd, char *output, uint16_t len)
{
	uint8_t cadr;
	uint8_t dadr;
	uint8_t data;
	sscanf_P(cmd, PSTR("%u %u %x"), &cadr, &dadr, &data);
	if (cadr < 7 || cadr > 127)
		return ECMD_ERR_PARSE_ERROR;
	uint16_t ret = i2c_write_byte_data(cadr, dadr, data);
#ifdef ECMD_MIRROR_REQUEST
	return ECMD_FINAL(snprintf_P(output, len, PSTR("i2c wbd %d %d 0x%02X"), cadr, dadr, ret));
#else
	return ECMD_FINAL(snprintf_P(output, len, PSTR("0x%02X"), ret));
#endif
}
コード例 #4
0
ファイル: LTC4245.cpp プロジェクト: mthoren-adi/Linduino
// Write an 8-bit code to the LTC4245
int8_t LTC4245_write(uint8_t i2c_address, uint8_t command, uint8_t code)
{
  int8_t ack;
  ack = i2c_write_byte_data(i2c_address,command,code);
  return ack;
}
コード例 #5
0
ファイル: x_pigpiod_if2.c プロジェクト: SlySven/pigpio
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");
}