• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ I2C_Read函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了I2C_Read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: i2c_data_verify

bool i2c_data_verify(alt_u32 scl_base, alt_u32 sda_base, alt_u8 ControlAddr){
    bool bPass;
    const alt_8 DeviceAddr = 0xA0;
    alt_u8 OrgData, TestData, Data;
    
    TestData = alt_nticks();
    if (TestData == 0)
        TestData = 0x12;
    
    bPass = I2C_Read(scl_base, sda_base, DeviceAddr, ControlAddr, &OrgData);
    if (bPass) // write
        bPass = I2C_Write(scl_base, sda_base, DeviceAddr, ControlAddr, TestData);
    if (bPass) // read        
        bPass = I2C_Read(scl_base, sda_base, DeviceAddr, ControlAddr, &Data);
    if (bPass && (Data != TestData)) // verify
        bPass = FALSE;        
    // restore        
    if (bPass) // write back
        bPass = I2C_Write(scl_base, sda_base, DeviceAddr, ControlAddr, OrgData);
    if (bPass) // read        
        bPass = I2C_Read(scl_base, sda_base, DeviceAddr, ControlAddr, &Data);
    if (bPass && (Data != OrgData)) // verify
        bPass = FALSE; 
        
    return bPass;
}
开发者ID:pghu,项目名称:obstacle_avoider,代码行数:26,代码来源:I2C.c


示例2: Mpu6050ReadTemp

/*******************************************************************************
  * @brief  mpu6050 Tx.
  * @param  DestAddr: To
  * @param  pData: The data Tx
  * @param  DataLen: The number of data need to Tx
  * @retval Ref to system.h - StatusTypeDef.
  */
void Mpu6050ReadTemp(unsigned char DevID, char *pTemp)
{
  unsigned char buf[2] = {0, 0};

	I2C_Read(DevID, TEMP_OUT_L, 1, &buf[0]);
	I2C_Read(DevID, TEMP_OUT_H, 1, &buf[1]);
	*pTemp = (*(short *)buf) / 340 + 36.53;
}
开发者ID:AnCheTeng,项目名称:autonet,代码行数:15,代码来源:mpu6050APIs.c


示例3: EE_Read

/******************************************************************************
** Function name:   EE_Read
**
** Description:     Reads a word from EEPROM (Uses I2CRead)
**
** Parameters:      Address to read from
** Returned value:    Data at address
**
******************************************************************************/
uint32_t EE_Read (uint16_t _EEadd)
{
  uint32_t retDATA = 0;

  retDATA = I2C_Read(_EEadd+3);
  retDATA = (retDATA << 8) + I2C_Read(_EEadd+2);
  retDATA = (retDATA << 8) + I2C_Read(_EEadd+1);
  retDATA = (retDATA << 8) + I2C_Read(_EEadd+0);

  return retDATA;
}
开发者ID:stuff1993,项目名称:Unlimited_BMU_Shunt,代码行数:20,代码来源:Unlimited_BMU_Shunt.c


示例4: MPU9050_Read

uint8_t MPU9050_Read(mpu9050_t *mpu9050)
{
	//const TickType_t xTickToWait = 10;
	uint8_t status;

	I2C_Read(MPUSLVADDR, INT_STATUS, &status, 1);

	I2C_Read(MPUSLVADDR, ACCEL_XOUT_H, (uint8_t *)&mpu9050->accel.x, sizeof(triaxial_t));
	I2C_Read(MPUSLVADDR, GYRO_XOUT_H, (uint8_t *)&mpu9050->gyro.x, sizeof(triaxial_t));

	return status;
}
开发者ID:khldragon,项目名称:FreeRTOS_MSP430,代码行数:12,代码来源:mpu9050.c


示例5: HMC_Read

uint8_t HMC_Read(HMC_Data_t *hmc_data)
{
	uint8_t DataBuf[6];
	float tmp, r;

	I2C_Read(HMC_SLV_ADDR, DOUT_X_MSB, DataBuf, 6);

	hmc_data->direct.x = (DataBuf[0] << 8 | DataBuf[1]);
	hmc_data->direct.y = (DataBuf[2] << 8 | DataBuf[3]);
	hmc_data->direct.z = (DataBuf[4] << 8 | DataBuf[5]);

	r = sqrt((double)hmc_data->direct.x*(double)hmc_data->direct.x
			+(double)hmc_data->direct.y*(double)hmc_data->direct.y
			+(double)hmc_data->direct.z*(double)hmc_data->direct.z);

	tmp = (double)hmc_data->direct.x/r;
	tmp = acos(tmp);
	hmc_data->angle.x = tmp*180.0/3.1415926;
	
	tmp = (double)hmc_data->direct.y/r;
	tmp = acos(tmp);
	hmc_data->angle.y = tmp*180.0/3.1415926;
	
	tmp = (double)hmc_data->direct.z/r;
	tmp = acos(tmp);
	hmc_data->angle.z = tmp*180.0/3.1415926;

	return pdTRUE;
}
开发者ID:khldragon,项目名称:FreeRTOS_MSP430,代码行数:29,代码来源:hmc5883l.c


