Ejemplo n.º 1
0
uint8_t SENSOR9AXIS_Read_Bytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
{
    /*
     * devAddr should be shifted 1 bit to left ...
     */
    
    Status  i2cRW_status;

    /* Disable FSMC */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, DISABLE);

    Buffer_Tx1[0] = regAddr;

    i2cRW_status = I2C_Master_BufferWrite(I2C1, Buffer_Tx1, 1, Interrupt, devAddr << 1);
    if(Error == i2cRW_status)
    {
        DEBUG_MSG_FUNC_ERROR;
        return 0;
    }

    i2cRW_status = I2C_Master_BufferRead(I2C1, data, length, Polling, devAddr << 1);
    if(Error == i2cRW_status)
    {
        DEBUG_MSG_FUNC_ERROR;
        return 0;
    }

    /* Enable FSMC */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

    return length;
}
Ejemplo n.º 2
0
/**  
  * @brief  This function handles TIM2 interrupt request.  
  * @param  None  
  * @retval : None  
  */   
void TIM2_IRQHandler(void)   
{   
   
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);   
    I2C_Master_BufferRead(Master_Buffer_Rx, 6);   
   
}   
Ejemplo n.º 3
0
//读取MPU6050 I2C Slave0 的数据
int MPU6050_Read_Ext_Sens_Data(uint8_t RegAddr,uint8_t *buff, uint8_t length)
{
	Status rtn;
	IIC_Buffer_Tx[0] = RegAddr;  
	rtn = I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
	rtn = I2C_Master_BufferRead(MPU6050_I2C, buff,length,Polling, MPU6050_Addr);
	return rtn;
}
Ejemplo n.º 4
0
//**************************************
//读指定地址数据
//**************************************
uint16_t MPU6050_GetData(uint8_t REG_Address)
{
	Status rtn;
	char H,L;
	//H=Single_ReadI2C(REG_Address);
		IIC_Buffer_Tx[0]=REG_Address;
	  I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
		rtn=I2C_Master_BufferRead(MPU6050_I2C,IIC_Buffer_Rx,1,Polling, MPU6050_Addr);	
		if(rtn == Success) H=IIC_Buffer_Rx[0];
		else H=0;
	//L=Single_ReadI2C(REG_Address+1);
		IIC_Buffer_Tx[0]=REG_Address+1;
	  I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
		rtn=I2C_Master_BufferRead(MPU6050_I2C,IIC_Buffer_Rx,1,Polling, MPU6050_Addr);
		if(rtn == Success) L=IIC_Buffer_Rx[0];
		else L=0;
	return (H<<8)+L;   //合成数据
}
Ejemplo n.º 5
0
uint8_t at24c64_read_bytes(uint16_t address, uint8_t *data, uint16_t n) {
    tx = (uint8_t*)malloc(2 * sizeof(uint8_t));
    tx[0] = address << 8;
    tx[1] = 0x00FF & address;
    I2C_Master_BufferWrite(I2C1, tx, 2, Polling, AT24C64_ADDRESS << 1);
    I2C_Master_BufferRead(I2C1, data, n, Polling, AT24C64_ADDRESS << 1);

    free(tx);
    return 0;
}
Ejemplo n.º 6
0
// init ADG715 switch to use for EC or Temp measurements, or EC or Temp calibration
void init_adg715(uint8_t mode) {
    range_mode = mode;
    adg_conf[0] = mode;
    uint8_t i=0;
    // write config
    I2C_Master_BufferWrite(EVAL0349_I2CX,adg_conf,1,Polling, ADG715_ADDR);
    Delay_us_(100000);
    // and read it back for assurance. Could be disabled to enhance the speed
    I2C_Master_BufferRead(EVAL0349_I2CX, adg_conf, 1,DMA,ADG715_ADDR);
    Delay_us_(100000);
}
Ejemplo n.º 7
0
// set pointer and read the data from AD5934
uint8_t ad5934_read_data(int addr) {
    uint8_t buf[2];
    buf[0] = AD5934_SET_ADDR_PNTR;
    buf[1] = addr;

    // send Set Pointer command to AD5934
    I2C_Master_BufferWrite(EVAL0349_I2CX,buf,2,DMA, AD5934_ADDR);

    Delay_us_(1000);
    // Read the data from AD5934. It sends the data from the register address with pointer set
    I2C_Master_BufferRead(EVAL0349_I2CX, buf, 1,DMA,AD5934_ADDR);
    vTaskDelay(50);
    return buf[0];
}
Ejemplo n.º 8
0
//**************************************
//连续读ax,ay,az,temperature,gx,gy,gz数据
//**************************************
int MPU6050_ReadRawData(struct MPU6050_RawData_s *s_IMUVar)
{
	Status rtn;
	char H,L;

	IIC_Buffer_Tx[0]=ACCEL_XOUT_H;
  I2C_Master_BufferWrite(MPU6050_I2C, IIC_Buffer_Tx,1,Polling, MPU6050_Addr);
	rtn=I2C_Master_BufferRead(MPU6050_I2C,IIC_Buffer_Rx,14,Polling, MPU6050_Addr);	
	if(rtn == Success) 
	{
		H=IIC_Buffer_Rx[0];
		L=IIC_Buffer_Rx[1];
		s_IMUVar->ax = (H<<8)+L;
		
		H=IIC_Buffer_Rx[2];
		L=IIC_Buffer_Rx[3];
		s_IMUVar->ay = (H<<8)+L;
		
		H=IIC_Buffer_Rx[4];
		L=IIC_Buffer_Rx[5];
		s_IMUVar->az = (H<<8)+L;
		
		H=IIC_Buffer_Rx[6];
		L=IIC_Buffer_Rx[7];
		s_IMUVar->temperature = (H<<8)+L;
		
		H=IIC_Buffer_Rx[8];
		L=IIC_Buffer_Rx[9];
		s_IMUVar->gx = (H<<8)+L;
		
		H=IIC_Buffer_Rx[10];
		L=IIC_Buffer_Rx[11];
		s_IMUVar->gy = (H<<8)+L;
		
		H=IIC_Buffer_Rx[12];
		L=IIC_Buffer_Rx[13];
		s_IMUVar->gz = (H<<8)+L;

	}
	return !rtn;
}
Ejemplo n.º 9
0
int stm32_i2c_read(unsigned char slave_addr,
                    unsigned char reg_addr,
                    unsigned char length,
                    unsigned char *data)
{
		Status rtn;
    if (!length)
        return 0;

		rtn=I2C_Master_BufferWrite(MPU6050_I2C, &reg_addr,1,Polling, slave_addr);
		if(rtn!=Success) return -1;
		rtn=I2C_Master_BufferRead(MPU6050_I2C, (uint8_t*)data,length,Polling, slave_addr);
    if(rtn==Success)
		{
			
			return 0;
		}
		else 
		{
			return -1;
		}
}
Ejemplo n.º 10
0
void hd44780_backlight(bool new_value) {
    backlight = new_value << 3;
    I2C_Master_BufferRead(I2C1, hd44780_data, 1, Polling, hd44780_address << 1);
    hd44780_data[0] |= backlight;
    I2C_Master_BufferWrite(I2C1, hd44780_data, 1, Polling, hd44780_address << 1);
}
Ejemplo n.º 11
0
//-----------------------------------------------------------------------------
// Helper function that is used to read from the part which abstracts what
// bus mode is currently being used.
//-----------------------------------------------------------------------------
static uint32_t si47xx_lowRead(u8 number_bytes, u8 *data_in)
{
	return I2C_Master_BufferRead(I2C1, data_in, number_bytes, Polling, SI47XX_ADDR);
	//I2C_Master_BufferRead(I2C1,Buffer_Rx1,120,Polling, 0x28);
}