OB1203 basic mbed driver
Diff: OB1203.cpp
- Revision:
- 4:f25ca600a0e6
- Parent:
- 3:ffcd0d2ec97f
- Child:
- 5:527556d05aa8
--- a/OB1203.cpp Wed May 09 20:44:00 2018 +0000 +++ b/OB1203.cpp Mon May 14 16:57:51 2018 +0000 @@ -1,9 +1,11 @@ #include "OB1203.h" #include "mbed.h" +//#include "SoftI2C.h" extern Serial pc; OB1203::OB1203(I2C *i2c_obj) +//OB1203::OB1203(SoftI2C *i2c_obj) { i2c = i2c_obj; } @@ -44,6 +46,12 @@ writeData[0] = startReg; i2c->write(addr,writeData,1,true); i2c->read(addr,data,numBytes); +// wait_us(800); +// for(int n=0;n<numBytes;n++) +// { +// i2c->read(addr,data+n,1,1); +// wait_us(20); +// } } uint16_t OB1203::get_status() @@ -67,7 +75,8 @@ { char writeData[2]; writeData[0] = ls_sai | ls_mode | ls_en; //MAIN_CTRL_0 - writeData[1] = ps_sai_en | ppg_ps_mode | ppg_ps_en; //MAIN_CTRL_1 + writeData[1] = temp_en | ps_sai_en | ppg_ps_mode | ppg_ps_en; //MAIN_CTRL_1 + pc.printf("main config 1 to write %02x\r\n",writeData[1]); writeBlock(OB1203_ADDR,REG_MAIN_CTRL_0,writeData,2); } @@ -318,14 +327,15 @@ char OB1203::get_ps_ls_data(uint32_t *data) { - char byte_data[19]; - readBlock(OB1203_ADDR,REG_STATUS_0,byte_data,19); + char byte_data[21]; + readBlock(OB1203_ADDR,REG_STATUS_0,byte_data,21); #ifdef DEBUG - pc.printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\r\n", + pc.printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x $02x\r\n", byte_data[0],byte_data[1],byte_data[2],byte_data[3],byte_data[4], byte_data[5],byte_data[6],byte_data[7],byte_data[8],byte_data[9], byte_data[10],byte_data[11],byte_data[12],byte_data[13],byte_data[14], - byte_data[15],byte_data[16],byte_data[17],byte_data[18] ); + byte_data[15],byte_data[16],byte_data[17],byte_data[18] ), + byte_data[19],byte_data[20]; #endif data[0] = ((uint32_t)byte_data[3])<<8 | ((uint32_t)byte_data[2]); //ps @@ -334,6 +344,7 @@ data[3] = bytes2uint32(byte_data,10); //b data[4] = bytes2uint32(byte_data,13); //r data[5] = bytes2uint32(byte_data,16); //c + data[6] = ((uint32_t)byte_data[19])<<8 | ((uint32_t)byte_data[20]); //temp data return ( (byte_data[0] & LS_NEW_DATA) == 0x01 ? 1 : 0); //return 1 if new data or 0 if old data }