Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Quadrocopter by
Diff: messen.cpp
- Revision:
- 4:3eaf38e4809f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/messen.cpp Wed Aug 02 11:23:54 2017 +0000 @@ -0,0 +1,74 @@ +#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); +} +