int eep_read(uint32_t addr, uint8_t *buf, uint32_t len) { uint8_t chip_addr; chip_addr = (addr/256) + eep_dev.addr; return I2C_BurstRead(eep_dev.bus_instance, chip_addr, addr%256, 1, buf, len); }
int IIC_Read(uint8_t addr, uint8_t reg, uint8_t len, uint8_t *buf) { if(I2C_BurstRead(HW_I2C0,addr,reg,1,buf,len)) return FALSE; else return TRUE; }
uint8_t MB85RC64_ReadByte(uint16_t pos) { uint8_t data; pos = BSWAP_16(pos); I2C_BurstRead(gInstance, MB85RC64_ADDR, pos, 2, &data, 1); return data; }
int mpu6050_readangle_dmp(float *pitch_dmp,float *roll_dmp,float *yaw_dmp,int16_t *gyro_x,int16_t *gyro_y,int16_t *gyro_z) { static int16_t gyro_y_save=0,gyro_z_save=0; static float roll_save =0,pitch_save =0,yaw_save =0; float GyroscopeAngleSpeed; dmp_read_fifo(gyro, accel, quat, &sensor_timestamp, &sensors,&more); /* Gyro and accel data are written to the FIFO by the DMP in chip frame and hardware units. * This behavior is convenient because it keeps the gyro and accel outputs of dmp_read_fifo and mpu_read_fifo consistent. **/ /*if (sensors & INV_XYZ_GYRO ) send_packet(PACKET_TYPE_GYRO, gyro); if (sensors & INV_XYZ_ACCEL) send_packet(PACKET_TYPE_ACCEL, accel); */ /* Unlike gyro and accel, quaternions are written to the FIFO in the body frame, q30. * The orientation is set by the scalar passed to dmp_set_orientation during initialization. **/ int16_t gdata[3]; uint8_t buf[6]; while(I2C_BurstRead(HW_I2C0, 0x68, 0x43, 1, buf, 6)); gdata[0] = (int16_t)(((uint16_t)buf[0]<<8)+buf[1]); gdata[1] = (int16_t)(((uint16_t)buf[2]<<8)+buf[3]); gdata[2] = (int16_t)(((uint16_t)buf[4]<<8)+buf[5]); if(sensors & INV_XYZ_GYRO ) { q0 = quat[0] / q30; q1 = quat[1] / q30; q2 = quat[2] / q30; q3 = quat[3] / q30; Pitch = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3; // pitch Roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3; // roll Yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3; //yaw *pitch_dmp = pitch_save= Pitch; *roll_dmp = roll_save = Roll; *yaw_dmp = yaw_save = Yaw; *gyro_x = gdata[0]+ flashcontrol_read(GYROSCOPE_OFFSET); *gyro_y = gyro_y_save = gyro[1]; *gyro_z = gyro_z_save = gyro[2]; return 0;//success } GyroscopeAngleSpeed = (gdata[0] + flashcontrol_read(GYROSCOPE_OFFSET)) *flashcontrol_read(GYROSCOPE_ANGLE_RATIO); roll_save += GyroscopeAngleSpeed; *pitch_dmp = pitch_save; *roll_dmp = roll_save ; *yaw_dmp = yaw_save ; *gyro_x = gdata[0]+ flashcontrol_read(GYROSCOPE_OFFSET); *gyro_y = gyro_y_save; *gyro_z = gyro_z_save; return 1; }
/** * @brief read single register value * \param[in] instance instance of i2c moudle * \param[in] chipAddr i2c slave addr * \param[in] addr i2c slave register offset * \param[out] data data pointer * @note usually used on i2c sensor devices * \retval 0 success * \retval 1 failure */ int I2C_ReadSingleRegister(uint32_t instance, uint8_t chipAddr, uint8_t addr, uint8_t *data) { return I2C_BurstRead(instance, chipAddr, addr, 1, data, 1); }
/** * @brief 读取一个从机寄存器(寄存器地址在从机中必须为8位地址 如MMA845x等传感器设备) * @code * //使用i2c的1模块读取地址为0x55的从机中地址为0x01的数据,存储到data中 * I2C_WriteSingleRegister(HW_I2C1, 0x55, 0x01, &data); * @endcode * @param instance :I2C模块号 * @arg HW_I2C0 :I2C0模块 * @arg HW_I2C1 :I2C1模块 * @arg HW_I2C2 :I2C2模块 * @param deviceAddress :从机设备地址0~127 * @param registerAddress: 寄存器在从机中的地址 * @param pData: 数据指针 * @retval 0:成功 1:地址发送失败 2:数据发送失败 */ uint8_t I2C_ReadSingleRegister(uint32_t instance, uint8_t deviceAddress, uint8_t registerAddress, uint8_t* pData) { return I2C_BurstRead(instance, deviceAddress, registerAddress, 1, pData, 1); }
int MB85RC64_Read(uint16_t pos, uint8_t * buf, uint32_t len) { pos = BSWAP_16(pos); return I2C_BurstRead(gInstance, MB85RC64_ADDR, pos, 2, buf, len); }