Application of I2C temperature sensor

Source: Internet
Author: User

Demand:
Read the value of the embedded temperature sensor.

Known conditions:
* The temperature sensor has been welded on the motherboard.
* Temperature Sensor Model LM75
*linux Drive, in linux-2.6.20.21/drivers/hwmon/lm75.c
* The circuit of the temperature sensor

Questions and Answers:
*linux How to use the drive with its own.

Look at the LM75.C code and find out that this temperature sensor is using a I2C bus.
The code sees the I2C-driven interface defined as follows, unlike a character-driven interface that was previously done.
[CPP] View Plain Copy * * is the driver that'll be inserted/static struct I2c_driver Lm75_driver = {. drive  R = {. Name = "Lm75",},. id = i2c_driverid_lm75,. Attach_adapter = Lm75_attach_adapter,. detach_client = Lm75_detach_client,};

Search in this book of Linux Device driver, which is not covered in this book.

Www.linuxjournal.com/article/7136,www.linuxjournal.com/article/7252 said it well. Especially the latter. I2C is used more in the application of the sensor on the motherboard, but it was added in the newer version of the Linux kernel, no wonder ldd the book.

Then look at the data structure of the callback function, specifically what to do is more clear. According to the content of the function, the driver automatically detects the device on the I2C bus when it is loaded, so it automatically discovers the temperature sensor. Lm75_update_device () is a function used for polling readings of temperature sensors.

According to the article guideline, look at the/sys/bus/i2c/of the equipment. The following already has the LM75 sensor data, the direct read has the data, and the data will change, as follows:


root:~# Cat/sys/bus/i2c/devices/0-0048/temp1_input
-31500


* reading is negative. What kind of readings are normal.
Added debug information to the driver code, print out the value of the registers that are read on the sensor, and not read on the file system.
Look at the Linux-2.6.20.21/documentation/hwmon/lm75, understand that Lm75 is an industrial standard. So the Lm75 drive in Linux is supported by a variety of temperature sensors.

Look at the chip on the board, it is lm75a. A datasheet was downloaded on the Internet, showing a total of 9-bit to control readings. The head position is positive or negative, followed by a value of 8-bit.
In the driver code to add debugging information, only print the register value of the 8-bit, put in the temperature test box The results appear to be full of reasonable.
[CPP] View plain copy @drivers/base/sys.c static ssize_t sysdev_show (struct kobject * kobj, struct attribute * attr,       char * buffer) {struct Sys_device * Sysdev = To_sysdev (kobj);          struct Sysdev_attribute * sysdev_attr = to_sysdev_attr (attr);       if (sysdev_attr->show) return sysdev_attr->show (Sysdev, buffer);   Return-eio; }

  [cpp]  View plain copy static device_attr (temp1_input, s_irugo, show_temp_input,  NULL);  /*  that truct device_attribute dev_attr_temp1_input =                                              __attr (temp1_input, s_irugo,                        show_temp1_input, null)   */  /* truct device_attribute dev_attr_temp1_input = {       .attr = {.name = __stringify (temp1_input),            .mode = S_IRUGO,            . owner =  this_module },       .show   = show_temp1_input,                         .store  = NULL, }  */    

[CPP] View plain copy/* interface for exporting device attributes/struct Device_attribute {struct attrib       Ute attr; ssize_t (*show) (struct device *dev, struct device_attribute, *attr,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.