示例6: BusyXLCD

unsigned char BusyXLCD(void) {
    OLATB_curr |= 0xC0; // RW and RS are on
    clockLCDLow();
    I2C_Write(EXPANDER_IODIRB, 0x1E); // data bus is now an input
    I2C_Write(EXPANDER_OLATB, OLATB_curr);
    DelayFor18TCY();
    clockLCDHigh(); // Clock in the command with E
    DelayFor18TCY();
    
    busy = I2C_Read(EXPANDER_GPIOB);

    clockLCDLow(); // Reset clock line
    DelayFor18TCY();
    clockLCDHigh(); // Clock out other nibble
    DelayFor18TCY();
    clockLCDLow();
    OLATB_curr &= 0xBF; // Reset control line
    I2C_Write(EXPANDER_OLATB, OLATB_curr);
    I2C_Write(EXPANDER_IODIRB, 0x00); // set data bus back to output

    // busy bit is high?
    if (busy & 0x02)
    {
        return 1;
    }

    // Busy bit is low
    return 0;
}
开发者ID:yahooguntu,项目名称:DoorOpener,代码行数:29,代码来源:busyxlcd.c


示例7: ReadGPIO

/* Read GPIO Digital Inputs */
void ReadGPIO(void)
{
	int fd;
	unsigned char buff[5];
	unsigned char data[5];
	
	
	buff[0]=0x03;
	data[0]=0x00;
	
	
	/* Open I2C-BUS */	
	I2C_Open(&fd, 0x21);
	
	/* Write register */
	I2C_Send(&fd, buff,1 );
	
	/* Read the ADC */
	
	I2C_Read(&fd, data, 1);
	
	printf("GPIO: 0x%02x\n", data[0]);

	/* Close I2C-BUS */
	I2C_Close(&fd);


}
开发者ID:1ntroVert,项目名称:OLINUXINO,代码行数:29,代码来源:IO2.c


示例8: ReadSV

/* Read Board Firmware Version */
void ReadSV(void)
{
	int fd;
	unsigned char buff[5];
	unsigned char data[5];
	
	
	buff[0]=0x21;
	data[0]=0x00;
	
	
	/* Open I2C-BUS */	
	I2C_Open(&fd, 0x21);
	
	/* Write register */
	I2C_Send(&fd, buff,1 );
	
	/* Read the ADC */
	
	I2C_Read(&fd, data, 1);
	printf("Firmware Version: %d.0.%2d\n", data[0]>>4,data[0]&0x0f);

	/* Close I2C-BUS */
	I2C_Close(&fd);


}
开发者ID:1ntroVert,项目名称:OLINUXINO,代码行数:28,代码来源:IO2.c


示例9: ReadID

/* Read Board ID */
void ReadID(void)
{
	int fd;
	unsigned char buff[5];
	unsigned char data[5];
	
	
	buff[0]=0x20;
	data[0]=0x00;
	
	
	/* Open I2C-BUS */	
	I2C_Open(&fd, 0x21);
	
	/* Write register */
	I2C_Send(&fd, buff,1 );
	
	/* Read ID */
	
	I2C_Read(&fd, data, 1);
	printf("ID: 0x%x\n", data[0]);

	/* Close I2C-BUS */
	I2C_Close(&fd);


}
开发者ID:1ntroVert,项目名称:OLINUXINO,代码行数:28,代码来源:IO2.c


示例10: MAX44000_ReadRegister

//--------------- Reads data from device - single location
char MAX44000_ReadRegister(char rAddr) {
  tmp_data[0] = rAddr;
  I2C_Start();              // issue I2C start signal
  I2C_Write(MAX44000_I2C_Adr,tmp_data,1,_I2C_END_MODE_RESTART);
  I2C_Read (MAX44000_I2C_Adr,tmp_data,1,_I2C_END_MODE_STOP);
  return tmp_data[0];
}
开发者ID:Btar,项目名称:HEXIWEAR,代码行数:8,代码来源:MAX44000_Driver.c


示例11: Temperature_Get

/*---------------------------------------------------------------------------*
 * Routine:  Temperature_Get
 *---------------------------------------------------------------------------*
 * Description:
 *      Read the value of the ADT7420 and return the temperature in Celcius.
 * Inputs:
 *      void
 * Outputs:
 *      uint16_t -- temperature with 4 bits of fraction and 12 bits of
 *          integer.
 *---------------------------------------------------------------------------*/
