In this post i am going to interface LM74 temperature sensor with Pic18f452 microcontroller. LM74 is a temperature sensor by Texas Instruments. It comes with an SPI (Serial Peripheral Interface) interface. You can operate it in SPI (Serial Peripheral Interface) mode. A processor/microcontroller can read temperature reading from LM74 at any time. LM74 provides resolution of up to 0.0625 degree Centigrade. It can operate between -55 degree to +150 degree centigrade. It works only as slave in a system. When interfaced with processor / microcontroller in SPI mode it can only be a slave to a host.
I assume that you are already familiar with the SPI interface. If not then first took some tutorials on SPI (Serial Peripheral Interface) interface before going through this project.
LM74 Temperature Sensor Pin Out
The only important pins are SI/O (Slave Input/Output) and SC (Slave Clock). CS is Chip select and its active low, the sensor will not work if you don’t make CS Low(0). So make sure to make CS low before using the sensor.
SI/O is Slave input/output. All the commands, control signals and data, travels in and out of the sensor from this pin.Data is clocked out from the sensor on the falling edge of the serial clock (SC), while data is clocked in on the rising edge of SC. A complete transmit/receive communication will consist of 32 serial clocks. The first 16 clocks comprise the transmit phase of communication, while the second 16 clocks are the receive phase. SC is Slave clock. In SPI mode clock is essential to carry out the task.
SI/O is Slave input/output. All the commands, control signals and data, travels in and out of the sensor from this pin.Data is clocked out from the sensor on the falling edge of the serial clock (SC), while data is clocked in on the rising edge of SC. A complete transmit/receive communication will consist of 32 serial clocks. The first 16 clocks comprise the transmit phase of communication, while the second 16 clocks are the receive phase. SC is Slave clock. In SPI mode clock is essential to carry out the task.
LM74 Temperature Sensor Registers
LM74 temperature sensor has three registers. All three registers are 16-bit wide.
LM74 Temperature Sensor Configuration Register
Configuration register sets the LM74 in shutdown or continuous conversion mode. Continuous conversion means continuously convert the temperature. Its a 16-bit wide register. To enable shutdown mode or continuous conversion mode see the data bits configuration in the pic from datasheet below.
LM74 Temperature Register
LM74 measures temperature and places the equivalent digital value in the Temperature register. Now host can read the temperature from temperature register. Its a 16-bit wide register. First 2 bits are void. Third bit is always high. Bits from 4 to 16 (DB3 to DB15) are data bits. Temperature digital values are stored in these DB3 to DB15 bits.
Note: On first power up LM74 will output arbitrary data don’t worry its for the first time power up. Then its start working perfectly.
LM74 Manufacturer’s Device ID Register
This register works only when LM74 is in shutdown mode. It outputs manufacture device ID. You don’t need to care about this register.
SPI communication with Pic8f452 Microcontroller
Four pins of Pic18f452 are dadicated for SPI communication. It is assumed that you are already familiar with the SPI communication protocol and their is no need to explain these pins and their functions.
- Serial Data Out (SDO) – RC5/SDO
- Serial Data In (SDI) – RC4/SDI
- Serial Clock (SCK) – RC3/SCK
- Slave Select (SS) – RA5/SS
Three registers are associated with SPI communication. To carry out successful SPI communication we have to configure them correctly.
SSPSTAT SPI status register
Individual bits of register with their fuctions are below. I uploaded SSPSTAT=0x00 which means SPI in Master Mode, Data transmitted on falling clock.
SSPCON1 SPI Control Register
Individual bits of register with their functions are below. I uploaded SSPCON1=0x20 which means Serial port not enabled and Clock=Fosc/4.
SSPBUF (Serial Receive and Transmit Register)
This register is not directly accessible. The data which goes out and comes in is dropped in this register and user can pick data from this register.
Project Circuit Diagram
Project Code
Project code is written in c language and is compiled in MP-Lab using high tech C compiler. Simulation is made in proteaus 8.0.
Download the Project files, folder includes the project code(Hex, C++) and simulation in Proteaus 8.0. If you have any questions regarding the post please leave your queries below in the comments section.
Filed Under: Microcontroller Projects, PIC Microcontroller
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.