Closed sandeepmvd closed 7 years ago
cc @bcostm @adustm @LMESTM @jeromecoutant
@andcor02
@binary-nerd Hello there are weekly non-regression tests in MBED of reading I2C temperature sensors with all NUCLEO boards, so there is no limitation.
Here is a working example of a temperature driver: https://developer.mbed.org/users/neilt6/code/LM75B/file/7ac462ba84ac/LM75B.cpp I think many sensors work the same so you could re-use part of the code for the mlx90614.
I think that your code is missing the "STEP4: Send Repeated Start" In the library that shared this repeated start is sent with passing true as the last parameter to m_I2C_write. ` unsigned short LM75B::read16(char reg) { //Create a temporary buffer char buff[2];
//Select the register
m_I2C.write(m_ADDR, ®, 1, true);
//Read the 16-bit register
m_I2C.read(m_ADDR, buff, 2);
//Return the combined 16-bit value
return (buff[0] << 8) | buff[1];
} `
I think that you need to add this "true" parameter in your code: ` cmd[0] = 0x07;
i2c.write(addr8bit, cmd, 1, true);
i2c.read( addr8bit, cmd, 2); `
This sensor is a bit tricky. It can be used in two different configuration: i2c or pwm mode. We had to enable the i2c mode everytime we started the system. We used a NUCLEO_F411RE.
The lm75 is much more easier.
@LMESTM
Thank you very much. setting repeated start to true
works.
I am now getting sensible sensor data.
I get varying temperature data and the values look nice.
The temperature sensor data on nucleo is as follows :
cmd[0] = 94 cmd[1] = 58
cmd[0] = 96 cmd[1] = 58
cmd[0] = 97 cmd[1] = 58
cmd[0] = 96 cmd[1] = 58
cmd[0] = 94 cmd[1] = 58
cmd[0] = 97 cmd[1] = 58
cmd[0] = 96 cmd[1] = 58
cmd[0] = 97 cmd[1] = 58
cmd[0] = 96 cmd[1] = 58
cmd[0] = 146 cmd[1] = 58
cmd[0] = 136 cmd[1] = 58
cmd[0] = 142 cmd[1] = 58
cmd[0] = 140 cmd[1] = 58
cmd[0] = 146 cmd[1] = 58
cmd[0] = 96 cmd[1] = 58
@ohagendorf I am not explicitly setting its mode. With the change suggested by @LMESTM it starts to work. I checked the datasheet to see how to change the mode from I2c to PWM and vice-versa. Cannot find any relevant stuff. Could you please explain here how you are explicitly setting its mode to I2c and PWM?
@binary-nerd glad to hear this works fine now - I'll let you close the issue when you think it's ok. You can continue discussion about the sensor even if issue is closed ;-)
Ok. I will close the issue. :) I will be waiting for reply from @ohagendorf
Question
I am trying to read some data from the mlx90614 temperature sensor attached to a NUCLEO-F091RC. so far, not successful.
There are many posts on this topic but the issue remains unresolved everywhere.
Following is the code I am trying with.
The raw data is always 255. both
cmd[0] and [cmd[1]
The above code, I wrote based is based on the working code on Arduino Uno board (github), I2c mbed API's and referring to the sensor's datasheet:
Registers to read from sensor:
Here is the pseudo code from the datasheet
Toolchain: GCC_ARM
Is there any limitation wrt using I2c on nucleo?
Output:
Raw data from Arduino board (not mbed code. (Arduino library code) )
With the code I posted above, the data is as follows
cmd[0] 255 cmd[1] 255 cmd[0] 255 cmd[1] 255 cmd[0] 255 cmd[1] 255 cmd[0] 255 cmd[1] 255 cmd[0] 255 cmd[1] 255