Código fonte da Plataforma Voadora - PDF

Description
Código fonte da Plataforma Voadora #include #include #include #pin_select IC1=PIN_B14 #pin_select IC3=PIN_B14 // Ganho do controlador de distancia float KP_distancia_Z=3500;

Please download to get full document.

View again

of 49
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information
Category:

Games & Puzzles

Publish on:

Views: 19 | Pages: 49

Extension: PDF | Download: 0

Share
Transcript
Código fonte da Plataforma Voadora #include main_mpu6050.h #include stdlib.h #include math.h #pin_select IC1=PIN_B14 #pin_select IC3=PIN_B14 // Ganho do controlador de distancia float KP_distancia_Z=3500; float KD_distancia_Z=8000; float KI_distancia_Z=2; // Ganho do controlador de Pitch / Roll float KP=72; //Porpocional float KD=4050; //Derivativo float KI=3.2; //Integral float KPB=00; //Porpocional float KDB=00; //Derivativo float KIB=0; //Integral //Valores de offset do giroscopio float GYRO_XOUT_OFFSET = ; float GYRO_YOUT_OFFSET = ; float GYRO_ZOUT_OFFSET = ; //Valores de offset do acelerometro int ACELL_XOUT_OFFSET=+139; int ACELL_YOUT_OFFSET=-108; int ACELL_ZOUT_OFFSET=0; //Variaveis int media_acelaracao=13550;// estabilizaçao 79 int ref_acelaracao=13550; float d_z_filter[20]=0.1,0.1,0.1,0.1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0; int distancia_z_i=0; int distancia_z_anterior=0; int count_distancia_z_filter=0; float CMD_distancia_Z=0; float CMD_compass_angulo=0; float erro_compass_angulo=0; float media_distancia_z=0; float64 soma_acelaracao=0; int count_media_aceleracao=0; int aux_acelaracao=0; float med_pressao=0; float soma_pressao=0; float CMD_pressao=0; float pressao=0; float erro_pressao=0; float integral_pressao=0; float derivativo_pressao=0; float erro_anterior_pressao=0; float KI_erro_pressao=5; float KD_erro_pressao=4000; float KP_erro_pressao=2000; int in=0; float distancia_z; signed int ACCEL_XOUT = 0; signed int ACCEL_YOUT = 0; signed int ACCEL_ZOUT = 0; float GYRO_XRATE = 0; float GYRO_YRATE = 0; 80 float GYRO_ZRATE = 0; int GYRO_XRATERAW = 0; int GYRO_YRATERAW = 0; int GYRO_ZRATERAW = 0; unsigned int8 GYRO_XOUT_L ; unsigned int8 GYRO_XOUT_H ; unsigned int8 GYRO_YOUT_L ; unsigned int8 GYRO_YOUT_H ; unsigned int8 GYRO_ZOUT_L ; unsigned int8 GYRO_ZOUT_H ; float GYRO_XOUT = 0; float GYRO_YOUT = 0; float GYRO_ZOUT = 0; unsigned int8 ACCEL_XOUT_L ; unsigned int8 ACCEL_XOUT_H ; unsigned int8 ACCEL_YOUT_L ; unsigned int8 ACCEL_YOUT_H ; unsigned int8 ACCEL_ZOUT_L ; unsigned int8 ACCEL_ZOUT_H ; signed long GYRO_XOUT_OFFSET_1000SUM = 0; signed long GYRO_YOUT_OFFSET_1000SUM = 0; signed long GYRO_ZOUT_OFFSET_1000SUM = 0; float XANGLE = 0; float YANGLE = 0; float GYRO_XANGLE = 0; float GYRO_YANGLE = 0; float GYRO_ZANGLE = 0; 81 long GYRO_XANGLERAW = 0; long GYRO_YANGLERAW = 0; long GYRO_ZANGLERAW = 0; float ACCEL_XANGLE = 0; float ACCEL_YANGLE = 0; float ACCEL_ZANGLE = 0; int count = 0; int8 xmsb; int8 xlsb; int8 ymsb; int8 ylsb; int8 zmsb; int8 zlsb; signed int16 rate_x; signed int16 rate_y; signed int16 rate_z; signed int32 dc_offset_x=0; signed int32 dc_offset_y=0; signed int32 dc_offset_z=0; signed int16 prev_rate_x=0; signed int16 prev_rate_y=0; signed int16 prev_rate_z=0; signed int16 gyrogx=0; signed int16 gyrogy=0; signed int16 gyrogz=0; float noise=0; float xg=0; float yg=0; float zg=0; 82 float compass_angulo=0,compass_angulo_anterior=0; //dados de voo int comando_altitude=0; int comando_angulo_x=0; int comando_angulo_y=0; int comando_angulo_r=0; int v_motor_xf_1=0; int v_motor_yt_2=0; int v_motor_xf_3=0; int v_motor_yf_4=0; unsigned velocidade_m1; unsigned velocidade_m2; unsigned velocidade_m3; unsigned velocidade_m4; unsigned long IC1_valor1, IC1_valor2; int count_ic1=0; //float KP,KD,KI,KPB,KDB,KIB; #define timeconstant.1 int8 i,accel_data[6],giro_data[6],j,k; signed int16 x=0,y=0,z=0; signed int16 x0=0,y0=0,z0=0; signed int16 x1=0,y1=0,z1=0; signed int16 x2=0,y2=0,z2=0; signed int16 x3=0,y3=0,z3=0; signed int16 x4=0,y4=0,z4=0; signed int16 x5=0,y5=0,z5=0; signed int16 x6=0,y6=0,z6=0; signed int16 x7=0,y7=0,z7=0; 83 signed int16 x8=0,y8=0,z8=0; signed int16 x9=0,y9=0,z9=0; //unsigned= int off_x=6,off_y=9,off_z=232; float roll=0; float pitch=0; float roll_radio=0; float pitch_radio=0; float acel_roll=0; float acel_pitch=0; int count_acel=0; float anterior_roll=0; float anterior_pitch=0; int32 K_2_velocidade_M1=0,K_2_velocidade_M2=0,K_2_velocidade_M3=0,K_2_velocidade_ M4=0; int K_1_velocidade_M1=0,K_1_velocidade_M2=0,K_1_velocidade_M3=0,K_1_velocidade_ M4=0; int erro_roll=0,k_1_erro_roll=0,erro_pitch=0,k_1_erro_pitch=0; float integral_erro_roll=0,integral_erro_pitch=0,integral_erro_compass_angulo=0; float derivativo_erro_roll=0,derivativo_erro_pitch=0,derivativo_erro_compass_angulo=0; float KI_erro_pitch=0,KI_erro_roll=0,KP_erro_pitch=0,KP_erro_roll=0,KD_erro_pitch=0,KD_ erro_roll=0; float erro_anterior_distancia_z=0,erro_distancia_z=0; float integral_distancia_z=0,derivativo_distancia_z=0; float KI_erro_distancia_Z=0,KP_erro_distancia_Z=0,KD_erro_distancia_Z=0; unsigned int aceleracao=0; int contg=0; int count_rf=150,count_bosula=0; 84 //int count=0; // MPU6050 atribuição nomes aos registos i2c #define MPU6050_ADDRESS 0b // Address with end write bit #define MPU6050_RA_XG_OFFS_TC 0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD #define MPU6050_RA_YG_OFFS_TC 0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD #define MPU6050_RA_ZG_OFFS_TC 0x02 //[7] PWR_MODE, [6:1] ZG_OFFS_TC, [0] OTP_BNK_VLD #define MPU6050_RA_X_FINE_GAIN 0x03 //[7:0] X_FINE_GAIN #define MPU6050_RA_Y_FINE_GAIN 0x04 //[7:0] Y_FINE_GAIN #define MPU6050_RA_Z_FINE_GAIN 0x05 //[7:0] Z_FINE_GAIN #define MPU6050_RA_XA_OFFS_H 0x06 //[15:0] XA_OFFS #define MPU6050_RA_XA_OFFS_L_TC 0x07 #define MPU6050_RA_YA_OFFS_H 0x08 //[15:0] YA_OFFS #define MPU6050_RA_YA_OFFS_L_TC 0x09 #define MPU6050_RA_ZA_OFFS_H 0x0A //[15:0] ZA_OFFS #define MPU6050_RA_ZA_OFFS_L_TC 0x0B #define MPU6050_RA_XG_OFFS_USRH 0x13 //[15:0] XG_OFFS_USR #define MPU6050_RA_XG_OFFS_USRL 0x14 #define MPU6050_RA_YG_OFFS_USRH 0x15 //[15:0] YG_OFFS_USR #define MPU6050_RA_YG_OFFS_USRL 0x16 #define MPU6050_RA_ZG_OFFS_USRH 0x17 //[15:0] ZG_OFFS_USR #define MPU6050_RA_ZG_OFFS_USRL 0x18 #define MPU6050_RA_SMPLRT_DIV 0x19 #define MPU6050_RA_CONFIG 0x1A #define MPU6050_RA_GYRO_CONFIG 0x1B #define MPU6050_RA_ACCEL_CONFIG 0x1C #define MPU6050_RA_FF_THR 0x1D #define MPU6050_RA_FF_DUR 0x1E #define MPU6050_RA_MOT_THR 0x1F 85 #define MPU6050_RA_MOT_DUR 0x20 #define MPU6050_RA_ZRMOT_THR 0x21 #define MPU6050_RA_ZRMOT_DUR 0x22 #define MPU6050_RA_FIFO_EN 0x23 #define MPU6050_RA_I2C_MST_CTRL 0x24 #define MPU6050_RA_I2C_SLV0_ADDR 0x25 #define MPU6050_RA_I2C_SLV0_REG 0x26 #define MPU6050_RA_I2C_SLV0_CTRL 0x27 #define MPU6050_RA_I2C_SLV1_ADDR 0x28 #define MPU6050_RA_I2C_SLV1_REG 0x29 #define MPU6050_RA_I2C_SLV1_CTRL 0x2A #define MPU6050_RA_I2C_SLV2_ADDR 0x2B #define MPU6050_RA_I2C_SLV2_REG 0x2C #define MPU6050_RA_I2C_SLV2_CTRL 0x2D #define MPU6050_RA_I2C_SLV3_ADDR 0x2E #define MPU6050_RA_I2C_SLV3_REG 0x2F #define MPU6050_RA_I2C_SLV3_CTRL 0x30 #define MPU6050_RA_I2C_SLV4_ADDR 0x31 #define MPU6050_RA_I2C_SLV4_REG 0x32 #define MPU6050_RA_I2C_SLV4_DO 0x33 #define MPU6050_RA_I2C_SLV4_CTRL 0x34 #define MPU6050_RA_I2C_SLV4_DI 0x35 #define MPU6050_RA_I2C_MST_STATUS 0x36 #define MPU6050_RA_INT_PIN_CFG 0x37 #define MPU6050_RA_INT_ENABLE 0x38 #define MPU6050_RA_DMP_INT_STATUS 0x39 #define MPU6050_RA_INT_STATUS 0x3A #define MPU6050_RA_ACCEL_XOUT_H 0x3B #define MPU6050_RA_ACCEL_XOUT_L 0x3C #define MPU6050_RA_ACCEL_YOUT_H 0x3D #define MPU6050_RA_ACCEL_YOUT_L 0x3E #define MPU6050_RA_ACCEL_ZOUT_H 0x3F 86 #define MPU6050_RA_ACCEL_ZOUT_L 0x40 #define MPU6050_RA_TEMP_OUT_H 0x41 #define MPU6050_RA_TEMP_OUT_L 0x42 #define MPU6050_RA_GYRO_XOUT_H 0x43 #define MPU6050_RA_GYRO_XOUT_L 0x44 #define MPU6050_RA_GYRO_YOUT_H 0x45 #define MPU6050_RA_GYRO_YOUT_L 0x46 #define MPU6050_RA_GYRO_ZOUT_H 0x47 #define MPU6050_RA_GYRO_ZOUT_L 0x48 #define MPU6050_RA_EXT_SENS_DATA_00 0x49 #define MPU6050_RA_EXT_SENS_DATA_01 0x4A #define MPU6050_RA_EXT_SENS_DATA_02 0x4B #define MPU6050_RA_EXT_SENS_DATA_03 0x4C #define MPU6050_RA_EXT_SENS_DATA_04 0x4D #define MPU6050_RA_EXT_SENS_DATA_05 0x4E #define MPU6050_RA_EXT_SENS_DATA_06 0x4F #define MPU6050_RA_EXT_SENS_DATA_07 0x50 #define MPU6050_RA_EXT_SENS_DATA_08 0x51 #define MPU6050_RA_EXT_SENS_DATA_09 0x52 #define MPU6050_RA_EXT_SENS_DATA_10 0x53 #define MPU6050_RA_EXT_SENS_DATA_11 0x54 #define MPU6050_RA_EXT_SENS_DATA_12 0x55 #define MPU6050_RA_EXT_SENS_DATA_13 0x56 #define MPU6050_RA_EXT_SENS_DATA_14 0x57 #define MPU6050_RA_EXT_SENS_DATA_15 0x58 #define MPU6050_RA_EXT_SENS_DATA_16 0x59 #define MPU6050_RA_EXT_SENS_DATA_17 0x5A #define MPU6050_RA_EXT_SENS_DATA_18 0x5B #define MPU6050_RA_EXT_SENS_DATA_19 0x5C #define MPU6050_RA_EXT_SENS_DATA_20 0x5D #define MPU6050_RA_EXT_SENS_DATA_21 0x5E #define MPU6050_RA_EXT_SENS_DATA_22 0x5F 87 #define MPU6050_RA_EXT_SENS_DATA_23 0x60 #define MPU6050_RA_MOT_DETECT_STATUS 0x61 #define MPU6050_RA_I2C_SLV0_DO 0x63 #define MPU6050_RA_I2C_SLV1_DO 0x64 #define MPU6050_RA_I2C_SLV2_DO 0x65 #define MPU6050_RA_I2C_SLV3_DO 0x66 #define MPU6050_RA_I2C_MST_DELAY_CTRL 0x67 #define MPU6050_RA_SIGNAL_PATH_RESET 0x68 #define MPU6050_RA_MOT_DETECT_CTRL 0x69 #define MPU6050_RA_USER_CTRL 0x6A #define MPU6050_RA_PWR_MGMT_1 0x6B #define MPU6050_RA_PWR_MGMT_2 0x6C #define MPU6050_RA_BANK_SEL 0x6D #define MPU6050_RA_MEM_START_ADDR 0x6E #define MPU6050_RA_MEM_R_W 0x6F #define MPU6050_RA_DMP_CFG_1 0x70 #define MPU6050_RA_DMP_CFG_2 0x71 #define MPU6050_RA_FIFO_COUNTH 0x72 #define MPU6050_RA_FIFO_COUNTL 0x73 #define MPU6050_RA_FIFO_R_W 0x74 #define MPU6050_RA_WHO_AM_I 0x75 #define gyro_xsensitivity 131 //66.5 Dead on at last check #define gyro_ysensitivity 131 //72.7 Dead on at last check #define gyro_zsensitivity 131 #define a 0.01 #define dt // SI4432 atribuição nomes aos registos i2c #define SI4432_PWRSTATE_READY 01 // Si4432 ready mode define #define SI4432_PWRSTATE_TX 0x09 // Si4432 Tx mode define #define SI4432_PWRSTATE_RX 05 // Si4432 Rx mode define 88 #define SI4432_PACKET_SENT_INTERRUPT 04 // Si4432 packet sent interrupt define #define SI4432_Rx_packet_received_interrupt 0x02 // Si4432 packet received interrupt define #define nirq PIN_B6 // MCU input port #define nsel PIN_B7 // MCU output port #define SDN PIN_B5// MCU output port unsigned char rx_buf[15]= 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00; unsigned char tx_test_data[10] = 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x6d; //FIM RF void spi_rw(unsigned char addr, unsigned char data) output_bit(nsel,0); delay_us(1); spi_write2(addr); spi_write2(data); delay_us(1); output_bit(nsel,1); void init_rf(void) output_bit(sdn,1); delay_ms(200); // RF module reset output_bit(sdn,0); delay_ms(300); // Delay 200 ms 89 spi_rw(0x03,0x00); // clear interrupt factor of Si4432 spi_rw(0x04,0x00); spi_rw(0x06 0x80, 0x00); // disable the interrupt of Si4432 spi_rw(0x07 0x80, SI4432_PWRSTATE_READY); // to Ready mode spi_rw(0x09 0x80, 0x7f); // load Capacitance = 12PF spi_rw(0x0a 0x80, 0x05); // output clock spi_rw(0x0b 0x80, 0xea); // GPIO 0 = digital output spi_rw(0x0c 0x80, 0xea); //GPIO 1 = digital output spi_rw(0x0d 0x80, 0xf4); // /GPIO 2 = Rx data // The settings below are obtained from the Excel calculation table from silicon labs spi_rw(0x70 0x80, 0x2c); spi_rw(0x1d 0x80, 0x40); // enable AFC // 1.2K bps setting spi_rw(0x1c 0x06, 0x1B); spi_rw(0x20 0x80, 0x3F); spi_rw(0x21 0x80, 0x02); // spi_rw(0x22 0x80, 0x0C);// spi_rw(0x23 0x80, 0x4A); // spi_rw(0x24 0x80, 0x04); // spi_rw(0x25 0x80, 0x58); // spi_rw(0x2a 0x80, 0x14); spi_rw(0x6e 0x80, 0x10); spi_rw(0x6f 0x80, 0x62); //spi_rw(0x6e 0x80, 0x41); //spi_rw(0x6f 0x80, 0x89); spi_rw(0x70 0x80, 0x04); //1.2K bps setting end spi_rw(0x30 0x80, 0x8c); // PH + FiFo, MSB, CRC enabled spi_rw(0x32 0x80, 0xff); // Header= Byte0, 1, 2, 3 spi_rw(0x33 0x80, 0x42); // Sync = byte 3,2 spi_rw(0x34 0x80, 16); // Tx Preamble = 16 nibble spi_rw(0x35 0x80, 0x20); // Detected preamble = 4 nibble 90 spi_rw(0x36 0x80, 0x2d); // Sync word = 0x2dd4 spi_rw(0x37 0x80, 0xd4); spi_rw(0x38 0x80, 0x00); spi_rw(0x39 0x80, 0x00); spi_rw(0x3a 0x80, 's'); // Tx header = swwx spi_rw(0x3b 0x80, 'w'); spi_rw(0x3c 0x80, 'w'); spi_rw(0x3d 0x80, 'x'); spi_rw(0x3e 0x80, 10); // payload = 10 byte spi_rw(0x3f 0x80, 's'); // header checked = swwx spi_rw(0x40 0x80, 'w'); spi_rw(0x41 0x80, 'w'); spi_rw(0x42 0x80, 'x'); spi_rw(0x43 0x80, 0xff); // all bit need be checked spi_rw(0x44 0x80, 0xff); // spi_rw(0x45 0x80, 0xff); // spi_rw(0x46 0x80, 0xff); // spi_rw(0x6d 0x80, 0x07); // max power output spi_rw(0x79 0x80, 0x0); // no hopping spi_rw(0x7a 0x80, 0x0); // no hopping spi_rw(0x71 0x80, 0x2B); // RF mode = FSK, FiFo spi_rw(0x72 0x80, 0x28); // Frequency deviation = 30KHz spi_rw(0x73 0x80, 0x0); // No freq offset spi_rw(0x74 0x80, 0x0); // No freq offset spi_rw(0x75 0x80, 0x53); // freq = 433.5MHz spi_rw(0x76 0x80, 0x57); // spi_rw(0x77 0x80, 0x80); void Modo_RX_RF(void) 91 spi_rw(0x07 0x80, SI4432_PWRSTATE_READY); // enter Ready mode delay_ms(1); // stablize the OSC; not needed if OSC is on spi_rw(0x0e 0x80, 0x02); // Antenna switch to Rx mode //TX0_RX1; // antenna switch = Rx mode spi_rw(0x08 0x80, 0x03); //clear Tx/Rx fifo spi_rw(0x08 0x80, 0x00); //clear Tx/Rx fifo spi_rw(0x07 0x80,SI4432_PWRSTATE_RX ); // enter Rx mode spi_rw(0x05 0x80, SI4432_Rx_packet_received_interrupt); // interrupt for packet received spi_rw(0x03,0x00); //clear all interrupt factor spi_rw(0x04,0x00); //clear all interrupt factor void Ler_Dados_RF(void) if(input(nirq)==1) //printf( sem dados\n\r ); return; unsigned char i, j, chksum; spi_rw(0x03,0x00); // clear interrupt factor //read the Interrupt Status1 register spi_rw(0x04,0x00); // clear interrupt factor output_bit(nsel,0); delay_us(2); spi_write2(0x7f); // read data from the Si4432 FiFo for(i = 0;i 10;i++) rx_buf[i] = spi_read2(0x7f); 92 output_bit(nsel,1); spi_rw(0x07 0x80, SI4432_PWRSTATE_READY); // Exit Rx mode after all the data read from the FiFo chksum = 0; for(i=0;i 9;i++) // calculate the checksum for the received data chksum += rx_buf[i]; if(( 0x41 == 0x41 )) //printf( dados ok\n\r ); //printf( dados rx0=%x rx1=%x rx2=%x\n\r ,rx_buf[0],rx_buf[1],rx_buf[2]); else //printf( dados Erro\n\r ); //printf( dados rx%c\n\r ,rx_buf[0]); modo_rx_rf(); void LDByteWriteI2C( int8 deviceaddress,int8 address,int8 val_pass) i2c_start(); // start transmission to device i2c_write(0b ); // send device address i2c_write(address); // send register address i2c_write(val_pass); // send value to write i2c_stop(); // end transmission delay_ms(1); int8 LDByteReadI2C(unsigned char deviceaddress, unsigned char address) 93 unsigned int8 dados_read; i2c_start(); // start transmission to device i2c_write(0b ); // This is where you have to _write_ the register number you want i2c_write(address); // register to read i2c_start(); // restart - the bus is now set to _read_ i2c_write(0b ); // now turn the bus round dados_read= i2c_read(0); i2c_stop(); // This will update x, y, and z with new values return dados_read; // Inicialização do Acelerometro void acel_init() restart_init: int8 Data = 0x00; unsigned char Failed = 0; LDByteWriteI2C(MPU6050_ADDRESS, 0b ); delay_ms(100); LDByteWriteI2C(MPU6050_ADDRESS, 0b ); MPU6050_RA_PWR_MGMT_1, MPU6050_RA_PWR_MGMT_1, //Sets sample rate to 1000/1+1 = 500Hz LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_SMPLRT_DIV, 0x01); //Disable FSync, 48Hz DLPF LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_CONFIG, 0x05); //Disable gyro self tests, scale of 500 degrees/s LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_CONFIG, 0b ); 94 //Disable accel self tests, scale of +-4g, no DHPF LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_ACCEL_CONFIG, 0b ); //Freefall threshold of 0mg LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_FF_THR, 0x00); //Freefall duration limit of 0 LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_FF_DUR, 0x00); //Motion threshold of 0mg LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_MOT_THR, 0x00); //Motion duration of 0s LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_MOT_DUR, 0x00); //Zero motion threshold LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_ZRMOT_THR, 0x00); //Zero motion duration threshold LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_ZRMOT_DUR, 0x00); //Disable sensor output to FIFO buffer LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_FIFO_EN, 0x00); //AUX I2C setup //Sets AUX I2C to single master control, plus other config LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_MST_CTRL, 0x00); //Setup AUX I2C slaves LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_ADDR, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_REG, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_CTRL, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_ADDR, 0x00); 95 0x00); 0x00); 0x00); 0x00); 0x00); 0x00); 0x00); 0x00); 0x00); 0x00); 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_REG, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_CTRL, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_ADDR, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_REG, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_CTRL, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_ADDR, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_REG, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_CTRL, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_ADDR, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_REG, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_DO, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_CTRL, LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV4_DI, 0x00); //MPU6050_RA_I2C_MST_STATUS //Read-only //Setup INT pin and AUX I2C pass through LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_INT_PIN_CFG, 0x02); //Enable data ready interrupt LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_INT_ENABLE, 0x00); //Slave out, dont care 96 LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV0_DO, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV1_DO, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV2_DO, 0x00); LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_SLV3_DO, 0x00); //More slave config LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_I2C_MST_DELAY_CTRL, 0x00); //Reset sensor signal paths LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_SIGNAL_PATH_RESET, 0x00); //Motion detection control LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_MOT_DETECT_CTRL, 0x00); //Disables FIFO, AUX I2C, FIFO and I2C reset bits to 0 LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_USER_CTRL, 0x00); //Sets clock source to gyro reference w/ PLL LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_1, 0b ); //Controls frequency of wakeups in accel low power mode plus the sensor standby modes LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_PWR_MGMT_2, 0x00); //MPU6050_RA_BANK_SEL //Not in datasheet //MPU6050_RA_MEM_START_ADDR //Not in datasheet //MPU6050_RA_MEM_R_W //Not in datasheet //MPU6050_RA_DMP_CFG_1 //Not in datasheet //MPU6050_RA_DMP_CFG_2 //Not in datasheet //MPU6050_RA_FIFO_COUNTH //Read-only //MPU6050_RA_FIFO_COUNTL //Read-only //Data transfer to and from the FIFO buffer LDByteWriteI2C(MPU6050_ADDRESS, MPU6050_RA_FIFO_R_W, 0x00); //MPU6050_RA_WHO_AM_I //Read-only, I2C address 97 printf( \nmpu6050 Setup Complete ); delay_ms(1000); // Teste de leitura dos registos Data=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_SMPLRT_DIV); if(data!= 0x01) printf( \nregister check 1 failed, value should be 0x01, was 0x%x\n\r , Data); Failed = 1; if (Failed == 0) printf( \nregister value check passed\n\r ); else printf( register value check failed\n\r ); i2c_start(); i2c_stop(); goto restart_init; delay_ms(100); test: int x = 0; GYRO_XOUT_OFFSET_1000SUM = 0; GYRO_YOUT_OFFSET_1000SUM = 0; GYRO_ZOUT_OFFSET_1000SUM = 0; GYRO_XOUT= 0; GYRO_YOUT = 0; GYRO_ZOUT = 0; goto pass_gyro_cal; 98 for(x = 1; x =1000; ++x) /* GYRO_XOUT_H=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_XOUT_H); GYRO_XOUT_L=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_XOUT_L); GYRO_YOUT_H=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_YOUT_H); GYRO_YOUT_L=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_YOUT_L); GYRO_ZOUT_H=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_ZOUT_H); GYRO_ZOUT_L=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_GYRO_ZOUT_L); */ GYRO_XOUT_H=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_ACCEL_XOUT_H); GYRO_XOUT_L=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_ACCEL_XOUT_L); GYRO_YOUT_H=LDByteReadI2C(MPU6050_ADDRESS, MPU6050_RA_ACCEL_YOUT_H); GYRO
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks