2019-06-02 03:46 AM
Dear Members,
How can I save FIFO ?
I have a psedo code :
for (i = 0; i < NUM_SAMPLES_TO_READ; i++) {
Read FIFO_DATA;
Save IR[15:8];
Read FIFO_DATA;
Save IR[7:0];
Read FIFO_DATA;
Save R[15:8];
Read FIFO_DATA;
Save R[7:0];
}
STOP;
my code :
for(i=0;i<=number_sample;i++)
{
printf("The output from MAX30100, from 0x09 register (FIFO DATA) : %u \r\n", buffer_rx[i]);
}
what should I add there ?
thanks
2019-06-02 04:00 AM
correct me ?
HAL_I2C_Master_Receive(&hi2c2, 0xAF, buffer_rx ,number_sample, 100); //receive 4 bytes from MAX30100
for(i=0;i<=number_sample;i++)
{
FIFO_IR_samples[i] = buffer_rx[ ( i << 2 ) ];
FIFO_IR_samples[i] <<= 8U;
FIFO_IR_samples[i] |= buffer_rx[ ( i << 2 ) + 1 ];
printf("Output MAX30100,0x09 register (FIFO DATA) IR : %u \r\n", FIFO_IR_samples[i]);
FIFO_RED_samples[i] = buffer_rx[ ( i << 2 ) ];
FIFO_RED_samples[i] <<= 8U;
FIFO_RED_samples[i] |= buffer_rx[ ( i << 2 ) + 1 ];
printf("Output MAX30100,0x09 register (FIFO DATA) RED : %u \r\n", FIFO_RED_samples[i]);
}
2019-06-02 04:12 AM
There are some code in git to dig in...
https://github.com/kontakt/MAX30100
https://www.arduinolibraries.info/libraries/max30100
Obsolete item at Digikey...
2019-06-02 05:10 AM
uint8_t buffer_rx[32*4];
int32_t j;
#define MAKEWORD(b, a) ((uint16_t)(((uint8_t)(a)) | ((uint16_t)((uint8_t)(b))) << 8))
HAL_I2C_Master_Receive(&hi2c2, 0xAF, buffer_rx ,number_sample*4, 100); //receive 4 bytes from MAX30100
for(i=j=0;i<=number_sample;i++,j+=4)
{
FIFO_IR_samples[i] = MAKEWORD( buffer_rx[ j+0 ], buffer_rx[ j+1 ] );
FIFO_RED_samples[i] = MAKEWORD( buffer_rx[ j+2 ], buffer_rx[ j+3 ] );
printf("Output MAX30100,0x09 register (FIFO DATA) IR : %u , RED: %u \r\n", FIFO_IR_samples[i]), FIFO_RED_samples[i]);
}
2019-06-02 11:39 PM
Is my filter right ?
void filter(sample *s)
{
uint8_t i;
uint32_t red = 0;
uint32_t ired = 0;
for (i = 0; i < filter_level - 1; i++)
{
red += samplebuff[i].red;
ired += samplebuff[i].ired;
}
s->red = (red + s->red) / filter_level;
s->ired = (ired + s->ired) / filter_level;
}
void buffinsert(sample s)
{
uint8_t i;
for (i = buff_size - 1; i > 0; i--)
{
samplebuff[i].red = samplebuff[i - 1].red;
samplebuff[i].ired = samplebuff[i - 1].ired;
}
samplebuff[0].red = s.red;
samplebuff[0].ired = s.ired;
}
void calacdc(uint16_t *rac, uint32_t *rdc, uint16_t *iac, uint32_t *idc)
{
uint32_t rmax = samplebuff[0].red;
uint32_t rmin = samplebuff[0].red;
uint32_t imax = samplebuff[0].ired;
uint32_t imin = samplebuff[0].ired;
uint8_t i;
for (i = 0; i < buff_size; i++)
{
if (samplebuff[i].red > rmax)
rmax = samplebuff[i].red;
if (samplebuff[i].red < rmin)
rmin = samplebuff[i].red;
if (samplebuff[i].ired > imax)
imax = samplebuff[i].ired;
if (samplebuff[i].ired < imin)
imin = samplebuff[i].ired;
}
*rac = rmax - rmin;
*rdc = (rmax + rmin) / 2;
*iac = imax - imin;
*idc = (imax + imin) / 2;
}
Inside the loop :
HAL_I2C_Master_Receive(&hi2c2, 0xAF, buffer_rx ,number_sample*4, 100); //receive 4 bytes from MAX30100
for(i=j=0;i<=number_sample;i++,j+=4)
{
samplebuff[i].ired = buffer_rx[ j ];
samplebuff[i].ired <<= 8U;
samplebuff[i].ired |= buffer_rx[ j + 1 ];
printf("Data %u ",i);
printf("Output MAX30100,0x09 register (FIFO DATA) IR : %u \r\n", samplebuff[i].ired);
//FIFO_IR_samples[i] = buffer_rx[ j ];
//FIFO_IR_samples[i] <<= 8U;
//FIFO_IR_samples[i] |= buffer_rx[ j + 1 ];
//printf("Output MAX30100,0x09 register (FIFO DATA) IR : %u \r\n", FIFO_IR_samples[i]);
//Filter it
//samplebufftemp[i].ired = FIFO_IR_samples[i];
samplebufftemp[i].ired = samplebuff[i].ired;
buffinsert(samplebufftemp[i]);
calacdc(&redac, &reddc, &iredac, &ireddc);
filter(&samplebufftemp[i]);
//FIFO_RED_samples[i] = buffer_rx[ j+2 ];
//FIFO_RED_samples[i] <<= 8U;
//FIFO_RED_samples[i] |= buffer_rx[ j+3 ];
samplebuff[i].red = buffer_rx[ j ];
samplebuff[i].red <<= 8U;
samplebuff[i].red |= buffer_rx[ j + 1 ];
printf("Data %u ",i);
printf("Output MAX30100,0x09 register (FIFO DATA) RED : %u \r\n", samplebuff[i].red);
//samplebufftemp[i].red = FIFO_RED_samples[i];
samplebufftemp[i].red = samplebuff[i].red;
buffinsert(samplebufftemp[i]);
calacdc(&redac, &reddc, &iredac, &ireddc);
filter(&samplebufftemp[i]);
float r = (((float)(redac)) / ((float)(reddc))) / (((float)(iredac)) / ((float)(ireddc)));
if (r >= 0.36 && r < 0.66)
spo2 = (uint8_t)(107 - 20 * r);
else if (r >= 0.66 && r < 1)
spo2 = (uint8_t)(129.64 - 54 * r);
printf("SPO2 = %u\r\n",spo2);
static uint8_t eachbeatsamplecount = 0; //????????????
static uint8_t lasttenbeatsamplecount[10]; //?????????????
static uint32_t last_ired = 0;
uint8_t ii;
eachsamplediff = last_ired - samplebufftemp[i].ired;
if (eachsamplediff > 50 && eachbeatsamplecount > 12)
{
for (ii = 9; ii > 0; ii--)
lasttenbeatsamplecount[i] = lasttenbeatsamplecount[i - 1];
lasttenbeatsamplecount[0] = eachbeatsamplecount;
uint32_t totaltime = 0;
for (ii = 0; ii < 10; ii++)
totaltime += lasttenbeatsamplecount[i];
heartrate = (uint8_t)(60.0 * 10 / 0.02 / ((float)totaltime));
printf("Heart Rate = %u\r\n",heartrate);
eachbeatsamplecount = 0;
}
last_ired = samplebufftemp[i].ired;
eachbeatsamplecount++;
}
global variable :
#define buff_size 50
sample samplebuff[buff_size];
sample samplebufftemp[buff_size];
uint8_t heartrate = 0;
uint8_t spo2 = 0;
uint16_t redac = 0;
uint32_t reddc = 0;
uint16_t iredac = 0;
uint32_t ireddc = 0;
int16_t eachsamplediff = 0;
#define filter_level 8
2019-06-03 02:47 AM
I got the output :
Data 0 Output MAX30100,0x09 register (FIFO DATA) IR : 22337
Data 0 Output MAX30100,0x09 register (FIFO DATA) RED : 22337
SPO2 = 0
Data 1 Output MAX30100,0x09 register (FIFO DATA) IR : 30557
Data 1 Output MAX30100,0x09 register (FIFO DATA) RED : 30557
SPO2 = 0
Data 2 Output MAX30100,0x09 register (FIFO DATA) IR : 38668
Data 2 Output MAX30100,0x09 register (FIFO DATA) RED : 38668
SPO2 = 0
Data 3 Output MAX30100,0x09 register (FIFO DATA) IR : 46878
Data 3 Output MAX30100,0x09 register (FIFO DATA) RED : 46878
SPO2 = 0
Data 4 Output MAX30100,0x09 register (FIFO DATA) IR : 55170
Data 4 Output MAX30100,0x09 register (FIFO DATA) RED : 55170
SPO2 = 0
Data 5 Output MAX30100,0x09 register (FIFO DATA) IR : 63290
Data 5 Output MAX30100,0x09 register (FIFO DATA) RED : 63290
SPO2 = 0
Data 6 Output MAX30100,0x09 register (FIFO DATA) IR : 65535
Data 6 Output MAX30100,0x09 register (FIFO DATA) RED : 65535
SPO2 = 0
Data 7 Output MAX30100,0x09 register (FIFO DATA) IR : 65535
Data 7 Output MAX30100,0x09 register (FIFO DATA) RED : 65535
SPO2 = 0
Data 8 Output MAX30100,0x09 register (FIFO DATA) IR : 0
Data 8 Output MAX30100,0x09 register (FIFO DATA) RED : 0
SPO2 = 0