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: max32630fthr USBDevice
main.cpp@10:aec2b8ba06a0, 2020-08-14 (annotated)
- Committer:
- tlyp
- Date:
- Fri Aug 14 19:18:42 2020 +0000
- Revision:
- 10:aec2b8ba06a0
- Parent:
- 9:02c5adb483c8
- Child:
- 11:72363a906638
Basic Reciever w/ ID and Type
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phonemacro | 9:02c5adb483c8 | 1 | /******************************************************************************* |
phonemacro | 9:02c5adb483c8 | 2 | * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. |
phonemacro | 9:02c5adb483c8 | 3 | * |
phonemacro | 9:02c5adb483c8 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
phonemacro | 9:02c5adb483c8 | 5 | * copy of this software and associated documentation files (the "Software"), |
phonemacro | 9:02c5adb483c8 | 6 | * to deal in the Software without restriction, including without limitation |
phonemacro | 9:02c5adb483c8 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
phonemacro | 9:02c5adb483c8 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
phonemacro | 9:02c5adb483c8 | 9 | * Software is furnished to do so, subject to the following conditions: |
phonemacro | 9:02c5adb483c8 | 10 | * |
phonemacro | 9:02c5adb483c8 | 11 | * The above copyright notice and this permission notice shall be included |
phonemacro | 9:02c5adb483c8 | 12 | * in all copies or substantial portions of the Software. |
phonemacro | 9:02c5adb483c8 | 13 | * |
phonemacro | 9:02c5adb483c8 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
phonemacro | 9:02c5adb483c8 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
phonemacro | 9:02c5adb483c8 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
phonemacro | 9:02c5adb483c8 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
phonemacro | 9:02c5adb483c8 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
phonemacro | 9:02c5adb483c8 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
phonemacro | 9:02c5adb483c8 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
phonemacro | 9:02c5adb483c8 | 21 | * |
phonemacro | 9:02c5adb483c8 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
phonemacro | 9:02c5adb483c8 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
phonemacro | 9:02c5adb483c8 | 24 | * Products, Inc. Branding Policy. |
phonemacro | 9:02c5adb483c8 | 25 | * |
phonemacro | 9:02c5adb483c8 | 26 | * The mere transfer of this software does not imply any licenses |
phonemacro | 9:02c5adb483c8 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
phonemacro | 9:02c5adb483c8 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
phonemacro | 9:02c5adb483c8 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
phonemacro | 9:02c5adb483c8 | 30 | * ownership rights. |
phonemacro | 9:02c5adb483c8 | 31 | ******************************************************************************* |
phonemacro | 9:02c5adb483c8 | 32 | */ |
switches | 0:60a522ae2e35 | 33 | #include "mbed.h" |
switches | 2:57500e991166 | 34 | #include "max32630fthr.h" |
switches | 1:6923b075c8d7 | 35 | #include "USBSerial.h" |
tlyp | 10:aec2b8ba06a0 | 36 | #include "MAX30208.h" |
tlyp | 10:aec2b8ba06a0 | 37 | #include "ForwardErrCorr.h" |
switches | 0:60a522ae2e35 | 38 | |
switches | 6:684c51f32c1d | 39 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
switches | 0:60a522ae2e35 | 40 | |
switches | 1:6923b075c8d7 | 41 | // Hardware serial port over DAPLink |
phonemacro | 9:02c5adb483c8 | 42 | Serial daplink(USBTX, USBRX); // Use USB debug probe for serial link |
phonemacro | 9:02c5adb483c8 | 43 | Serial uart(P2_1, P2_0); |
tlyp | 10:aec2b8ba06a0 | 44 | RawSerial uart2(P3_1,P3_0);//tx,rx |
tlyp | 10:aec2b8ba06a0 | 45 | |
tlyp | 10:aec2b8ba06a0 | 46 | I2C i2c(P3_4, P3_5); //sda,scl |
tlyp | 10:aec2b8ba06a0 | 47 | |
tlyp | 10:aec2b8ba06a0 | 48 | MAX30208 TempSensor(i2c, 0x50); //Constructor takes 7-bit slave adrs |
tlyp | 10:aec2b8ba06a0 | 49 | char TransTable[] = {0x1F,0x18,0x06,0x01}; |
tlyp | 10:aec2b8ba06a0 | 50 | Translator transRx(uart2, TransTable); |
switches | 1:6923b075c8d7 | 51 | |
switches | 3:601c11238ccb | 52 | // Virtual serial port over USB |
h_keyur | 8:d2b660bf5f94 | 53 | USBSerial microUSB; |
switches | 2:57500e991166 | 54 | DigitalOut rLED(LED1); |
tlyp | 10:aec2b8ba06a0 | 55 | DigitalOut gLED(LED2); |
switches | 2:57500e991166 | 56 | DigitalOut bLED(LED3); |
tlyp | 10:aec2b8ba06a0 | 57 | DigitalIn TakeData(P5_6); |
tlyp | 10:aec2b8ba06a0 | 58 | DigitalIn TakeData2(P5_5); |
tlyp | 10:aec2b8ba06a0 | 59 | DigitalIn sw1(SW1); |
tlyp | 10:aec2b8ba06a0 | 60 | |
tlyp | 10:aec2b8ba06a0 | 61 | void buildArray(int j, char *input,char *output){ |
tlyp | 10:aec2b8ba06a0 | 62 | int i = j+1; |
tlyp | 10:aec2b8ba06a0 | 63 | int k = 0; |
tlyp | 10:aec2b8ba06a0 | 64 | while(input[i] != 'c'){ |
tlyp | 10:aec2b8ba06a0 | 65 | output[k] = input[i]; |
tlyp | 10:aec2b8ba06a0 | 66 | i++; |
tlyp | 10:aec2b8ba06a0 | 67 | k++; |
tlyp | 10:aec2b8ba06a0 | 68 | } |
tlyp | 10:aec2b8ba06a0 | 69 | } |
tlyp | 10:aec2b8ba06a0 | 70 | char dataIn[50]; |
tlyp | 10:aec2b8ba06a0 | 71 | |
tlyp | 10:aec2b8ba06a0 | 72 | void SerialCallback(){ |
tlyp | 10:aec2b8ba06a0 | 73 | //Timer timer; |
tlyp | 10:aec2b8ba06a0 | 74 | //timer.start(); |
tlyp | 10:aec2b8ba06a0 | 75 | wait_ms(1); |
tlyp | 10:aec2b8ba06a0 | 76 | int i = strlen(dataIn); |
tlyp | 10:aec2b8ba06a0 | 77 | if (i >= 50){ |
tlyp | 10:aec2b8ba06a0 | 78 | i = 0; |
tlyp | 10:aec2b8ba06a0 | 79 | } |
tlyp | 10:aec2b8ba06a0 | 80 | while(uart2.readable()){ |
tlyp | 10:aec2b8ba06a0 | 81 | dataIn[i] = uart2.getc(); |
tlyp | 10:aec2b8ba06a0 | 82 | i++; |
tlyp | 10:aec2b8ba06a0 | 83 | } |
tlyp | 10:aec2b8ba06a0 | 84 | //wait_ms(10); |
tlyp | 10:aec2b8ba06a0 | 85 | } |
switches | 0:60a522ae2e35 | 86 | |
switches | 0:60a522ae2e35 | 87 | // main() runs in its own thread in the OS |
switches | 0:60a522ae2e35 | 88 | // (note the calls to Thread::wait below for delays) |
switches | 0:60a522ae2e35 | 89 | int main() |
switches | 0:60a522ae2e35 | 90 | { |
switches | 2:57500e991166 | 91 | rLED = LED_ON; |
switches | 2:57500e991166 | 92 | gLED = LED_ON; |
switches | 2:57500e991166 | 93 | bLED = LED_OFF; |
tlyp | 10:aec2b8ba06a0 | 94 | uart2.baud(9600); |
tlyp | 10:aec2b8ba06a0 | 95 | uart2.attach(&SerialCallback); |
switches | 2:57500e991166 | 96 | rLED = LED_OFF; |
tlyp | 10:aec2b8ba06a0 | 97 | char dataOut[50]; |
tlyp | 10:aec2b8ba06a0 | 98 | uint16_t output[10]; |
switches | 1:6923b075c8d7 | 99 | while(1) { |
tlyp | 10:aec2b8ba06a0 | 100 | if (strlen(dataIn) >= 12){ |
tlyp | 10:aec2b8ba06a0 | 101 | int j = 0; |
tlyp | 10:aec2b8ba06a0 | 102 | while(dataIn[j] != 'b' && j < 30){ |
tlyp | 10:aec2b8ba06a0 | 103 | j++; |
tlyp | 10:aec2b8ba06a0 | 104 | } |
tlyp | 10:aec2b8ba06a0 | 105 | if (dataIn[j] == 'b'){ |
tlyp | 10:aec2b8ba06a0 | 106 | microUSB.printf("\r\n\r\n\r\n\r\n"); |
tlyp | 10:aec2b8ba06a0 | 107 | buildArray(j,dataIn,dataOut); |
tlyp | 10:aec2b8ba06a0 | 108 | microUSB.printf("\r\n"); |
tlyp | 10:aec2b8ba06a0 | 109 | if (transRx.Reconstruct(dataOut,output) == 1){ |
tlyp | 10:aec2b8ba06a0 | 110 | microUSB.printf("Error reconstructing\r\n"); |
tlyp | 10:aec2b8ba06a0 | 111 | } |
tlyp | 10:aec2b8ba06a0 | 112 | |
tlyp | 10:aec2b8ba06a0 | 113 | //Print out the Device Type, ID, and Temperature |
tlyp | 10:aec2b8ba06a0 | 114 | microUSB.printf("Device Type: %c\r\n", dataIn[j+1]); |
tlyp | 10:aec2b8ba06a0 | 115 | microUSB.printf("Device ID: %c\r\n", dataIn[j+2]); |
tlyp | 10:aec2b8ba06a0 | 116 | |
tlyp | 10:aec2b8ba06a0 | 117 | //uint16_t temp1 = (output[0]<<8); |
tlyp | 10:aec2b8ba06a0 | 118 | //uint16_t delivery = (temp1 + output[1]); |
tlyp | 10:aec2b8ba06a0 | 119 | //float clesius = TempSensor.toCelsius(output[0]); |
tlyp | 10:aec2b8ba06a0 | 120 | //float fare = TempSensor.toFahrenheit(clesius); |
tlyp | 10:aec2b8ba06a0 | 121 | microUSB.printf("Data read %u\r\n",output[0]); |
tlyp | 10:aec2b8ba06a0 | 122 | for (int i = 0;i<sizeof(dataIn);i++){ |
tlyp | 10:aec2b8ba06a0 | 123 | dataIn[i] = 0; |
tlyp | 10:aec2b8ba06a0 | 124 | } |
tlyp | 10:aec2b8ba06a0 | 125 | } |
tlyp | 10:aec2b8ba06a0 | 126 | else{ |
tlyp | 10:aec2b8ba06a0 | 127 | for (int i = 0;i<sizeof(dataIn);i++){ |
tlyp | 10:aec2b8ba06a0 | 128 | dataIn[i] = 0; |
tlyp | 10:aec2b8ba06a0 | 129 | } |
tlyp | 10:aec2b8ba06a0 | 130 | } |
tlyp | 10:aec2b8ba06a0 | 131 | } |
switches | 0:60a522ae2e35 | 132 | } |
switches | 0:60a522ae2e35 | 133 | } |