本文整理汇总了C++中i2c_read_byte函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_read_byte函数的具体用法?C++ i2c_read_byte怎么用?C++ i2c_read_byte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_read_byte函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: i2c_read
int i2c_read (uint8_t chip_id, uint8_t reg_addr, uint8_t* buffer, uint16_t len)
{
int status = 0;
/* send chip internal register address (pointer register) */
if (status == 0) i2c_send_start ();
if (status == 0) status = i2c_write_byte (chip_id << 1 | I2C_WRITE_OPER);
if (status == 0) status = i2c_write_byte (reg_addr);
if (status == 0) i2c_send_repeated_start ();
/* send again chip id before to switch to read mode */
if (status == 0) status = i2c_write_byte ((chip_id << 1) | I2C_READ_OPER);
if (status == 0) i2c_switch_to_read_operation(len > 1);
/* read specified number of bytes */
if (status == 0) {
while (len > 1) {
*buffer++ = i2c_read_byte (--len > 1);
}
}
i2c_send_stop ();
if (status == 0) *buffer++ = i2c_read_byte (false);
return status;
}
开发者ID:Grelinfo,项目名称:RealTimeEmbeddedConsole,代码行数:25,代码来源:i2c.c
示例2: ds1721_read
float ds1721_read()
{
unsigned char hi, lo;
unsigned char i;
short tmp = 1;
float rev;
float frac[] = { 0.0625, 0.125, 0.25, 0.5 };
i2c_send_start();
i2c_send_byte(DS1721_ADDR | DS1721_WRITE);
i2c_send_byte(DS1721_CMD_READ);
i2c_send_start(); /* restart */
i2c_send_byte(DS1721_ADDR | DS1721_READ);
hi = i2c_read_byte(1);
lo = i2c_read_byte(1);
// _delay_us(70); /* WHAT ?! */
// i2c_send_stop();
// task_sm.piezo0_count = 5;
////////////////
////////////////
if (hi & 0x80)
{ /* negative */
tmp = (hi << 8) + lo;
tmp = ~tmp;
tmp++;
hi = tmp >> 8;
lo = tmp & 0x00ff;
tmp = -1;
}
开发者ID:chopin1998,项目名称:horse-drink,代码行数:34,代码来源:ds1721.c
示例3: ak8975a_read_raw_data
void ak8975a_read_raw_data(int16_t *val)
{
start:
// Launch the first acquisition
i2c_write_byte(AK8975A_ADDRESS, AK8975A_CNTL, 0x01);
//nrf_delay_ms(1);
// Wait for a data to become available
while ((i2c_read_byte(AK8975A_ADDRESS, AK8975A_ST1) & 0x01) == 0);
// If there is no overflow
if((i2c_read_byte(AK8975A_ADDRESS, AK8975A_ST2) & 0x0C)==0) {
int16_t v[3];
// Read the six raw data registers sequentially into data array
// WARNING : code valid for little endian only !
i2c_read_bytes(AK8975A_ADDRESS, AK8975A_XOUT_L, 6, (uint8_t *)v);
// WARNING, magnetometer axis are not the same as the accel / gyro ones
// Thus : x <--> y, and z <--> -z
val[0] = v[1];
val[1] = v[0];
val[2] = -v[2];
return;
}
goto start;
}
开发者ID:Books305,项目名称:twiz-fw,代码行数:27,代码来源:ak8975a.c
示例4: main
int main(void) {
uart_init();
debug_init();
lcd_init(LCD_DISP_ON);
lcd_clrscr();
DEBUG("init");
msg("begin loop");
while(1) {
msg("i2c_start");
i2c_start();
msg("i2c_read_byte(1)");
uint8_t temp = i2c_read_byte(1);
DEBUG("get_temp(0): %d", temp);
lcd_gotoxy(0, 0);
lcd_puts_P(PSTR("Temp: "));
lcd_puts(itoa(temp));
lcd_puts_P(PSTR(DEG"C"));
msg("i2c_read_byte(0)");
i2c_read_byte(0);
msg("i2c_stop");
i2c_stop();
msg("delay");
_delay_ms(1000);
}
}
开发者ID:yath,项目名称:avr-lm75test,代码行数:26,代码来源:main.c
示例5: hal_dev_mag3110_read_reg
uint8 hal_dev_mag3110_read_reg(uint8 addr)
{
uint8 result;
i2c_start(I2C_MAG);
i2c_write_byte(I2C_MAG, MAG3110_I2C_ADDRESS | I2C_WRITE);
i2c_wait(I2C_MAG);
i2c_get_ack(I2C_MAG);
i2c_write_byte(I2C_MAG, addr);
i2c_wait(I2C_MAG);
i2c_get_ack(I2C_MAG);
i2c_repeated_start(I2C_MAG);
i2c_write_byte(I2C_MAG, MAG3110_I2C_ADDRESS | I2C_READ);
i2c_wait(I2C_MAG);
i2c_get_ack(I2C_MAG);
i2c_set_rx_mode(I2C_MAG);
i2c_give_nack(I2C_MAG);
result = i2c_read_byte(I2C_MAG);
i2c_wait(I2C_MAG);
i2c_stop(I2C_MAG);
result = i2c_read_byte(I2C_MAG);
pause();
return result;
}
开发者ID:Lyanzh,项目名称:Learning_Material,代码行数:30,代码来源:hal_dev_mag3110.c
示例6: check_chipid
static int check_chipid(struct ftdi_context *ftdi)
{
int ret;
uint8_t ver = 0xff;
uint16_t id = 0xffff;
ret = i2c_read_byte(ftdi, 0x00, (uint8_t *)&id + 1);
if (ret < 0)
return ret;
ret = i2c_read_byte(ftdi, 0x01, (uint8_t *)&id);
if (ret < 0)
return ret;
ret = i2c_read_byte(ftdi, 0x02, &ver);
if (ret < 0)
return ret;
if ((id & 0xff00) != (CHIP_ID & 0xff00)) {
fprintf(stderr, "Invalid chip id: %04x\n", id);
return -EINVAL;
}
/* compute embedded flash size from CHIPVER field */
flash_size = (128 + (ver & 0xF0)) * 1024;
printf("CHIPID %04x, CHIPVER %02x, Flash size %d kB\n", id, ver,
flash_size / 1024);
return 0;
}
开发者ID:akappy7,项目名称:ChromeOS_EC_LED_Diagnostics,代码行数:27,代码来源:iteflash.c
示例7: imu_g_read_data_raw
void imu_g_read_data_raw(vector *v)
{
unsigned char xl,xh,yl,yh,zl,zh;
i2c_start();
i2c_write_byte(0xD0);
i2c_write_byte(0x1d);
i2c_start();
i2c_write_byte(0xD1);
xh = i2c_read_byte();
xl = i2c_read_byte();
yh = i2c_read_byte();
yl = i2c_read_byte();
zh = i2c_read_byte();
zl = i2c_read_last_byte();
i2c_stop();
v->x = xh << 8 | xl;
v->y = yh << 8 | yl;
v->z = zh << 8 | zl;
}
开发者ID:carp3,项目名称:RM-G146,代码行数:27,代码来源:imu_g.c
示例8: I2C_ReadOneByte
uint8_t I2C_ReadOneByte(uint8_t SlaveAddr, uint8_t RegAddr)
{
uint8_t result;
i2c_start(I2C0_B);
i2c_write_byte(I2C0_B, (SlaveAddr<<1) | I2C_WRITE);
i2c_wait(I2C0_B);
i2c_get_ack(I2C0_B);
i2c_write_byte(I2C0_B, RegAddr);
i2c_wait(I2C0_B);
i2c_get_ack(I2C0_B);
i2c_repeated_start(I2C0_B);
i2c_write_byte(I2C0_B, (SlaveAddr<<1) | I2C_READ);
i2c_wait(I2C0_B);
i2c_get_ack(I2C0_B);
i2c_set_rx_mode(I2C0_B);
i2c_give_nack(I2C0_B);
result = i2c_read_byte(I2C0_B);
i2c_wait(I2C0_B);
i2c_stop(I2C0_B);
result = i2c_read_byte(I2C0_B);
pause(40);
return result;
}
开发者ID:Wangwenxue,项目名称:KL26_SDCard,代码行数:30,代码来源:i2c.c
示例9: i2c_read_bytes
void i2c_read_bytes(i2c_connection conn, size_t n, uint8_t *buf,
enum i2c_ack_type last_ack_type) {
uint8_t *p = buf;
while (n > 1) {
*p++ = i2c_read_byte(conn, I2C_ACK);
n--;
}
if (n == 1) *p = i2c_read_byte(conn, last_ack_type);
}
开发者ID:2bright,项目名称:mongoose-iot,代码行数:9,代码来源:cc3200_i2c.c
示例10: sensor_read
uint16_t sensor_read (uint8_t HR, uint8_t LR)
{
uint8_t sh, sl;
uint16_t s;
sh = i2c_read_byte(HR);
sl = i2c_read_byte(LR);
s = ((uint16_t)sh<<8) + (uint16_t)sl;
return s;
}
开发者ID:JulioLP,项目名称:Stable_Walking_Detector,代码行数:11,代码来源:MPU_9050.cpp
示例11: read_xyz
void read_xyz(void)
{
// sign extend byte to 16 bits - need to cast to signed since function
// returns uint8_t which is unsigned
acc_X = (int8_t) i2c_read_byte(MMA_ADDR, REG_XHI);
DelayMS(100);
acc_Y = (int8_t) i2c_read_byte(MMA_ADDR, REG_YHI);
DelayMS(100);
acc_Z = (int8_t) i2c_read_byte(MMA_ADDR, REG_ZHI);
}
开发者ID:abhijithpecsol,项目名称:ncsu-ece561-EmbeddedSystemsDesign,代码行数:11,代码来源:mma8451.c
示例12: adxl346_read_z
int16_t adxl346_read_z(void) {
uint8_t acceleration[2];
int16_t z;
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAZ0_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[0]);
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAZ1_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[1]);
z = (acceleration[1] << 8) | acceleration[0];
return z;
}
开发者ID:Joan93,项目名称:MasterThesis,代码行数:13,代码来源:adxl346.c
示例13: adxl346_read_y
int16_t adxl346_read_y(void) {
uint8_t acceleration[2];
int16_t y;
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAY0_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[0]);
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAY1_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[1]);
y = (acceleration[1] << 8) | acceleration[0];
return y;
}
开发者ID:Joan93,项目名称:MasterThesis,代码行数:13,代码来源:adxl346.c
示例14: adxl346_read_x
int16_t adxl346_read_x(void) {
uint8_t acceleration[2];
int16_t x;
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAX0_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[0]);
i2c_write_byte(ADXL346_ADDRESS, ADXL346_DATAX1_ADDR);
i2c_read_byte(ADXL346_ADDRESS, &acceleration[1]);
x = (acceleration[1] << 8) | acceleration[0];
return x;
}
开发者ID:Joan93,项目名称:MasterThesis,代码行数:13,代码来源:adxl346.c
示例15: i2c_reg_read
uint16_t i2c_reg_read(uint8_t regAddr)
{
uint16_t dat;
i2c_start();
i2c_send_byte(I2C_INA_ADDR << 1 | I2C_WRITE_CMD);
i2c_send_byte(regAddr);
i2c_repeat_start();
i2c_send_byte(I2C_INA_ADDR << 1 | I2C_READ_CMD);
dat = i2c_read_byte(1) << 8;
dat |= i2c_read_byte(1);
i2c_stop();
return dat;
}
开发者ID:toolbitorg,项目名称:m-stack,代码行数:13,代码来源:luke_func.c
示例16: get_fet_str
int get_fet_str(int board_id , char * fet){
int err=0;
int rc=0;
int fetflag = 0;
int vpdrev ;
pthread_mutex_lock(&i2c_mutex);
err = setI2CSwitches(board_id);
if (err){
rc = FET_ERROR_BOARD_NA;
goto get_out;
}
vpdrev = (unsigned char)i2c_read_byte(MAIN_BOARD_I2C_EEPROM_DEV_ADDR, 0 , &err);
if (err){
rc = FET_ERROR_BOARD_NA;
goto get_out;
}
if (vpdrev == 0xFF) {
fprintf(stderr,"VPD not written at all\n");
rc = FET_ERROR_BLANK_VPD;
goto get_out;
}
else if (vpdrev < FET_SUPPORT_VPD_REV){
fprintf(stderr,"VPD from revision %d (need at least %d to include FET information)\n", vpdrev , FET_SUPPORT_VPD_REV);
rc = FET_ERROR_VPD_FET_NOT_SUPPORT;
goto get_out;
}
fetflag = (unsigned char)i2c_read_byte(MAIN_BOARD_I2C_EEPROM_DEV_ADDR, MAIN_BOARD_VPD_FET_FLAG_ADDR_START , &err);
if (fetflag != 1)
{
fprintf(stderr,"VPD does not include FET information\n");
rc = FET_ERROR_VPD_FET_NOT_SET;
goto get_out;
}
get_out:
resetI2CSwitches();
pthread_mutex_unlock(&i2c_mutex);
if (rc == 0){
readMain_I2C_eeprom(fet , board_id , MAIN_BOARD_VPD_FET_STR_ADDR_START , MAIN_BOARD_VPD_FET_STR_ADDR_LENGTH);
}
return rc;
}
开发者ID:Spondoolies-Tech,项目名称:miner_gate_sp30,代码行数:50,代码来源:mainvpd_lib.cpp
示例17: usb_in
extern byte_t usb_in ( byte_t* data, byte_t len )
#endif
{
uchar i;
if(status == STATUS_ADDRESS_ACK) {
if(len > expected) {
len = expected;
}
// consume bytes
for(i=0;i<len;i++) {
expected--;
*data = i2c_read_byte(expected == 0);
data++;
}
// end transfer on last byte
if((saved_cmd & CMD_I2C_END) && !expected)
i2c_stop();
} else {
memset(data, 0, len);
}
return len;
}
开发者ID:Technus,项目名称:usbavrlab-tool,代码行数:26,代码来源:main_i2cinterface.c
示例18: pcf8536_read
/*************************************************************************
** 函数名称: pcf8536_read(uint8 addr,uint8 *p,uint8 num)
** 功能描述: 读pcf8563
** 输 入: uint8 addr :高八位为器件地址,低八位为内部寄存器地址
uint8 *p :读出的数据存放地址的起始地址
uint8 num :读出数据的个数
**************************************************************************/
void pcf8536_read(uint8 addr,uint8 *p,uint8 num)
{
uint8 *pbuf = p;
i2c_start();
if(i2c_write_byte(WR_ADDR_CMD)==SLA_W)
{
i2c_write_byte(addr);
}
else
{
syserr=ERR_SLA_W;
}
i2c_start();
if(i2c_write_byte(RD_ADDR_CMD)==SLA_W)
{
i2c_write_byte(addr);
}
else
{
syserr=ERR_SLA_W;
}
for(; num > 0; num--)
{
*pbuf = i2c_read_byte();
pbuf++;
}
}
开发者ID:ryanbaw,项目名称:bravo,代码行数:37,代码来源:pcf8563.c
示例19: I2C_GPIO_Read
unsigned char I2C_GPIO_Read(unsigned char addr, unsigned char* buf, unsigned int len)
{
unsigned int i;
unsigned char state, data;
#if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr = 0u;
#endif
OS_ENTER_CRITICAL();
i2c_start(); //起始条件,开始数据通信
//发送地址和数据读写方向
data = (addr << 1) | 1; //低位为1,表示读数据
state = i2c_write_byte(data);
if(state != 0) {
i2c_stop();
OS_EXIT_CRITICAL();
return 1;
}
//读入数据
for (i=0; i<len; i++) {
buf[i] = i2c_read_byte();
}
i2c_stop(); //终止条件,结束数据通信
OS_EXIT_CRITICAL();
return 0;
}
开发者ID:nustpq,项目名称:uif_host_os_v2,代码行数:30,代码来源:i2c_gpio.c
示例20: sensor_report_value
static int sensor_report_value(struct i2c_client *client)
{
struct sensor_private_data *sensor =
(struct sensor_private_data *) i2c_get_clientdata(client);
struct sensor_platform_data *pdata = sensor->pdata;
int ret = 0;
int x = 0, y = 0, z = 0;
struct sensor_axis axis;
char buffer[6] = {0};
int i = 0;
int value = 0;
memset(buffer, 0, 6);
#if 0
/* Data bytes from hardware xL, xH, yL, yH, zL, zH */
do {
buffer[0] = sensor->ops->read_reg;
ret = sensor_rx_data(client, buffer, sensor->ops->read_len);
if (ret < 0)
return ret;
} while (0);
#else
for(i=0; i<6; i++)
{
i2c_read_byte(client, sensor->ops->read_reg + i,&buffer[i]);
}
#endif
x = (short) (((buffer[0]) << 8) | buffer[1]);
y = (short) (((buffer[2]) << 8) | buffer[3]);
z = (short) (((buffer[4]) << 8) | buffer[5]);
//printk("%s: x=%d y=%d z=%d \n",__func__, x,y,z);
if(pdata && pdata->orientation)
{
axis.x = (pdata->orientation[0])*x + (pdata->orientation[1])*y + (pdata->orientation[2])*z;
axis.y = (pdata->orientation[3])*x + (pdata->orientation[4])*y + (pdata->orientation[5])*z;
axis.z = (pdata->orientation[6])*x + (pdata->orientation[7])*y + (pdata->orientation[8])*z;
}
else
{
axis.x = x;
axis.y = y;
axis.z = z;
}
//filter gyro data
if((abs(axis.x) > pdata->x_min)||(abs(axis.y) > pdata->y_min)||(abs(axis.z) > pdata->z_min))
{
gyro_report_value(client, &axis);
/* »¥³âµØ»º´æÊý¾Ý. */
mutex_lock(&(sensor->data_mutex) );
sensor->axis = axis;
mutex_unlock(&(sensor->data_mutex) );
}
return ret;
}
开发者ID:Dee-UK,项目名称:RK3288_Lollipop_Kernel,代码行数:60,代码来源:ewtsa.c
注:本文中的i2c_read_byte函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论