
If you want to know more, please check the datasheet.
#MCP9808 STM32 DRIVER HOW TO#
t_critical_limit(SET_CRITICAL_LIMIT_ADDR,u16) is used for the inturrupt mode, in this wiki we only show you how to work as a comparator. When the temperature is higher than the value we set, the output of the ALE Pad will goes down. t_upper_limit(SET_UPPER_LIMIT_ADDR,u16) is used to set the upper temperature limit, also u16 is the 4 bit Hexadecimal temperature we set. When the temperature is lower than the value we set, the output of the ALE Pad will goes down. t_lower_limit(SET_LOWER_LIMIT_ADDR,u16) is used to set the lower temperature limit, u16 is the 4 bit Hexadecimal temperature we set. You can use those 3 functions to set your own conditions. t_upper_limit(SET_UPPER_LIMIT_ADDR,u16) t_lower_limit(SET_LOWER_LIMIT_ADDR,u16) t_critical_limit(SET_CRITICAL_LIMIT_ADDR,u16) Īs we mentioned before, the default output of the ALE Pad is high, and the output level goes low when the temperature meets certain conditions. We provide 3 functions in the file Seeed_MCP9808.cpp. e means 14 in decimal,Īnd the higer bit 1 means 16 in decimal. We set it as 0, then the valid number is 0x1e. The 0x01e0 is a four bit Hexadecimal number, the last bit in the right represent the fractional part. We use this function to control the temperature, the first parameter is the UPPER_LIMIT register address and the second parameter 0x01e0 is the Hexadecimal temperature we set, as we mentioned above, it's 30℃. set_upper_limit ( SET_UPPER_LIMIT_ADDR, 0x01e0 ) So you may ask, what if i want to change the threshold temperature. When the temperature is higher than 30℃, the ALE Pad will output low-0v. When the temperature is lower than 30℃, the ALE Pad output default high-3.3v.
#MCP9808 STM32 DRIVER CODE#
In addition to measuring temperature, this code also implements a function. #include "Seeed_MCP9808.h" MCP9808 sensor void setup () In order to better understand this part, you can refer to the AN10441 In the schematic above, Q6 and Q5 are N-Channel MOSFET 2N7002A, which act as a bidirectional switch. The I 2C bus of this sensor use 3.3V, if the I 2C bus of the Arduino use 5V, this circuit will be needed. This is a typical Bi-directional level shifter circuit to connect two different voltage section of an I 2C bus. You can set the condition when you finish this wiki 😄 Schematic ¶Īs we mentioned above, we use those three sets of pads to select the I 2C address, if you want to change the default adress, you can cut of the wire and re-solder it.Īs you can see, the ALE pad is connected to the 3.3V through a pull-up resistor. When the condition is met, the output voltage becomes low(0V). The default output is high, in this board it should be 3.3V. The alert signal output from this pad can be used as an external interrupt signal for other controllers. You can see the ALE Pad on the back of the PCB. The I 2C address in the file Seeed_MCP9808.h in the Grove_Temperature_sensor_MCP9808-master library. So the I 2C address range from 0x18 to 0x1F, among them, you can choose whatever you want, just make sure you will change High level, we will get 0001,1111, which is 0x1F. By the same token, if we solder all the pads to the We often use the hexadecimal address in the code, so let's convert the binary address to a hexadecimal address, here we get 0x18.


Normaly the address should be 8bits, so we need to add one bit 0 to the MSB(Most Significant Bit), then we get 0001,1000. The defaut setting is A 0=0/A 1=0/A 2=0, so the default I 2CĪddress is 0011000.

0011 is the address code, which is the factory setting, we can not change it.Ī 0A 1A 2 is the slave address, we can change it. The I 2C address is a 7bits address 0011A 0A 1A 2. The default AD0~AD2 are all connected to the Low level pads, you can cut those pads and solder them to the other side(High level). We offer 3 sets of pads on the back of the PCB. User-Programmable Temperature Alert Output.We use a separate pin to output the alarm signal, you will find it so convenient to use this signal as an interruption to control other board.Īll in all, we believe this sensor will be a new star for temperature control. In addition to high-precision temperature measurements, we also offer programmable temperatureĪlert. The measurement resolution of this sensor. The Grove - I2C High Accuracy Temperature Sensor(MCP9808) is a high accuracy digital module based on MCP9808. Edit Grove - I2C High Accuracy Temperature Sensor(MCP9808)
