c_cpp I2C_pressure_sensor.c

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp I2C_pressure_sensor.c相关的知识,希望对你有一定的参考价值。

// I2C burst read (reads from 7 bit I2C device 'address' 'size' bytes starting with register 'reg' into data)
// i2c_read(uint8_t address, uint8_t reg, uint8_t *data, size_t size);
// I2C burst write (writes to 7 but I2C device 'address' 'size' bytes, starting with register 'reg')
// i2c_write(uint8_t address, uint8_t reg, uint8_t *data, size_t size);
// Write two interface functions that allow to (1) read temperature in degrees celsius (C) and (2) pressure in hecto-pascal (hPa) as a double.
// Ensure the BMP180 is actually available on the I2C bus.
// Read measured data as burst reads and convert to temperature and pressure.

int8_t i2c_read(uint8_t address, uint8_t reg, uint8_t *data, size_t size)
{
	int8_t ret = 0;
	uint8_t arr[8] = {0};    // length of i2c buffer
	uint8_t pos = 0;
	arr[0] = reg;

	for (pos = 0; pos < size; pos++) {
		*(data + pos) = arr[pos];
	}
	return ret;
}

int8_t i2c_write(uint8_t address, uint8_t reg, uint8_t *data, size_t size)
{
	int8_t ret = 0;
	uint8_t arr[8];    // length of i2c buffer
	uint8_t pos = 0;
	arr[0] = reg;
	for (pos = 0; pos < size; pos++) {
		arr[pos + C_BMP180_ONE_U8X] = *(data + pos);
	}
	return ret;
}

以上是关于c_cpp I2C_pressure_sensor.c的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 200.岛屿数量

c_cpp 127.单词阶梯

c_cpp MOFSET

c_cpp MOFSET

c_cpp 31.下一个排列

c_cpp string→char *