Test program for a Max30102 heartrate sensor on a STM32L476RG specific board ENSMM
Dependencies: mbed
These two pictures show how to connect the Mheuve Sensor to the ST-Link debugger (don't forget to disable ST-link jumpers and JP5 on the board! ):
These two pictures show how to connect the Mheuve Sensor TX RX to the ST-Link debugger (don't forget to cross TX and RX, it means Mheuve sensor TX on ST-Link RX and ST-Link TX on Mheuve sensor RX ):
The Mheuve sensor board needs to be powered by an external battery.
The result appears on the terminal, speed config is 115200 bds.
Revision 5:648aa1e83d65, committed 2021-01-27
- Comitter:
- jimbaud
- Date:
- Wed Jan 27 09:32:22 2021 +0000
- Parent:
- 4:5273ab1085ab
- Commit message:
- Test program for a Max30102 heartrate sensor on a STM32L476RG specific board ENSMM
Changed in this revision
--- a/MAX30102/MAX30102.cpp Thu May 19 22:04:06 2016 +0000 +++ b/MAX30102/MAX30102.cpp Wed Jan 27 09:32:22 2021 +0000 @@ -59,11 +59,9 @@ #include "mbed.h" #include "MAX30102.h" -#ifdef TARGET_MAX32600MBED -I2C i2c(I2C1_SDA, I2C1_SCL); -#else -I2C i2c(I2C_SDA, I2C_SCL); -#endif + +I2C i2c(PC_1, PC_0); + bool maxim_max30102_write_reg(uint8_t uch_addr, uint8_t uch_data) /**
--- a/main.cpp Thu May 19 22:04:06 2016 +0000 +++ b/main.cpp Wed Jan 27 09:32:22 2021 +0000 @@ -1,76 +1,3 @@ -/** \file main.cpp ****************************************************** -* -* Project: MAXREFDES117# -* Filename: main.cpp -* Description: This module contains the Main application for the MAXREFDES117 example program. -* -* -* -------------------------------------------------------------------- -* -* This code follows the following naming conventions: -* -* char ch_pmod_value -* char (array) s_pmod_s_string[16] -* float f_pmod_value -* int32_t n_pmod_value -* int32_t (array) an_pmod_value[16] -* int16_t w_pmod_value -* int16_t (array) aw_pmod_value[16] -* uint16_t uw_pmod_value -* uint16_t (array) auw_pmod_value[16] -* uint8_t uch_pmod_value -* uint8_t (array) auch_pmod_buffer[16] -* uint32_t un_pmod_value -* int32_t * pn_pmod_value -* -* ------------------------------------------------------------------------- */ -/******************************************************************************* -* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a -* copy of this software and associated documentation files (the "Software"), -* to deal in the Software without restriction, including without limitation -* the rights to use, copy, modify, merge, publish, distribute, sublicense, -* and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES -* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -* OTHER DEALINGS IN THE SOFTWARE. -* -* Except as contained in this notice, the name of Maxim Integrated -* Products, Inc. shall not be used except as stated in the Maxim Integrated -* Products, Inc. Branding Policy. -* -* The mere transfer of this software does not imply any licenses -* of trade secrets, proprietary technology, copyrights, patents, -* trademarks, maskwork rights, or any other form of intellectual -* property whatsoever. Maxim Integrated Products, Inc. retains all -* ownership rights. -******************************************************************************* -*/ -/*!\mainpage Main Page -* -* \section intro_sec Introduction -* -* This is the code documentation for the MAXREFDES117# subsystem reference design. -* -* The Files page contains the File List page and the Globals page. -* -* The Globals page contains the Functions, Variables, and Macros sub-pages. -* -* \image html MAXREFDES117_Block_Diagram.png "MAXREFDES117# System Block Diagram" -* -* \image html MAXREFDES117_firmware_Flowchart.png "MAXREFDES117# Firmware Flowchart" -* -*/ #include "mbed.h" #include "algorithm.h" #include "MAX30102.h" @@ -86,18 +13,12 @@ int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid uint8_t uch_dummy; -Serial pc(USBTX, USBRX); //initializes the serial port -#ifdef TARGET_KL25Z -PwmOut led(PTB18); //initializes the pwm output that connects to the on board LED -DigitalIn INT(PTD1); //pin PTD1 connects to the interrupt output pin of the MAX30102 -#endif -#ifdef TARGET_K64F -DigitalIn INT(PTD1); //pin PTD1 connects to the interrupt output pin of the MAX30102 -#endif -#ifdef TARGET_MAX32600MBED -PwmOut led(LED_RED); //initializes the pwm output that connects to the on board LED -DigitalIn INT(P2_0); //pin P20 connects to the interrupt output pin of the MAX30102 -#endif +Serial pc(PB_10, PB_11); //initializes the serial port + +DigitalOut led(PC_4); //initializes the pwm output that connects to the on board LED +DigitalIn INT(PC_13); //pin PTD1 connects to the interrupt output pin of the MAX30102 + +DigitalOut VEN(PC_2); // the setup routine runs once when you press reset: int main() { @@ -111,22 +32,14 @@ pc.baud(115200); pc.format(8,SerialBase::None,1); wait(1); + led = 1; //read and clear status register maxim_max30102_read_reg(0,&uch_dummy); - - //wait until the user presses a key - while(pc.readable()==0) - { - pc.printf("\x1B[2J"); //clear terminal program screen - pc.printf("Press any key to start conversion\n\r"); - wait(1); - } - uch_dummy=getchar(); - + + VEN = 1; maxim_max30102_init(); //initializes the MAX30102 - - + n_brightness=0; un_min=0x3FFFF; un_max=0; @@ -136,7 +49,7 @@ //read the first 500 samples, and determine the signal range for(i=0;i<n_ir_buffer_length;i++) { - while(INT.read()==1); //wait until the interrupt pin asserts + //while(INT.read()==1); //wait until the interrupt pin asserts maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i)); //read from MAX30102 FIFO @@ -150,7 +63,7 @@ pc.printf("%i\n\r", aun_ir_buffer[i]); } un_prev_data=aun_red_buffer[i]; - + //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples) maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); @@ -200,9 +113,9 @@ if(n_brightness>MAX_BRIGHTNESS) n_brightness=MAX_BRIGHTNESS; } -#if defined(TARGET_KL25Z) || defined(TARGET_MAX32600MBED) - led.write(1-(float)n_brightness/256); -#endif + + led = 1; + //send samples and calculation result to terminal program through UART pc.printf("red="); pc.printf("%i", aun_red_buffer[i]); @@ -212,6 +125,7 @@ pc.printf("HRvalid=%i, ", ch_hr_valid); pc.printf("SpO2=%i, ", n_sp02); pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid); + // wait(1); } maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid); }
--- a/mbed.bld Thu May 19 22:04:06 2016 +0000 +++ b/mbed.bld Wed Jan 27 09:32:22 2021 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file