Px4flow Read specific register data program via IIC

Source: Internet
Author: User

The underlying communication with yesterday's written IIC, today combined with official information successfully read all the specified register data attached to the source code

Include.h mainly includes some stm32 IO control macro definitions, specific reference to all routines in the time Atom Sys.h header file

Inc

#ifndef __px4flow_h#define__px4flow_h#include"include.h"//Device Address#definePx4flow_addr 0x42//Register macro definition, if it is 2 bytes a data address refers to the low byte bit, the high byte is the low-byte address after a bit, the combination is complete data interpretation from the official website//non-integral data//record the total number of IIC frames created#defineFrame_count_sum 0x00//uint16_t counts created i²c frames [frames]//X-axis latest frame all pixel moves and *10#definePixel_flow_x_sum 0x02//int16_t latest x Flow measurement in pixels*10 [pixels]//Y-Axis latest frame all pixel moves and *10#definePixel_flow_y_sum 0x04//int16_t latest y flow measurement in pixels*10 [pixels]//x-Axis speed#defineFlow_comp_m_x 0x06//int16_t x velocity*1000 [meters/sec]//y-Axis speed#defineFlow_comp_m_y 0x08//int16_t y velocity*1000 [meters/sec]//Optical Flow image quality#defineQUAL 0x0a//int16_t Optical Flow quality/confidence [0:bad, 255:maximum Quality]//x-axis gyroscope speed#defineGyro_x_rate 0x0c//int16_t Latest Gyro x rate [Rad/sec]//y-axis gyroscope speed#defineGyro_y_rate 0x0e//int16_t Latest Gyro y rate [rad/sec]//z-axis gyroscope speed#defineGyro_z_rate 0x10//int16_t latest Gyro Z rate [rad/sec]//Gyroscope data range#defineGyro_range 0x12//uint8_t Gyro Range [0:7] equals [deg/sec.: Deg/sec]//ultrasonic Data last update time to current time interval#defineSONAR_TIMESTAMP1 0x13//uint8_t time since last sonar update [milliseconds]//Ground Distance positive: Known distance, negative value: Unknown distance#defineGround_distance1 0x14//int16_t Ground distance in meters*1000 [meters]. Positive value:distance known.                                                             //Negative Value:unknown distance//the data address after the integration//How many times data has been updated since the last time the data was read#defineFrame_count_since_last_readout 0x16//uint16_t number of flow measurements since last i²c readout [frames]//The value after the x-axis speed integral since the last read of the IIC data#definePixel_flow_x_integral 0x18//int16_t accumulated flow in radians*10000 around X axis since last i²c readout [rad*10000]//The value after the y-axis speed integral since the last read of the IIC data#definePixel_flow_y_integral 0x1a//int16_t accumulated flow in radians*10000 around Y axis since last i²c readout [rad*10000]//x-axis angular velocity integral value since the last time the IIC data was read#defineGyro_x_rate_integral 0x1c//int16_t accumulated gyro x rates in radians*10000 since last i²c readout [rad*10000]//the y-axis angular velocity integral value since the last time the IIC data was read#defineGyro_y_rate_integral 0x1e//int16_t accumulated Gyro y rates in radians*10000 since last i²c readout [rad*10000]//z-axis angular velocity integral value since the last time the IIC data was read#defineGyro_z_rate_integral 0x20//int16_t accumulated Gyro Z rates in radians*10000 since last i²c readout [rad*10000]//the interval between the last and this time the IIC data was read#defineIntegration_timespan 0x22//uint32_t accumulation TimeSpan in microseconds since last i²c readout [microseconds]//ultrasonic Data last update time to current time interval#defineSONAR_TIMESTAMP2 0x26//uint32_t time since last sonar update [microseconds]//Ground Distance#defineGround_distance2 0x2a//int16_t Ground distance in meters*1000 [meters*1000]//Gyro Temperature#defineGyro_temperature 0x2c//int16_t Temperature * centi-degrees Celsius [degcelsius*100]//Optical flow integral data quality#defineQuality 0x2e//uint8_t averaged quality of accumulated flow values [0:bad quality;255:max quality]//reads a specified register specifying the number of bytes of dataU8 Flow_read_data (U8 addr,u8 reg,u8 len,u8 *buf);//Read 8-bit unsigned datauint8_t readu8_date (U8 addr,u8 reg);//read 16-bit unsigned datauint16_t readu16_date (U8 addr,u8 reg);//read 16-bit signed dataint16_t reads16_date (U8 addr,u8 reg);//read 32-bit unsigned datauint32_t readu32_date (U8 addr,u8 reg);#endif

Src

#include"px4flow.h"#include"include.h"#include"myiic.h"//reads a specified register specifying the number of bytes of dataU8 Flow_read_data (U8 addr,u8 reg,u8 len,u8 *buf)     {Iic_start (); Iic_send_byte ((Addr<<1)|0);//Send device Address + Write command    if(Iic_wait_ack ())//waiting for an answer{iic_stop (); return 1;    } iic_send_byte (REG); //Write register AddressIic_wait_ack ();//waiting for an answerIic_start (); Iic_send_byte ((Addr<<1)|1);//Send device address + read commandIic_wait_ack ();//waiting for an answer     while(len) {if(len==1) *buf=iic_read_byte (0);//read data, send Nack        Else*buf=iic_read_byte (1);//read data, send ACKlen--; BUF++;    } iic_stop (); //Create a Stop condition    return 0; }//Read 8-bit unsigned datauint8_t readu8_date (U8 addr,u8 reg) {U8 buff[1];    uint8_t date; Flow_read_data (Addr,reg,1, Buff); Date= buff[0]; returndate;}//read 16-bit unsigned datauint16_t readu16_date (U8 addr,u8 reg) {U8 buff[2];    uint16_t date; Flow_read_data (Addr,reg,2, Buff); Date= buff[1] <<8| buff[0]; returndate;}//read 16-bit signed dataint16_t reads16_date (U8 addr,u8 reg) {U8 buff[2];    int16_t date; Flow_read_data (Addr,reg,2, Buff); Date= buff[1] <<8| buff[0]; returndate;}//read 32-bit unsigned datauint32_t readu32_date (U8 addr,u8 reg) {U8 buff[4];    int16_t date; Flow_read_data (Addr,reg,2, Buff); Date= buff[3] << -| buff[2] << -| buff[1] <<8| buff[0]; returndate;}

Px4flow Read specific register data program via IIC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.