当前位置: 首页>>代码示例>>C++>>正文


C++ i2c_read_byte函数代码示例

本文整理汇总了C++中i2c_read_byte函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_read_byte函数的具体用法?C++ i2c_read_byte怎么用?C++ i2c_read_byte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了i2c_read_byte函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的i2c_read_byte函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。