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@18:7f9c2b8541e1, 2017-10-18 (annotated)
- Committer:
- Muglug
- Date:
- Wed Oct 18 12:51:31 2017 +0000
- Revision:
- 18:7f9c2b8541e1
- Parent:
- 17:f98597cd2efc
- Child:
- 19:0a3ae902722e
Still Fixing Gustavo Shitty
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. |
Muglug | 18:7f9c2b8541e1 | 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" |
Muglug | 17:f98597cd2efc | 26 | |
Muglug | 17:f98597cd2efc | 27 | #include "XBeeLib.h" |
gusteibolt | 1:a6dc717fb060 | 28 | //----------------------------------------------------------------- |
gusteibolt | 0:73cd0cb02330 | 29 | |
gusteibolt | 1:a6dc717fb060 | 30 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 31 | // Declarations |
Muglug | 18:7f9c2b8541e1 | 32 | Timer time_stamp; //Timer µS time-stamp |
Muglug | 18:7f9c2b8541e1 | 33 | EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event |
gusteibolt | 3:26aeff25f610 | 34 | |
Muglug | 18:7f9c2b8541e1 | 35 | Serial PC(USBTX, USBRX); // PC Serial (Debug) |
Muglug | 18:7f9c2b8541e1 | 36 | // Serial XBeeee(PA_11, PA_12); // Xbee |
gusteibolt | 3:26aeff25f610 | 37 | |
Muglug | 18:7f9c2b8541e1 | 38 | // MPU9250 imu; // IMU MPU-9255 by Kris Winer |
gusteibolt | 1:a6dc717fb060 | 39 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 40 | |
gusteibolt | 1:a6dc717fb060 | 41 | //----------------------------------------------------------------- |
gusteibolt | 1:a6dc717fb060 | 42 | // Global Variables |
gusteibolt | 3:26aeff25f610 | 43 | // Your code here! |
gusteibolt | 1:a6dc717fb060 | 44 | //----------------------------------------------------------------- |
gusteibolt | 10:577e1fc4453e | 45 | /* |
gusteibolt | 1:a6dc717fb060 | 46 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 47 | void print_event(void const *argv, int i) { |
gusteibolt | 10:577e1fc4453e | 48 | pc.printf("%d ",i); |
gusteibolt | 8:ba93a973f967 | 49 | pc.printf((const char*)argv); |
gusteibolt | 10:577e1fc4453e | 50 | pc.printf("\r\n"); |
gusteibolt | 8:ba93a973f967 | 51 | } |
gusteibolt | 8:ba93a973f967 | 52 | //----------------------------------------------------------------- |
gusteibolt | 10:577e1fc4453e | 53 | */ |
gusteibolt | 8:ba93a973f967 | 54 | //----------------------------------------------------------------- |
Muglug | 18:7f9c2b8541e1 | 55 | /*void blink_event(DigitalOut pin){ |
gusteibolt | 10:577e1fc4453e | 56 | pin = !pin; |
gusteibolt | 8:ba93a973f967 | 57 | } |
gusteibolt | 8:ba93a973f967 | 58 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 59 | |
gusteibolt | 8:ba93a973f967 | 60 | //----------------------------------------------------------------- |
gusteibolt | 8:ba93a973f967 | 61 | void println_event(){ |
gusteibolt | 8:ba93a973f967 | 62 | pc.printf("Arroz, feijao e batata\r\n"); |
gusteibolt | 8:ba93a973f967 | 63 | } |
gusteibolt | 8:ba93a973f967 | 64 | //----------------------------------------------------------------- |
Muglug | 18:7f9c2b8541e1 | 65 | */ |
gusteibolt | 8:ba93a973f967 | 66 | //----------------------------------------------------------------- |
Muglug | 18:7f9c2b8541e1 | 67 | void Setup() |
Muglug | 18:7f9c2b8541e1 | 68 | { |
gusteibolt | 3:26aeff25f610 | 69 | // PC Serial (Debug) baudrate |
Muglug | 18:7f9c2b8541e1 | 70 | PC.baud(9600); |
Muglug | 18:7f9c2b8541e1 | 71 | PC.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
Muglug | 18:7f9c2b8541e1 | 72 | |
Muglug | 18:7f9c2b8541e1 | 73 | // XBeeee.baud(9600); |
Muglug | 18:7f9c2b8541e1 | 74 | |
gusteibolt | 3:26aeff25f610 | 75 | // Task queue |
Muglug | 18:7f9c2b8541e1 | 76 | // int task1_id = queue.call_every(1000, printf, "called every 1 seconds\n"); |
Muglug | 18:7f9c2b8541e1 | 77 | // int task2_id = queue.call_every(2500, printf, "called every 2.5 seconds\n"); |
Muglug | 18:7f9c2b8541e1 | 78 | // int task3_id = queue.call_every(3000, &print_event, (void *)"called every 3 seconds\n", (int) time_stamp.read()); |
Muglug | 18:7f9c2b8541e1 | 79 | // int task4_id = queue.call_every(50, blink_event, led1); |
Muglug | 18:7f9c2b8541e1 | 80 | // int task5_id = queue.call_every(500, println_event); |
Muglug | 18:7f9c2b8541e1 | 81 | // int task6_id = queue.call_every(500, readIMU); |
Muglug | 18:7f9c2b8541e1 | 82 | // int task7_id = queue.call_every(500, gayEvent); |
gusteibolt | 0:73cd0cb02330 | 83 | } |
gusteibolt | 1:a6dc717fb060 | 84 | //----------------------------------------------------------------- |
gusteibolt | 0:73cd0cb02330 | 85 | |
gusteibolt | 1:a6dc717fb060 | 86 | //----------------------------------------------------------------- |
Muglug | 18:7f9c2b8541e1 | 87 | /*void initMPU9250() |
Muglug | 18:7f9c2b8541e1 | 88 | { |
Muglug | 18:7f9c2b8541e1 | 89 | // Initialize MPU9250 device |
Muglug | 18:7f9c2b8541e1 | 90 | // wake up device |
Muglug | 18:7f9c2b8541e1 | 91 | imu.writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x00); // Clear sleep mode bit (6), enable all sensors |
Muglug | 18:7f9c2b8541e1 | 92 | }*/ |
Muglug | 18:7f9c2b8541e1 | 93 | |
Mister_Lopez | 4:56e903769e94 | 94 | //----------------------------------------------------------------- |
Mister_Lopez | 4:56e903769e94 | 95 | |
Muglug | 17:f98597cd2efc | 96 | using namespace XBeeLib; |
Muglug | 17:f98597cd2efc | 97 | |
Muglug | 18:7f9c2b8541e1 | 98 | /** Callback function, invoked at packet reception */ |
Muglug | 18:7f9c2b8541e1 | 99 | static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len) |
Muglug | 18:7f9c2b8541e1 | 100 | { |
Muglug | 18:7f9c2b8541e1 | 101 | for (int i = 0; i < len; i++) |
Muglug | 18:7f9c2b8541e1 | 102 | PC.printf("%c", data[i]); |
Muglug | 18:7f9c2b8541e1 | 103 | |
Muglug | 18:7f9c2b8541e1 | 104 | PC.printf("\r\n"); |
Muglug | 18:7f9c2b8541e1 | 105 | } |
Muglug | 18:7f9c2b8541e1 | 106 | |
Mister_Lopez | 4:56e903769e94 | 107 | //----------------------------------------------------------------- |
gusteibolt | 0:73cd0cb02330 | 108 | int main() |
gusteibolt | 0:73cd0cb02330 | 109 | { |
Muglug | 18:7f9c2b8541e1 | 110 | Setup(); // Initial Setups |
Muglug | 18:7f9c2b8541e1 | 111 | const uint8_t data[] = "Hello Master!"; |
Muglug | 18:7f9c2b8541e1 | 112 | const uint16_t data_len = sizeof data / sizeof data[0] - 1; |
Muglug | 18:7f9c2b8541e1 | 113 | |
Muglug | 18:7f9c2b8541e1 | 114 | XBeeZB XBee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 115200); |
Muglug | 18:7f9c2b8541e1 | 115 | XBee.init(); |
Mister_Lopez | 4:56e903769e94 | 116 | |
Muglug | 18:7f9c2b8541e1 | 117 | /* Register callbacks */ |
Muglug | 18:7f9c2b8541e1 | 118 | XBee.register_receive_cb(&receive_cb); |
Muglug | 18:7f9c2b8541e1 | 119 | |
Muglug | 18:7f9c2b8541e1 | 120 | |
Muglug | 18:7f9c2b8541e1 | 121 | // Reading the analog input (Microphone) |
Muglug | 18:7f9c2b8541e1 | 122 | // array = micro.read_u16(); |
Muglug | 18:7f9c2b8541e1 | 123 | |
gusteibolt | 10:577e1fc4453e | 124 | time_stamp.start(); // Start timer |
Muglug | 18:7f9c2b8541e1 | 125 | |
Muglug | 18:7f9c2b8541e1 | 126 | led1 = 1; |
gusteibolt | 0:73cd0cb02330 | 127 | while (true) { |
Muglug | 18:7f9c2b8541e1 | 128 | // queue.dispatch(); |
Muglug | 18:7f9c2b8541e1 | 129 | XBee.process_rx_frames(); |
Muglug | 18:7f9c2b8541e1 | 130 | |
Muglug | 18:7f9c2b8541e1 | 131 | TxStatus txStatus = XBee.send_data_to_coordinator(data, data_len); |
Muglug | 18:7f9c2b8541e1 | 132 | if (txStatus != TxStatusSuccess) { |
Muglug | 18:7f9c2b8541e1 | 133 | PC.printf("send_data_broadcast() failed with error %d\n", (int)txStatus); |
Muglug | 18:7f9c2b8541e1 | 134 | } |
gusteibolt | 0:73cd0cb02330 | 135 | } |
gusteibolt | 0:73cd0cb02330 | 136 | } |
Muglug | 18:7f9c2b8541e1 | 137 | //----------------------------------------------------------------- |