uint16_t Temperature_Get(void)
{
    uint8_t target_reg;
    uint8_t target_data[2] = {0x00, 0x00};
    uint16_t temp = 0;
    uint32_t timeout = MSTimerGet();
    I2C_Request r;

    r.iAddr = ADT7420_ADDR>>1;
    r.iSpeed = 100;
    r.iWriteData = &target_reg;
    r.iWriteLength = 1;
    r.iReadData = target_data;
    r.iReadLength = 2;
    I2C_Write(&r, 0);
    while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < 10))
    {}
    I2C_Read(&r, 0);
    while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < 10))
    {}

    /* Convert the device measurement into a decimal number and insert
     into a temporary string to be displayed */
    temp = (target_data[0] << 8) + target_data[1];
    // temp = temp >> 3;

    return temp;
}
开发者ID:hyller,项目名称:GladiatorLaboratory,代码行数:39,代码来源:Temperature.c


示例12: MPL3115A2_readBytes_

bool MPL3115A2_readBytes_(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest, bool loop) {     
	int i=0;
	for(;i<5;i++)
	{
		if(I2C_Write(address,
				  (unsigned char*)&subAddress,
				  1,
				  0))
				  break; // if written length > 0
			if (!loop) break;
	}
	if (i>=5) 
		return false;
	for(i=0;i<5;i++)
	{
		if(I2C_Read(address,
             dest,
             count,
             1))
			break;  // if read length > 0
		if (!loop) break;
	}
	if (i<5)
		return true;
	return false;
}
开发者ID:cliveboyd,项目名称:SmartCane,代码行数:26,代码来源:MPL3115.c


示例13: EEPROM_Seq_Read

/*---------------------------------------------------------------------------*
 * Routine:  EEPROM_Seq_Read
 *---------------------------------------------------------------------------*
 * Description:
 *      Read the value of the address and return the data .
 * Inputs:
 *      void
 * Outputs:
 *      uint16_t -- temperature with 4 bits of fraction and 12 bits of
 *          integer.
 *---------------------------------------------------------------------------*/
int16_t EEPROM_Seq_Read(uint16_t addr,uint8_t *pdata, uint16_t r_lenth)
{
    uint8_t target_address[2];
    uint32_t timeout = MSTimerGet();
    I2C_Request r;
    int16_t result = 0;

    target_address[0] = addr & 0xFF00;
    target_address[1] = addr & 0x00FF;     

    r.iAddr = EEPROM_ADDR >> 1;
    r.iSpeed = 100;
    r.iWriteData = target_address;
    r.iWriteLength = 2;
    r.iReadData = pdata;
    r.iReadLength = r_lenth;
    I2C_Write(&r, 0);
    while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < 10))
        {}
    I2C_Read(&r, 0);
    while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < 10))
        {}

    result = 1;

    return result;
}
开发者ID:exosite-garage,项目名称:rl78g14_gs_cloud,代码行数:38,代码来源:EEPROM.c


示例14: Gyr_Read

/**
  * @brief  Reads from gyro
  * @param  Pointer to data structure
  * @retval I2C success/error code
  */
I2C_Returntype Gyr_Read(Vector* a) {						//This uses the pointer looparound
	I2C_Returntype r=I2C_Read((uint8_t*)a,6,GYR_ADD,GYR_DATA);
	Flipbytes(&(a->x));							//Fixed the swapped endianess
	Flipbytes(&(a->y));
	Flipbytes(&(a->z));
	return r;
}
开发者ID:Laurenceb,项目名称:Dactyl,代码行数:12,代码来源:i2c.c


示例15: MSTimerGet

/*---------------------------------------------------------------------------*
 * Routine:  Accelerometer_Get
 *---------------------------------------------------------------------------*
 * Description:
 *      Read the value of the ADT7420 and return the LightSensor in Lux.
 * Inputs:
 *      void
 * Outputs:
 *      uint16_t -- LightSensor with 4 bits of fraction and 12 bits of
 *          integer.
 *---------------------------------------------------------------------------*/
int16_t *Accelerometer_Get(void)
{
    uint8_t target_reg, acc_axis;
    uint8_t target_data[2] = {0x00, 0x00};
    uint32_t timeout = MSTimerGet();
    I2C_Request r;
       
    //Accelerometer_Init();
    for(acc_axis=0; acc_axis<3; acc_axis++)
    {
      target_reg = acc_reg_addr[acc_axis];
  
      r.iAddr = ACCEL_ADDR>>1;
      r.iSpeed = 100;
      r.iWriteData = &target_reg;
      r.iWriteLength = 1;
      r.iReadData = target_data;
      r.iReadLength = 2;
      I2C_Write(&r, 0);
      while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < 10))
          {}
      I2C_Read(&r, 0);
      while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < 10))
          {}
  
      /* Convert the device measurement into a decimal number and insert
       into a temporary string to be displayed */
      gAccData[acc_axis] = (target_data[1] << 8) + target_data[0]; 
    }
    return gAccData;
}
开发者ID:callkodakwolf,项目名称:novatel_rl78_cloud,代码行数:42,代码来源:Accelerometer.c


