/* Includes ------------------------------------------------------------------*/ /* * libc */ #include /* * LIBOPENCM3 */ #include #include #include #include #include #include #include #include int ad7414Config(uint32_t i2cChannel, u8 address) { int iRtn; u8 buff[2]; // write config register continuous reading buff[0] = 0x01; //config register buff[1] = 0x60; //continuous reading no alert iRtn = I2C_Write(i2cChannel, I2C_MASTER, buff, 2, address); //printf("DEBUG> [ad7414Config] i2c(%s) @(0x%02x) iRtn(%d) error(%d)\n", // I2C_ToString(i2cChannel), address, iRtn, I2C_GetError(i2cChannel)); return iRtn; } int ad7414Read(uint32_t i2cChannel, u8 address, u8 dataChannel) { int iRtn; u8 buff[2]; int val = 0; buff[0] = 0; // read temperature register buff[1] = 0; iRtn = I2C_Write(i2cChannel, I2C_MASTER, buff, 1, address); //printf("DEBUG> [ad7414Read] i2c(%s) @(0x%02x) -write- iRtn(%d) error(%d)\n", // I2C_ToString(i2cChannel), address, iRtn, I2C_GetError(i2cChannel)); if (iRtn == -1) return (-1); iRtn = I2C_Read(i2cChannel, I2C_MASTER, buff, 2, address); //printf("DEBUG> [ad7414Read] i2c(%s) @(0x%02x) -read- iRtn(%d) error(%d)\n", // I2C_ToString(i2cChannel), address, iRtn, I2C_GetError(i2cChannel)); if (iRtn == -1) return (-1); iRtn = I2C_Read(i2cChannel, I2C_MASTER, buff, 2, address); //printf("DEBUG> [ad7414Read] i2c(%s) @(0x%02x) -read- iRtn(%d) error(%d)\n", // I2C_ToString(i2cChannel), address, iRtn, I2C_GetError(i2cChannel)); if (iRtn == -1) return (-1); val = buff[0]; val = ((val << 2) + (buff[1] >> 6)); return (val); }