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.
Revision 0:e1cf607d5c64, committed 2017-03-28
- Comitter:
- coola
- Date:
- Tue Mar 28 14:55:30 2017 +0000
- Commit message:
- Code_prof
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 28 14:55:30 2017 +0000 @@ -0,0 +1,103 @@ +#include "mbed.h" + +#define MPU_ADDR (0x68<<1) // MPU address +#define MPU_REG_PWR1 (0x68) +#define MPU_REG_TEMP (0x41) // Temperature Register +#define MPU_REG_ID (0x75) // Who am I Register + + +I2C i2c(I2C_SDA, I2C_SCL); // Add 10k pull-up + +DigitalOut myled(LED1); + +Serial pc(SERIAL_TX, SERIAL_RX); + +Timer t; + +char data_write[7]; +char data_read[51]; +char flag=0; + + +void get_data(); + +void soft_reset(); + +void read_registers(); + +void int1_flag() +{ + + flag=1; + + } + + +int main() +{ + int16_t temp=0; + float tempf; + int16_t aX; + int16_t aY; + int16_t aZ; + + int32_t debut=0; + int32_t fin=0; + char status; + + // pc.baud(115200); + // i2c.frequency(400000); + + // Hello + pc.printf("Hello world\r\n"); + + + // reset accelerometer registers + soft_reset(); + + // Switch on accelerometer + parameters : + + data_write[0] = MPU_REG_PWR1; + data_write[1] = 0; // exit sleep mode + status = i2c.write(MPU_ADDR, data_write, 2, 0); + /* pc.printf("statuswrite=%d\t",status); + if (status != 0) { // Error + while (1) { + myled = !myled; + wait(0.2); + } + } + */ + + // read_registers(); + wait(0.2); + + // Read Accelerometer ID + // Read ID register + data_write[0] = MPU_REG_ID; + i2c.write(MPU_ADDR, data_write, 1, 1); // no stop + i2c.read(MPU_ADDR, data_read, 1, 0); + // pc.printf("statusread=%d\n\r",status); + pc.printf("I am n°0x%x ",data_read[0]); + //Read Temperature + data_write[0] = MPU_REG_TEMP; + i2c.write(MPU_ADDR, data_write, 1, 1); + i2c.read(MPU_ADDR, data_read, 2, 0); + temp = (int16_t)((int16_t)data_read[0] << 8) | data_read[1]; + tempf=((float)temp)/340+36.53; + pc.printf("and the temperature is %f °C\n\r",tempf); + t.start(); + + while (1) { + + } + +} + + +void soft_reset() +{ + data_write[0] = MPU_REG_PWR1; + data_write[1] = 1<<7; + i2c.write(MPU_ADDR, data_write, 2, 0); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Mar 28 14:55:30 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb \ No newline at end of file