示例16: EEPROM_Read

/*******************************************************************************
 * Outline      : EEPROM_Read
 * Description  : This function writes the given contents to the
 *                 EEPROM, at the given location.
 * Argument     : offset -- Offset byte from start of EEPROM
 *                aData -- Pointer to bytes to write to EEPROM
 *                aSize -- number of bytes to write to EEPROM
 * Return value : 0 = success, else failure
 *******************************************************************************/
uint8_t EEPROM_Read(uint16_t offset, uint8_t *aData, uint16_t aSize)
{
    uint8_t writeData[2];
    uint32_t timeout = MSTimerGet();
    I2C_Request r;

    writeData[0] = (uint8_t)offset<<8;
    writeData[1] = (uint8_t)offset;
    
    r.iAddr = EEPROM_ADDR>>1;
    r.iSpeed = 100;
    r.iWriteData = writeData;
    r.iWriteLength = 2;
    r.iReadData = aData;
    r.iReadLength = aSize;
    
    I2C_Start();
    I2C_Write(&r, 0);
    while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < EEPROM_TIMEOUT))
        {}
    I2C_Read(&r, 0);
    while ((I2C_IsBusy()) && (MSTimerDelta(timeout) < EEPROM_TIMEOUT))
        {}

    return 0;
}
开发者ID:exosite-garage,项目名称:rl78g14_gs_cloud,代码行数:35,代码来源:EEPROM.c


示例17: main

/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main()
{
    int i;

    /*System clock configuration*/
    SystemInit();
    /* Configure UART2 */
   	S_UART_Init(115200);
    conf.scl = I2C_PA_9;
    conf.sda = I2C_PA_10;
    
    I2C_Init(&conf);
    
    //============ Write ==============
    I2C_Write(&conf, 0xa0, &Transmit_Data[0], MAX_SIZE);
    
    delay_function(4000);
    
    //========= Read =============
    //Write memory address
    I2C_Write(&conf, 0xA0, &Transmit_Data[0], 1);
    
    delay_function(4000);
    //Read data
    I2C_Read(&conf, 0xA0, &Recv_Data[0], MAX_SIZE - 1);
    
    printf("Recv data : ");
    for(i=0; i<MAX_SIZE - 1; i++)
    {
        printf("0x%x ", Recv_Data[i]);
    }
    printf("\r\n");
    
    
}
开发者ID:edwin-oetelaar,项目名称:W7500P,代码行数:40,代码来源:main.c


示例18: MPL3115A2_read8

uint8_t MPL3115A2_read8(uint8_t a) {
	int i=0;
	uint8_t out;
	for(;i<5;i++)
	{
		if(I2C_Write(MPL3115A2_ADDRESS,
				  (unsigned char*)&a,
				  1,
				  0))
				  break; // if written length > 0
	}
	if (i>=5) 
		return 0xff;  // failed
	for(i=0;i<5;i++)
	{
		if(I2C_Read(MPL3115A2_ADDRESS,
             &out,
             1,
             0))
			break;  // if read length > 0
	}
	if (i<5)
		return out;
	return 0xff;
}
开发者ID:cliveboyd,项目名称:SmartCane,代码行数:25,代码来源:MPL3115.c


示例19: BusScan

/* Use this function to find module i2c address */
void BusScan(void)
{
	int fd;
	unsigned char buff[5];
	unsigned char data[5];
	unsigned char adrs;
	
	
for (adrs = 1; adrs < 129; adrs++)
{	
	buff[0]=0x20;
	data[0]=0x00;

	
	/* Open I2C-BUS */	
	I2C_Open(&fd, adrs);
	
	if (1)
	{
	/* Write register */
	I2C_Send(&fd, buff,1 );
	
	/* Read the ADC */
	
	I2C_Read(&fd, data, 1);
	if (data[0]==0x23)
	printf("Found with I2c address 0x%02x \n", adrs);

	/* Close I2C-BUS */
	I2C_Close(&fd);
}
	
} 	
}
开发者ID:1ntroVert,项目名称:OLINUXINO,代码行数:35,代码来源:IO2.c


示例20: HMC_GetStatus

uint8_t HMC_GetStatus(void)
{
	uint8_t status;

	I2C_Read(HMC_SLV_ADDR, HMC_STATUS, &status, 1);

	return status;
}
开发者ID:khldragon,项目名称:FreeRTOS_MSP430,代码行数:8,代码来源:hmc5883l.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ I2C_ReceiveData函数代码示例发布时间:2022-05-30
下一篇:
C++ I2C_ITConfig函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap