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.
Dependencies: MPU9250_SPI
Fork of WearableDevice_Nucleo by
main.cpp@10:577e1fc4453e, 2017-10-14 (annotated)
- Committer:
- gusteibolt
- Date:
- Sat Oct 14 23:37:02 2017 +0000
- Revision:
- 10:577e1fc4453e
- Parent:
- 8:ba93a973f967
- Child:
- 11:f19020fa18f1
- Child:
- 12:c88478dfc622
Working on eventqueue callback functions..
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gusteibolt | 1:a6dc717fb060 | 1 | /* |
gusteibolt | 1:a6dc717fb060 | 2 | * Los Putacos |
gusteibolt | 1:a6dc717fb060 | 3 | * Copyright (C) 2017, All rights reserved. |
gusteibolt | 1:a6dc717fb060 | 4 | * ________________________________________ |
gusteibolt | 1:a6dc717fb060 | 5 | * |
gusteibolt | 1:a6dc717fb060 | 6 | * Created by: Gustavo Campana, Michael Schmidt, Miguel Lopez |
gusteibolt | 1:a6dc717fb060 | 7 | * Date: 11-Oct-2017 |
gusteibolt | 1:a6dc717fb060 | 8 | * Version: V0.1 |
gusteibolt | 1:a6dc717fb060 | 9 | */ |
gusteibolt | 1:a6dc717fb060 | 10 | |
gusteibolt | 1:a6dc717fb060 | 11 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 12 | // Board: NUCLEO - F401RE |
gusteibolt | 1:a6dc717fb060 | 13 | // Version: MR1136 rev C |
gusteibolt | 1:a6dc717fb060 | 14 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 15 | |
gusteibolt | 1:a6dc717fb060 | 16 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 17 | // Includes |
gusteibolt | 0:73cd0cb02330 | 18 | #include "mbed.h" |
gusteibolt | 0:73cd0cb02330 | 19 | #include "rtos.h" |
gusteibolt | 3:26aeff25f610 | 20 | #include "mbed_events.h" |
gusteibolt | 3:26aeff25f610 | 21 | |
gusteibolt | 3:26aeff25f610 | 22 | #include "configuration.h" |
gusteibolt | 10:577e1fc4453e | 23 | #include "event.h" |
gusteibolt | 7:ebaaff27840b | 24 | #include "pin.h" |
gusteibolt | 3:26aeff25f610 | 25 | #include "MPU9250.h" |
gusteibolt | 1:a6dc717fb060 | 26 | //----------------------------------------------------------------- |
gusteibolt | 0:73cd0cb02330 | 27 | |
gusteibolt | 1:a6dc717fb060 | 28 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 29 | // Declarations |
gusteibolt | 10:577e1fc4453e | 30 | Timer time_stamp; //Timer µS time-stamp |
gusteibolt | 3:26aeff25f610 | 31 | |
gusteibolt | 3:26aeff25f610 | 32 | EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event |
gusteibolt | 3:26aeff25f610 | 33 | |
gusteibolt | 3:26aeff25f610 | 34 | Serial pc(USBTX, USBRX); // PC Serial (Debug) |
gusteibolt | 10:577e1fc4453e | 35 | Serial xbee(PA_2, PA_3); // Xbee |
gusteibolt | 3:26aeff25f610 | 36 | |
gusteibolt | 10:577e1fc4453e | 37 | MPU9250 imu; // IMU MPU-9255 by Kris Winer |
gusteibolt | 1:a6dc717fb060 | 38 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 39 | |
gusteibolt | 1:a6dc717fb060 | 40 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 41 | // Global Variables |
gusteibolt | 3:26aeff25f610 | 42 | // Your code here! |
gusteibolt | 1:a6dc717fb060 | 43 | //----------------------------------------------------------------- |
gusteibolt | 10:577e1fc4453e | 44 | /* |
gusteibolt | 1:a6dc717fb060 | 45 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 46 | void print_event(void const *argv, int i) { |
gusteibolt | 10:577e1fc4453e | 47 | pc.printf("%d ",i); |
gusteibolt | 8:ba93a973f967 | 48 | pc.printf((const char*)argv); |
gusteibolt | 10:577e1fc4453e | 49 | pc.printf("\r\n"); |
gusteibolt | 8:ba93a973f967 | 50 | } |
gusteibolt | 8:ba93a973f967 | 51 | //----------------------------------------------------------------- |
gusteibolt | 10:577e1fc4453e | 52 | */ |
gusteibolt | 8:ba93a973f967 | 53 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 54 | void blink_event(DigitalOut pin){ |
gusteibolt | 10:577e1fc4453e | 55 | pin = !pin; |
gusteibolt | 8:ba93a973f967 | 56 | } |
gusteibolt | 8:ba93a973f967 | 57 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 58 | |
gusteibolt | 8:ba93a973f967 | 59 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 60 | void println_event(){ |
gusteibolt | 8:ba93a973f967 | 61 | pc.printf("Arroz, feijao e batata\r\n"); |
gusteibolt | 8:ba93a973f967 | 62 | } |
gusteibolt | 8:ba93a973f967 | 63 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 64 | |
gusteibolt | 8:ba93a973f967 | 65 | //----------------------------------------------------------------- |
gusteibolt | 7:ebaaff27840b | 66 | void setup(){ |
gusteibolt | 3:26aeff25f610 | 67 | |
gusteibolt | 3:26aeff25f610 | 68 | // PC Serial (Debug) baudrate |
gusteibolt | 3:26aeff25f610 | 69 | pc.baud(9600); |
gusteibolt | 3:26aeff25f610 | 70 | pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
gusteibolt | 3:26aeff25f610 | 71 | |
gusteibolt | 3:26aeff25f610 | 72 | // Task queue |
gusteibolt | 3:26aeff25f610 | 73 | int task1_id = queue.call_every(1000, printf, "called every 1 seconds\n"); |
gusteibolt | 3:26aeff25f610 | 74 | int task2_id = queue.call_every(2500, printf, "called every 2.5 seconds\n"); |
gusteibolt | 10:577e1fc4453e | 75 | //int task3_id = queue.call_every(3000, &print_event, (void *)"called every 3 seconds\n", (int) time_stamp.read()); |
gusteibolt | 10:577e1fc4453e | 76 | //int task4_id = queue.call_every(50, blink_event, led1); |
gusteibolt | 8:ba93a973f967 | 77 | int task5_id = queue.call_every(500, println_event); |
gusteibolt | 10:577e1fc4453e | 78 | int task6_id = queue.call_every(500, readIMU); |
gusteibolt | 0:73cd0cb02330 | 79 | } |
gusteibolt | 1:a6dc717fb060 | 80 | //----------------------------------------------------------------- |
gusteibolt | 0:73cd0cb02330 | 81 | |
gusteibolt | 1:a6dc717fb060 | 82 | //----------------------------------------------------------------- |
Mister_Lopez | 4:56e903769e94 | 83 | void initMPU9250() |
Mister_Lopez | 4:56e903769e94 | 84 | { |
Mister_Lopez | 4:56e903769e94 | 85 | // Initialize MPU9250 device |
Mister_Lopez | 4:56e903769e94 | 86 | // wake up device |
gusteibolt | 10:577e1fc4453e | 87 | imu.writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Clear sleep mode bit (6), enable all sensors |
Mister_Lopez | 4:56e903769e94 | 88 | } |
Mister_Lopez | 4:56e903769e94 | 89 | |
Mister_Lopez | 4:56e903769e94 | 90 | //----------------------------------------------------------------- |
Mister_Lopez | 4:56e903769e94 | 91 | |
Mister_Lopez | 4:56e903769e94 | 92 | //----------------------------------------------------------------- |
gusteibolt | 0:73cd0cb02330 | 93 | int main() |
gusteibolt | 0:73cd0cb02330 | 94 | { |
gusteibolt | 7:ebaaff27840b | 95 | setup(); // Initial setups |
gusteibolt | 3:26aeff25f610 | 96 | |
Mister_Lopez | 4:56e903769e94 | 97 | |
Mister_Lopez | 4:56e903769e94 | 98 | //Reading the analog input (Microphone) array = micro.read_u16(); |
Mister_Lopez | 4:56e903769e94 | 99 | |
gusteibolt | 10:577e1fc4453e | 100 | time_stamp.start(); // Start timer |
Mister_Lopez | 4:56e903769e94 | 101 | |
gusteibolt | 0:73cd0cb02330 | 102 | while (true) { |
gusteibolt | 3:26aeff25f610 | 103 | queue.dispatch(); |
gusteibolt | 0:73cd0cb02330 | 104 | } |
gusteibolt | 0:73cd0cb02330 | 105 | } |
gusteibolt | 1:a6dc717fb060 | 106 | //----------------------------------------------------------------- |