David Jung
/
MAX32664C_MAXM86146_Mode1_Optical
Mode1 Optical Validation
Diff: main.cpp
- Revision:
- 35:67699bdae57e
- Parent:
- 34:53043966c276
- Child:
- 36:a6e7ff9c87a0
--- a/main.cpp Tue Mar 15 21:02:23 2022 +0000 +++ b/main.cpp Thu Mar 31 01:04:22 2022 +0000 @@ -37,7 +37,7 @@ /****************************************************************************** * https://os.mbed.com/users/phonemacro/code/MAX32664C_Example_Host_Code * Tera Term output is set to 115200 baud rate. -* ver: 220310 +* ver: 220330 ******************************************************************************/ /****************************************************************************** @@ -89,7 +89,7 @@ // Comment out both of the below for Normal Algorithm Samples Format //#define EXTENDED_ALGO 1 // define this if you want the extended algo samples report format -#define PACKED_NORMAL_ALGO 1 // define this if you want the packed normal algo samples report format, 33.13.31 +//#define PACKED_NORMAL_ALGO 1 // define this if you want the packed normal algo samples report format, 33.13.31 //#define AGC 1 // define this for AGC, otherwise the default is AEC @@ -204,10 +204,17 @@ // tested w/ 33.13.12 doen't need 2.1 #endif // 2.2 +#if defined(PACKED_NORMAL_ALGO) + cmd[0] = 0x20; + sh_i2c.write(SH_ADDR, cmd, 1); +#else cmd[0] = 0x12; cmd[1] = 0x00; sh_i2c.write(SH_ADDR, cmd, 2); +#endif wait_us(100); sh_i2c.read(SH_ADDR, rsp, 2); +// mfio = 1; mfio = 0; wait_us(300); + // pc.printf("2.2 Status: %x %x\n\r", rsp[0], rsp[1]); samples = rsp[1]; // pc.printf("num samples %d, (num*ttl)+1 %d\n\r", rsp[1], TTL_SZ*samples+1); @@ -220,19 +227,25 @@ #endif // 2.3 - cmd[0] = 0x12; cmd[1] = 0x01; - sh_i2c.write(SH_ADDR, cmd, 2); - wait_us(100); - sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples)); - mfio = 1; +#if defined(PACKED_NORMAL_ALGO) + cmd[0] = 0x21;; + sh_i2c.write(SH_ADDR, cmd, 1); +#else + cmd[0] = 0x12; cmd[1] = 0x01; + sh_i2c.write(SH_ADDR, cmd, 2); +#endif + wait_us(100); + sh_i2c.read(SH_ADDR, rsp, 1+(TTL_SZ*samples)); +// mfio = 1; mfio = 0; wait_us(300); + mfio = 1; status = rsp[0]; sptr = 1; for (i = 0; i < scnt; i++) { -#ifdef ALGO_ONLY ptr = sptr; -#else +#if !defined(ALGO_ONLY) + ptr = sptr; ppg[0] = (rsp[ptr+0] << 16) | (rsp[ptr+1] << 8) | (rsp[ptr+2]); ppg[1] = (rsp[ptr+3] << 16) | (rsp[ptr+4] << 8) | (rsp[ptr+5]); @@ -341,7 +354,7 @@ #endif #elif defined(PACKED_NORMAL_ALGO) // pc.printf("ptr %d ttlsiz %d ", ptr, TTL_SZ); - opmode = rsp[ptr]; + opmode = rsp[ptr]; hr = (rsp[ptr+1] << 8) + rsp[ptr+2]; hr_conf = rsp[ptr+3]; ibi = (rsp[ptr+4] << 8) + rsp[ptr+5]; @@ -373,6 +386,15 @@ ibi_offset = rsp[ptr+15]; sptr += (TTL_SZ); +#if 0 + // print as hex bytes + for (j=0; j<ALGO_SZ; j++) + pc.printf("%02X ", rsp[ptr+j]); + pc.printf("\n\r" ); +#endif + + +#if 1 #if 1 if (heading_printed == 0) { heading_printed = 1; @@ -384,7 +406,8 @@ pc.printf("%d,%d,%d,%d,", spo2_lopi,spo2_unrel, spo2_state, scd); pc.printf("%d,", ibi_offset); pc.printf("%d,", inappro_ori); - + +#endif #else if (heading_printed == 0) { heading_printed = 1; @@ -480,7 +503,7 @@ // init_sh_algo /*****************************************************************************/ void init_sh_algo(void) { - char cmd[8]; + char cmd[64]; char rsp[256]; #ifdef OPTIMIZE_FIFO_READ @@ -501,15 +524,27 @@ #endif mfio = 0; wait_us(300); - -//read operating mode - cmd[0] = 0x02; cmd[1] = 0x00; - sh_i2c.write(SH_ADDR, cmd, 2); +#if 0 +//write SpO2 coefficients 0x00000000 FFD7FBDD 00AB61FE + cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x00; + cmd[3] = 0x00; cmd[4] = 0x00; cmd[5] = 0x00; cmd[6] = 0x00; + cmd[7] = 0xFF; cmd[8] = 0xD7; cmd[9] = 0xFB; cmd[10] = 0xDD; + cmd[11] = 0x00; cmd[12] = 0xAB; cmd[13] = 0x61; cmd[14] = 0xFE; + sh_i2c.write(SH_ADDR, cmd, 15); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); - sh_i2c.read(SH_ADDR, rsp, 2); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("Wr Spo2 Coeff %x\n\r", rsp[0]); +#endif +//1.1 rd SpO2 Coefficients + cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); - pc.printf("\n\r 0x02 0x00 Status, Read Operating Mode: %x %x\n\r", rsp[0], rsp[1]); -//1.1 rd ver + sh_i2c.read(SH_ADDR, rsp, 13); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("%x SpO2 Coeff %2X%2X%2X%2X %2X%2X%2X%2X %2X%2X%2X%2X\n\r", rsp[0], rsp[1], rsp[2], rsp[3], rsp[4], rsp[5], rsp[6], rsp[7], rsp[8], rsp[9], rsp[10], rsp[11], rsp[12]); + +//1.9 rd ver cmd[0] = 0xFF; cmd[1] = 0x03; sh_i2c.write(SH_ADDR, cmd, 2); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); @@ -517,6 +552,24 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("Ver: %d %d %d %d\n\r", rsp[0], rsp[1], rsp[2], rsp[3]); +#if defined(MAXM86146_CFG) && defined(PACKED_NORMAL_ALGO) +// wr config mask for packed normal data output fifo + cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0xFF; cmd[4] = 0xFF; cmd[5] = 0x00; +// cmd[0] = 0x50; cmd[1] = 0x07; cmd[2] = 0x20; cmd[3] = 0x7F; cmd[4] = 0xFF; cmd[5] = 0x00; + sh_i2c.write(SH_ADDR, cmd, 6); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 1); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("wr config mask packed: %x \n\r", rsp[0]); +// rd config mask for packed normal data output fifo + cmd[0] = 0x51; cmd[1] = 0x07; cmd[2] = 0x20; + sh_i2c.write(SH_ADDR, cmd, 3); + mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300); + sh_i2c.read(SH_ADDR, rsp, 4); + mfio = 1; mfio = 0; wait_us(300); + pc.printf("rd config mask for packed normal data output fifo %d %X %X %X \n\r", rsp[0], rsp[1], rsp[2], rsp[3]); +#endif + #if defined(MAXM86161_CFG) || defined(MAXM86146_CFG) // rd algo sz normal cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x01; @@ -540,7 +593,7 @@ mfio = 1; mfio = 0; wait_us(300); pc.printf("rd algo size: %d %d \n\r", rsp[0], rsp[1]); #if defined(MAXM86146_CFG) -// rd algo sz scd +// rd algo sz packed normal cmd[0] = 0x11; cmd[1] = 0x06; cmd[2] = 0x04; sh_i2c.write(SH_ADDR, cmd, 3); mfio = 1; thread_sleep_for(2); mfio = 0; wait_us(300);