Chris Elsholz / Mbed 2 deprecated Quadrocopter

Dependencies:   mbed TextLCD

Fork of Quadrocopter by Marco Friedmann

messen.cpp

Committer:
MarcoF89
Date:
2017-08-02
Revision:
4:3eaf38e4809f

File content as of revision 4:3eaf38e4809f:

#include "mbed.h"
#include "stdio.h"



extern Serial pc(SERIAL_TX, SERIAL_RX);
extern SPI spi(PE_6,PE_5,PE_2);         //mosi,miso,sclk
extern DigitalOut ncs(PE_4);            //ssel

/**********/
/*Messen Z*/
/**********/

int aktuell_gyro_z()
{
    int16_t z_high, z_low, z_high_low;   
    float messwert[7];
    char j, i;
    
    ncs = 0;
    spi.write(0xc7);                    //Z_OUT_H
    z_high = spi.write(0x0);
    ncs = 1;
    wait_us(1);
       
    ncs = 0;
    spi.write(0xc8);                    //Z_OUT_L
    z_low = spi.write(0x0);
    ncs = 1;
    wait_us(1);  
          
    z_high_low = z_low | z_high << 8;   //Low und High Byte zusammenfügen
    return z_high_low;                  
}


/**********************/
/*Initialisieren**Gyro*/
/**********************/
int initialisierung_gyro()
{
    ncs = 0;
    spi.write(0x6B);     // Register 107
    spi.write(0x80);     //Reset // Standby off
    ncs = 1;               
    wait_ms(1000); 
    
        
    ncs=0;
    spi.write(0x1A);     //CONFIG  write // DLPF_CFG // Register 26
    spi.write(0x06);     //Bandwidth: 250Hz// Delay: 0.97ms// Fs: 8kHz
    ncs = 1;                
    wait_ms(1);
    
    
    ncs=0;
    spi.write(0x1B);     //Gyro_CONFIG  write  
    spi.write(0x18);     //Max. Skalenwert//00=+250dps;08=+500dps;10=+1000dps;18=+2000dps
    ncs = 1;                
    wait_ms(1); 

    ncs = 0;
    spi.write(0x17);     // Register 23
    spi.write(0x00);     // Offset High Byte
    ncs = 1;               
    wait_ms(1); 
    
    ncs = 0;
    spi.write(0x18);     // Register 24
    spi.write(0x17);     // Offset Low Byte
    ncs = 1;               
    wait_ms(1000); 
}