Skip to content

DanJMaher/TMP102

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TI TMP102 Driver

Simple driver for the TI TMP102 I2C temperature sensor. For use with TI TM4C123X MCUs and TI's TivaWare™ Peripheral Driver Library.

Description

This is a very basic driver for the TI TMP102 I2C temperature sensor for use with TI TM4C123X microcontrollers.

This driver relies heavily on TI's TivaWare™ Peripheral Driver Library. Because of this, it should be portable to all TM3C123X MCUs, but was only tested using a TM4C123GH6PM.

This driver implements nearly every feature of the TMP102 sensor including temperature readings, alerts, alert polarity adjustment, conversion rate adjustment, shutdown mode, comparator mode, interrupt mode, fault queue adjustment, one-shot mode, and high/low limits.

The only feature I didn't implement was the ability to turn off enhanced mode. Enhanced mode allows for 13-bit temperature readings, which I hardcoded it into this driver.

Getting Started

For function details, please see the function descriptions in tmp102.h

Dependencies

  • You must be using TI's TivaWare™ Peripheral Driver Library in order for this driver to work. It can be downloaded here: https://www.ti.com/tool/SW-TM4C
  • You must be using an MCU compatible with TI's TivaWare™ Peripheral Driver Library. In my case, I used a TM4C123GH6PM.

Installing

  • Download tmp.c and tmp.h to your project directory, or another directory and add it to your project's include path.
  • Make sure to add #include "tmp102.h" to your project.

Usage

In order to use this driver, you must have an I2C port on your MCU configured. Once that is complete, you simply have to initialize your tmp102 sensor by using the tmp102Begin() function.

tmp102Begin() takes two arguments, the sensor address (default 0x48) and the I2C port number that you are using. This driver is able to use ports 0-3.

For example, if I wanted to initialize device 0x48 on I2C port 0, I would use the following:

tmp102Begin(0x48, 0);

This statement does three things:

  • Saves the device address locally
  • Saves the device's port number locally
  • Retrieves the current configuration from the sensor and ensures that EM mode (13-bit temperatures) is active

Everytime tmp102Begin() is called, the local address and port variables are overwritten with the new values. This means that you can use multiple TMP102 sensors on different addresses by calling the tmp102Begin() function to switch between sensors. Configuration settings are stored in the sensors themselves as long as they maintain power.

After tmp102Begin() is called, you are able to use any of the other functions. If you you want the most basic of functionality, you can immediately start calling tmp102GetTemp() after tmp102Begin():

float temp;
tmp102Begin(0x48, 0);

while(1){
   temp = tmp102GetTemp();
   //do something with temp
}

Authors

Dan Maher

Version History

  • 0.1
    • Initial Release

License

This project is licensed under the MIT License - see LICENSE.MD for details

Acknowledgments

Inspiration and Reference Material

About

Driver for the TI TMP102 I2C temperature sensor. For use with TI TM4C123X MCUs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages