Skip to main content
FEnis.1
Associate
March 23, 2021
Question

Hey everybody, is it possible to convert code for the STM32F103C8T6 so it works on the NUCLEO F446RE? Or can I just use the same code and use in STM32CubeMX?

  • March 23, 2021
  • 4 replies
  • 5310 views

I'm trying to do a Project with the MAX30102. I can read out the raw data of the sensor but I am unable to understand the algorithm to calculate the Heartrate and SPO2 out of the raw data. The only examples I can find are for Arduino Boards but that's not useful at all. I found this one Example for the STM32F103C8T6 and I was hoping I could just convert it for my board so at least I got something that works...

Here is the link for the example:

https://www.programmersought.com/article/90827305857/

I have the code in the attachment.

I hope somebody can help me.

best regards,

F.Enis

4 replies

KevinA
Senior
March 23, 2021

Nice find but I see two problems:

  1. You didn't copy max30102.h (no big)
  2. This project was created with MDK-ARM V5 as the tool chain.

How this will impact you if you don't use the KEIL compiler tool chain I have no idea

You should just use F466RE in Cube and try it! If you don't have the MAX30102 yet Adafruit has one and Mouser many - Mouser has the MAX Feather shield with the device.

;)

FYI MAX has a repository on mbed with this device and mbed has the Nuleco-F446RE supported.

FEnis.1
FEnis.1Author
Associate
March 24, 2021

Thanks for the reply.

The problem is that I tried it but can't get anything to work.

I found this website: https://morf.lv/implementing-pulse-oximeter-using-max30100

The author is doing the processing for the MAX30100 but the same principles should apply for the MAX30102. The problem is that I have problems converting the code he used for my Project. I am not that good at programming to be honest:grinning_face_with_sweat:.

I have my main file in the attachment. Maybe somebody could help me a little because I'm already really frustrated:o)

best regards,

F.Enis

Associate II
September 29, 2024

hey did u get ur output working?

 

Tesla DeLorean
Guru
September 29, 2024

From 3 years ago, try it yourself..

Read the data sheet. F1 and F4 are architecturally different. The HAL provides for a rough equivalence, and should be relatively fungible.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Associate III
December 13, 2024

Hi, 

When reading the FIFO buffer though I2C read command, we typically retrieve 6 bytes of data: 3 bytes for the Red LED value and 3 bytes for the IR LED value.

The question is: how is the data arranged in the 6-byte buffer?

Is it organized such that bytes 0 to 2 represent the Red LED data, and bytes 3 to 5 represent the IR LED data?

I'm a bit confused about how the data is arranged when reading multiple bytes. Could you clarify the orientation of the data in the buffer?

 

chai2145_0-1734075169037.png

uint8_t maxim_max30102_read_fifo(uint32_t *pun_red_led, uint32_t *pun_ir_led)
/**
* \brief Read a set of samples from the MAX30102 FIFO register
* \par Details
* This function reads a set of samples from the MAX30102 FIFO register
*
* \param[out] *pun_red_led - pointer that stores the red LED reading data
* \param[out] *pun_ir_led - pointer that stores the IR LED reading data
*
* \retval true on success
*/
{
 uint32_t un_temp;
 unsigned char uch_temp;
 *pun_red_led=0;
 *pun_ir_led=0;
 unsigned char ach_i2c_data[6];
 
 //read and clear status register
 maxim_max30102_read_reg(REG_INTR_STATUS_1, &uch_temp);
 maxim_max30102_read_reg(REG_INTR_STATUS_2, &uch_temp);
 
 ach_i2c_data[0]=REG_FIFO_DATA;

	HAL_I2C_GetState(&hi2c1);
	//DMP library driver slave_addr address needs to be shifted 1 bit to the left when sending, the last bit or upper read/write bit
	HAL_I2C_Mem_Read(&hi2c1, I2C_READ_ADDR, REG_FIFO_DATA, 1, ach_i2c_data, 6, HAL_MAX_DELAY);
	
	
 un_temp=(unsigned char) ach_i2c_data[0];
 un_temp<<=16;
 *pun_red_led+=un_temp;
 un_temp=(unsigned char) ach_i2c_data[1];
 un_temp<<=8;
 *pun_red_led+=un_temp;
 un_temp=(unsigned char) ach_i2c_data[2];
 *pun_red_led+=un_temp;
 
 un_temp=(unsigned char) ach_i2c_data[3];
 un_temp<<=16;
 *pun_ir_led+=un_temp;
 un_temp=(unsigned char) ach_i2c_data[4];
 un_temp<<=8;
 *pun_ir_led+=un_temp;
 un_temp=(unsigned char) ach_i2c_data[5];
 *pun_ir_led+=un_temp;
 *pun_red_led&=0x03FFFF; //Mask MSB [23:18]
 *pun_ir_led&=0x03FFFF; //Mask MSB [23:18]
 
 
 return 1;
}