How to code an ECG (Electrocardiogram) click 3 using STM32F446RE?

Hello Sir

You are right, the output are not correct, the same values keep repeating. Find below the output values on the terminal .

What can we do now ?
Here is the link to the serialPortPlotter setup and everything is about it.

Thanks a million . Will be expecting you tomorrow.

I suppose your shield is still in default “jumpers” configuration PWR SEL = 3v3 and CLK SEL = INT and also you powed it with 3.3V, right?

Also I did a mistake so replace

    printf("ECG: %zu\n", ecgData);
    ecg3click.getRTOR(&outHR, &outRR );
    printf("HeardBeat: %zu, R: %zu\n", ecgData, outRR);

with this

    ecg3click.getRTOR(&outHR, &outRR );
    printf("HeardBeat: %zu, R: %zu, ECG: %zu \r\n",outHR, outRR, ecgData);

The plotter seems to be simple - CieNTi/serial_port_plotter: Displays real time data from serial port (

Each message you send must start with ‘$’ and end with ‘;’ (semi-colon) and the integers inside need to be space-separated.

/* Example: Plot two values */
printf ("$%d %d;", data1, data2);

For the plotter is probably necessary to increase (from default 9600 to 115200 or more) the baud rate of the serial.
That can be done via mbed_app.json file

       "target_overrides": {
           "*": {
            "platform.stdio-baud-rate": 115200

or you can add

Serial pc(SERIAL_TX, SERIAL_RX, 115200);

BR, Jan

Hello Sir
Thank you , the plotter is working now .
currently am using arduino uno shield on top of the STM32F446E, so talking of the connection don’t really understand the way their link. I have tried to change the spi Bus connection , but still saying either the board has crushed or giving those big values like what I sent you previously.

Talking of the changes , I have done it but this time round the output is as follow HeardBeat: 0, R: 65528, ECG: 262143, and continuously repeat same values .

So I believe the issue is with the connection , I was wondering , what does D4, D5, 43 represent in the spiBus() function ? I have checked the library to understand but could not find it.

Thank you .

SPI - API references and tutorials | Mbed OS 6 Documentation
How you can see Constructor of SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC) required pins as input parameters. So you need to place pin names of some SPI interface.
In this case D4, D5 and D6 are pin masks for NUCLEO-F446RE | Mbed according to Arduino header standart.

// MOSI, MISO, SCLK SSEL (we not used SSEL here because the library control it)
SPI spiBus(D4, D5, D6);

And yes, it seems like you have bad pins used.
Is it this one arduino_uno_click_shield_schematic_a (
If yes, then place the ECG 3 click to second slot (D13 from first slot is used for LED1 ) and you need to change it from this

SPI spiBus(D4, D5, D6);
ECG_3_click ecg3click(spiBus, D7);

to this

SPI spiBus(D11, D12, D9);
ECG_3_click ecg3click(spiBus, D10);

BR, Jan

Hello Sir
thank you so much, well understood now . Yes that is the shield I use, but still does not work, it is saying the board has crushed so meaning the PINS are wrong. I have also tried to change it as follow
SPI spiBus(D11, D12, D13);
ECG_3_click ecg3click(spiBus, D9);
base on the explanation from link you sent but for this one, it’s generating same constant values like before ,which means still wrong .

is there anything we can do again ?

Ah, I again made a mistake, I looked to wrong line on shield…

  • Simplest is take out the shield and connect the ECG 3 click directly by wires.
  • If you still want to use the shield, then you must take soldering iron tool, turn the Nucleo board and remove SB21 (Solder Bridge) on the backside. You will lose control of LED 1(Mbed’s mask, on the board is marked as LD2, the green one) but that allow you use that pin for SPI1.

That is right, only D9 can be changed to D10, according what a position on shield you will choose.

BR, Jan

Good morning Sir
Thank you so much.
Ok, I have done the connection on a breadboard for now. But still having wrong values with the ecgData and the outRR. Talking of the heartbeat rate, it is varying between 60-72 bpm .
But was wondering about my connection , I have only connected the 6 pins on the left of the ECG 3 click (from GND to CS) to the STM32F446E , I have not touched the right side. Is it the right connection ?

In addition, I have noticed that the output generated by the terminal or console stops generating after 4 or 5 minutes . Why is it like that please ? is it not supposed to continuously generate till I decide to disconnect my board ?

Thank you .


How you can see in the schematic - ecg-3-click-schematic-v102 (, most of pins, on the right side, are not connected. And the rest…

  • CLK is required only when you want use it with an external clock signal - CLK SEL = EXT
  • 5V only if you want to power it with 5 volts - PWR SEL = 5V
  • INT can be used as trigger for your board via interrupt handling, but it is not necessary

ECG 3 click use MicroBus standard, that is why here is more pins than it is used. It is compatible with all Microe products.

You need to determine what is the source of this issue. PC side or Nucleo.

  • When you close and reopen the terminal app, will it work again?
  • When the output stops, what do the green led?

Ok, and the heartbeat rate corresponding with the reality?

BR, Jan

Hello Sir

Ok, so what is the issue with the other reading ? The ecgData and the RR ? If the connections are correct , what can it be the issue ?
Yes, the heart beat rate corresponds to the reality.

  • I might say it’s the NUCLEO , because before it stops generating values , the RGB LED on the board will be blinking as if a new .bin file is being sent to the board .
    _ Yes please , It works , I have to close and OPEN the software again before it works
    _ The green LED continuing blinking with an interval of 3 seconds, but this time round even throughout the intensity is very low .

What does it mean if the intensity is very low ?

Thanks a lot for your help.

That it is cool the heart beat rate is OK . With the rest it will be hard, maybe tomorrow I will try some changes in library, I will let you know. But it will be probably about configuration, I think.
You can look into the init method in the library and if you know what you want then you can to set it - page 26+ of MAX30003 - datasheet

That blinking of RGB led, on the ST-link, mean St-link connection initialization. That seems like…

  • power source issue on USB port
  • broken USB cable
  • But probably… check this topic

You need to change the value in wait(3) (3sec) function. Normally it run much faster, maybe 100ms or something like that.

BR, Jan

Good morning Sir
I’m grateful for everything , you are such a great help. Thanks a million

I have checked the datasheet and the library , everything was perfectly done, registers were well assigned . But I have realized from the datasheet that ECG burst and the ECG (FIFO memory) could read ECG voltage sample data , so I decided to read the ECG values from the ECG burst register , I have then changed the address 0x21 to 0x20 . So the output this time is not that bad , it seems to be okay, but I want to confirm it first. And want to do more experiment to see if it will continue working perfectly.

But please Sir, you can still try what you wanted :slight_smile: , I want to be sure , I have not made any mistake.

Ok Sir , will work on it and get back to you please. Thank you so much

Oh okay, I was referring to the brightness of the LED. it is very low …

Ah, ok I misunderstood. I do not know the reason for lower brightness. Maybe it is in the context of resets of the board.

BR, Jan

Good day Sir

Please I have been testing the code as I promised, but still it is not perfectly giving results was expected. When I plot the generated values, it does not generate a perfect or like shape of heart beats. I tried my best to adjust it throughout the week but still getting same results. So was wondering if there is still something you can try to help ?

Thank you Sir.


trully I do not know, I do not have this hardware in my hand so I can not test it.
From my point of view, when you receive some data, then the communication is OK and it is only about settings in registers, maybe about frequency of reading - for example.

You can try to read only getRTOR and then only getECG, if there is a difference.

BR, Jan

Good day Sir.
Sorry for this again.
Like the reading for Heart beats rate is correct, as well as the R-R interval . Only the ECG reading is not correct. And that is what I really want to displayed. It gives this huge number 262042.

Thank you Sir, I did not see much on getRTOR and getECG. But I have read the plotECG () , And I have written an ECG function accordingly as well to see if it will generate good result since the condition in the function is if (ecgData>50000) but still not getting any good result , kindly check my code below to see if I have made some mistakes

uint32_t ecgData = 0;
uint16_t outHR = 0, outRR = 0;
char text[ 50 ];
uint32_t measTimeCnt;

void plotECG()
if (ecgData > 50000)
//Convert long unsigned to String
sprintf(text, “%lu” ,ecgData );
sprintf(text, “%lu” ,measTimeCnt );
printf("$ECG: %zu;",text);

    if (measTimeCnt == 0xFFFFFFFF)
        measTimeCnt = 0;


int main()
DigitalOut led(LED1, 1);

SPI spiBus(D11, D12, D13);
ECG_3_click ecg3click(spiBus, D10);

printf("Start of loop\n");

    led = !led;


Thank you for your help

Hello SIR
Please can you help me with a suitable library to program my GSM-GPS click sim808 which can send SMS and get exact location ?


I already made an answer

BR, Jan