Ejemplo n.º 1
0
// gets raw z-gyro data
unsigned int getGyroZ()
{
     unsigned int z;
     unsigned char zH, zL;
     zH = I2C_Read_Byte(g_ID, g_zH);
     zL = I2C_Read_Byte(g_ID, g_zL);
     z = ((zH << 8) | zL);
     return z;
}
Ejemplo n.º 2
0
// gets raw y-gyro data
unsigned int getGyroY()
{
     unsigned int y;
     unsigned char yH, yL;
     yH = I2C_Read_Byte(g_ID, g_yH);
     yL = I2C_Read_Byte(g_ID, g_yL);
     y = ((yH << 8) | yL);
     return y;
}
Ejemplo n.º 3
0
// gets raw x-gyro data
unsigned int getGyroX()
{
     unsigned int x;
     unsigned char xH, xL;
     xH = I2C_Read_Byte(g_ID, g_xH);
     xL = I2C_Read_Byte(g_ID, g_xL);
     x = ((xH << 8) | xL);
     return x;
}
Ejemplo n.º 4
0
void m_updateZRaw()
{
	float z;
	unsigned char zH, zL;
	zH = I2C_Read_Byte(m_ID, m_zH);
	zL = I2C_Read_Byte(m_ID, m_zL);
	z = ((zH << 8) | zL);
	m_zRaw = z * m_scale;
}
Ejemplo n.º 5
0
void m_updateYRaw()
{
	float y;
	unsigned char yH, yL;
	yH = I2C_Read_Byte(m_ID, m_yH);
	yL = I2C_Read_Byte(m_ID, m_yL);
	y = ((yH << 8) | yL);
	m_yRaw = y * m_scale;
}
Ejemplo n.º 6
0
void m_updateXRaw()
{
	float x;
	unsigned char xH, xL;
	xH = I2C_Read_Byte(m_ID, m_xH);
	xL = I2C_Read_Byte(m_ID, m_xL);
	x = ((xH << 8) | xL);
	m_xRaw = x * m_scale;
}
void BH1750_Read(void)
{   	
    I2C_Start();                          //起始信号
    I2C_Send_Byte(BH1750_Addr+1);         //发送设备地址+读信号
	while(I2C_Wait_Ack());
	BH1750_Data_Buf[0]=I2C_Read_Byte(1);  //发送ACK
	BH1750_Data_Buf[1]=I2C_Read_Byte(0);  //发送NACK

    I2C_Stop();                          //停止信号
    Delay_NOP_ms(5);
}
Ejemplo n.º 8
0
uint8_t I2C_Read(uint8_t Slave_Addr, uint8_t REG_Address)
{
    uint8_t REG_data;
    I2C_Start();
    I2C_Write_Byte(Slave_Addr);
    I2C_Write_Byte(REG_Address);
    I2C_Start();
    I2C_Write_Byte(Slave_Addr+1);
    REG_data=I2C_Read_Byte();
    Sendack(1);
    I2C_Stop();
    return REG_data;
}
Ejemplo n.º 9
0
void read_RTC_I2c(unsigned char pos_memoria)
{
    I2C_Idle();
    I2C_Start();
    I2C_Idle();
    I2C_Write_Byte(0xD0); //address of DS1307.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Write_Byte(pos_memoria); // Position the address pointer to 0.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_ReStart();
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Write_Byte(0xD1); // Direction bit set to read.
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    leitura = I2C_Read_Byte();
    I2C_Idle(); //Verifica e aguarda até o barramento I2C estar disponível.
    I2C_Send_NACK();
    I2C_Stop();
}
Ejemplo n.º 10
0
void Multiple_Read_HMC5883(HMC5883_DATA *dat)
{
    uint8_t f;
    I2C_Start();
    I2C_Write_Byte(HMC5883_SLAVE_ADDR);
    I2C_Write_Byte(0x03);
    I2C_Start();
    I2C_Write_Byte(HMC5883_SLAVE_ADDR+1);
    for (f=0; f<6; f++)
    {
        ((uint8_t *)dat)[f] = I2C_Read_Byte();
        if (f == 5)
        {
            Sendack(1);
        }
        else
        {
            Sendack(0);
        }
    }
    I2C_Stop();
}
Ejemplo n.º 11
0
uint16_t read_bh1750()
{
	
		_DATA=0x0;
	
	  //Chon POWER_ON
	  I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	
		I2C_Write_Byte(I2C1,POWER_ON);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
	  delay_us(15000);
	
	  //Chon mode 
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	
		I2C_Write_Byte(I2C1,CONTINUOUS_HIGH_RES_MODE_1);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
		delay_us(15000);
	
		//Doc du lieu
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x47);
    I2C_Get_Ack(I2C1);
	
		_BYTE_DATA_H=I2C_Read_Byte(I2C1);
	  I2C_Give_Ack(I2C1);
		_BYTE_DATA_L=I2C_Read_Byte(I2C1);
		I2C_Give_Ack(I2C1);
		I2C_Stop(I2C1);
		delay_us(15000);
		
		_DATA|=_BYTE_DATA_H<<8;
		_DATA|=_BYTE_DATA_L;
		
		
		//RESET
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	  
		I2C_Write_Byte(I2C1,RESET);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
	  delay_us(15000);
		
		
		//POWER_DOWN
		I2C_Start(I2C1);
		I2C_Write_Byte(I2C1,0x46);
    I2C_Get_Ack(I2C1);
	  
		I2C_Write_Byte(I2C1,POWER_DOWN);
    I2C_Get_Ack(I2C1);
		I2C_Stop(I2C1);
	  delay_us(15000);
		
		return _DATA;
}