Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TmpLM74.cpp
00001 00002 #include "mbed.h" 00003 #include "TmpLM74.h" 00004 00005 00006 TmpLM74::TmpLM74(PinName mosi, PinName miso, PinName sclk, PinName csLM74): 00007 SPI(mosi, miso, sclk), _csLM74(csLM74) { 00008 00009 _csLM74 = 1; 00010 00011 format(8,3); // initialize SPI peripheral 00012 frequency(1000000); // initialize SPI peripheral 00013 00014 startLM74(); 00015 } 00016 00017 float TmpLM74::readTemp(void){ 00018 00019 float realTemp; 00020 int16_t tempRegister; 00021 00022 _csLM74 = 0; 00023 00024 tempRegister = ((uint16_t) write(0xFF)) << 8; 00025 tempRegister |= write(0xFF); 00026 00027 _csLM74 = 1; 00028 00029 // tempRegister = (((uint16_t) 0xE4) << 8) | 0x84; // -55.0 C 00030 // tempRegister = (((uint16_t) 0xFB) << 8) | 0x04; // -10.0 C 00031 // tempRegister = 0x8000; // power down 00032 00033 // pc.printf("TempRegister = 0x%x\n", tempRegister); debugging ONLY 00034 00035 if ((tempRegister & 0x0004) == 0) { // temp reading NOT ready or LM74 in power down 00036 if((tempRegister & 0xFFFC) == 0x8000) { // Manufacturer's Device ID Register (power down) ? 00037 startLM74(); 00038 } 00039 tempRegister = INVALID_LM74_TEMP; 00040 } else { 00041 tempRegister >>= 3; 00042 } 00043 realTemp = ((float) tempRegister) * 0.0625; 00044 00045 return realTemp; 00046 } 00047 // ****************************************************************** 00048 00049 void TmpLM74::startLM74(void){ 00050 00051 _csLM74 = 0; 00052 00053 uint8_t dummy = write(0x00); 00054 dummy = write(0x00); 00055 dummy = write(0x00); 00056 dummy = write(0x00); // this byte sets LM74 to continuous conversion 00057 00058 _csLM74 = 1; 00059 } 00060 // ****************************************************************** 00061 00062 void TmpLM74::shutLM74down(void){ 00063 00064 _csLM74 = 0; 00065 00066 uint8_t dummy = write(0xFF); 00067 dummy = write(0xFF); 00068 dummy = write(0xFF); // these 2 bytes set LM74 to power down 00069 dummy = write(0xFF); // these 2 bytes set LM74 to power down 00070 00071 _csLM74 = 1; 00072 } 00073 // ******************************************************************
Generated on Wed Jul 20 2022 01:50:12 by
1.7.2