Melexis MLX90620 and MLX90621, non-contact, 16x4 infrared array temperature sensor device driver.
Revision 2:82782c73251e, committed 2016-07-26
- Comitter:
- loopsva
- Date:
- Tue Jul 26 19:52:23 2016 +0000
- Parent:
- 1:fd536ebc7eaf
- Commit message:
- Fixes bug in DISCO_F746NG when reading MLX9062x EEPROM. The F746 has a 255 byte I2C limit. Any transfer larger, the buffer returns all 0xff. So, the MLX's EEPROM needs to be read 1 + 255 bytes in order to get all 256. A compiler flag is used.
Changed in this revision
MLX90620.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MLX90620.cpp Thu Jul 21 23:09:24 2016 +0000 +++ b/MLX90620.cpp Tue Jul 26 19:52:23 2016 +0000 @@ -24,7 +24,7 @@ _i2c.stop(); //initialize with a stop mlxDev = MLXtype; //user select device 620 or 621 } - + //--------------------------------------------------------------------------------------------------------------------------------------// //copy contents of EEPROM inside the MLX9062x into a local buffer. Data is used for lookup tables and parameters @@ -37,20 +37,20 @@ //clear out buffer first for(int i = 0; i < 256; i++) Pntr.MLXEEbuf[i] = 0; //clear out entire EEMPROM buffer - - //load the entire EEPROM - Pntr.MLXEEbuf[0] = 0; //start at address 0 of EEPROM + +//the following code addition of a 1 byte I2C fetch is due to a bug in the F746NG which can only transfer 255 bytes at a time. grrr!!!.... +#if defined(TARGET_DISCO_F746NG) +#warning "TARGET_DISCO_F746NG i2c bug, 255 byte limit!!!" + Pntr.MLXEEbuf[0] = 255; + if(!_i2c.write(MLX_EEPADDR, Pntr.MLXEEbuf, 1, true)) { + _i2c.read((MLX_EEPADDR + 1), Pntr.MLXEEbuf, 1, false); + Pntr.MLXEEbuf[255] = Pntr.MLXEEbuf[0]; + Pntr.MLXEEbuf[0] = 0; + _i2c.write(MLX_EEPADDR, Pntr.MLXEEbuf, 1, true); + _i2c.read((MLX_EEPADDR + 1), Pntr.MLXEEbuf, 255, false); //s/b 256 if F746NG bug wasn't there +#else if(!_i2c.write(MLX_EEPADDR, Pntr.MLXEEbuf, 1, true)) { //send command, 0 returned is ok - -#ifdef MLX_EEP_EASY_LOAD - _i2c.read((MLX_EEPADDR + 1), Pntr.MLXEEbuf, 256);//**** this command does not work with the KL25Z and v63 of mbed.lbr !!!! -#else - _i2c.start(); - _i2c.write(MLX_EEPADDR + 1); - for(int i = 0; i < 256; i++) { - Pntr.MLXEEbuf[i] = _i2c.read(1); - } - _i2c.stop(); + _i2c.read((MLX_EEPADDR + 1), Pntr.MLXEEbuf, 256, false); #endif } else { @@ -658,3 +658,4 @@ } +