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.
Dependents: ACandLightsandWifi ACandLightsandWifi
Fork of DS1820 by
DS1820 Class Reference
DS1820 Dallas 1-Wire Temperature Probe. More...
#include <DS1820.h>
Public Member Functions | |
| DS1820 (PinName data_pin, PinName power_pin) | |
| Create a probe object connected to the specified pins. | |
| DS1820 (PinName data_pin) | |
| Create a probe object connected to the specified pin this is used when all probes are externally powered. | |
| void | search_Rom_setup () |
| This routine initializes the global variables used in the search_Rom() and search_alarm() funtions. | |
| bool | search_Rom () |
| This routine will search for an unidentified device on the bus. | |
| bool | search_alarm () |
| This routine will search for an unidentified device which has the temperature alarm bit set. | |
| void | read_Rom () |
| This routine will read the RomMMMM (Family code, serial number and Checksum) fRomM a dedicated device on the bus. | |
| void | convert_temperature (devices device=this_device) |
| This routine will initiate the temperature conversion within a DS1820. | |
| float | temperature (char scale='c') |
| This function will return the probe temperature. | |
| bool | Rom_checksum_error () |
| This function calculates the Rom checksum and compares it to the CRC value stored in RomMMM[7]. | |
| bool | RAM_checksum_error () |
| This function calculates the RAM checksum and compares it to the CRC value stored in RAM[8]. | |
| bool | set_configuration_bits (unsigned int resolution) |
| This function returns the values stored in the temperature alarm registers. | |
| int | read_scratchpad () |
| This function sets the temperature resolution for the DS18B20 in the configuration register. | |
| void | write_scratchpad (int data) |
| This function will store the passed data into the DS1820's RAM. | |
| void | store_scratchpad (devices device=this_device) |
| This function will transfer the TH and TL registers fRomM the DS1820's RAM into the EEPRomMMMM. | |
| int | recall_scratchpad (devices device=this_device) |
| This function will copy the stored values fRomMMM the EEPRomM into the DS1820's RAM locations for TH and TL. | |
| bool | read_power_supply (devices device=this_device) |
| This function will return the type of power supply for a specific device. | |
Data Fields | |
| char | Rom [8] |
| RomMMM is a copy of the internal DS1820's Rom It is created during the search_RomM() or search_alarm() commands. | |
| char | RAM [9] |
| RAM is a copy of the internal DS1820's RAM It's updated during the read_RAM() command which is automaticaly called fRom any function using the RAM values. | |
Detailed Description
DS1820 Dallas 1-Wire Temperature Probe.
Example:
#include "mbed.h" #include "TextLCD.h" #include "DS1820.h" TextLCD lcd(p25, p26, p21, p22, p23, p24, TextLCD::LCD16x2); // rs, e, d0-d3, layout const int MAX_PROBES = 16; DS1820* probe[MAX_PROBES]; int main() { int i; int devices_found=0; // Initialize the probe array to DS1820 objects for (i = 0; i < MAX_PROBES; i++) probe[i] = new DS1820(p27); // Initialize global state variables probe[0]->search_RomMM_setup(); // Loop to find all devices on the data line while (probe[devices_found]->search_RomM() and devices_found<MAX_PROBES-1) devices_found++; // If maximum number of probes are found, // bump the counter to include the last array entry if (probe[devices_found]->RomMMMM[0] != 0xFF) devices_found++; lcd.cls(); if (devices_found==0) lcd.printf("No devices found"); else { while (true) { probe[0]->convert_temperature(DS1820::all_devices); lcd.cls(); for (i=0; i<devices_found; i++) { lcd.printf("%3.1f ",probe[i]->temperature('f')); } } } }
Definition at line 81 of file DS1820.h.
Constructor & Destructor Documentation
| DS1820 | ( | PinName | data_pin, |
| PinName | power_pin | ||
| ) |
Create a probe object connected to the specified pins.
- Parameters:
-
data_pin DigitalInOut pin for the data bus power_pin DigitalOut pin to control the power MOSFET
Definition at line 10 of file DS1820.cpp.
| DS1820 | ( | PinName | data_pin ) |
Create a probe object connected to the specified pin this is used when all probes are externally powered.
- Parameters:
-
data_pin DigitalInOut pin for the data bus
Definition at line 18 of file DS1820.cpp.
Member Function Documentation
| void convert_temperature | ( | devices | device = this_device ) |
This routine will initiate the temperature conversion within a DS1820.
There is a built in 750ms delay to allow the conversion to complete.
To update all probes on the bus, use a statement such as this: probe[0]->convert_temperature(DS1820::all_devices);
- Parameters:
-
allows the fnction to apply to a specific device or to all devices on the 1-Wire bus.
Definition at line 249 of file DS1820.cpp.
| bool RAM_checksum_error | ( | ) |
This function calculates the RAM checksum and compares it to the CRC value stored in RAM[8].
- Returns:
- true if the checksum matches, otherwise false.
Definition at line 207 of file DS1820.cpp.
| bool read_power_supply | ( | devices | device = this_device ) |
This function will return the type of power supply for a specific device.
It can also be used to query all devices looking for any device that is parasite powered.
- Returns:
- true if the device (or all devices) are Vcc powered, returns false if the device (or ANY device) is parasite powered.
Definition at line 381 of file DS1820.cpp.
| void read_Rom | ( | ) |
This routine will read the RomMMMM (Family code, serial number and Checksum) fRomM a dedicated device on the bus.
NOTE: This command can only be used when there is only one DS1820 on the bus. If this command is used when there is more than one slave present on the bus, a data collision will occur when all the DS1820s attempt to respond at the same time.
Definition at line 173 of file DS1820.cpp.
| int read_scratchpad | ( | ) |
This function sets the temperature resolution for the DS18B20 in the configuration register.
- Parameters:
-
a number between 9 and 12 to specify the resolution
- Returns:
- true if successful
Definition at line 300 of file DS1820.cpp.
| int recall_scratchpad | ( | devices | device = this_device ) |
This function will copy the stored values fRomMMM the EEPRomM into the DS1820's RAM locations for TH and TL.
- Parameters:
-
allows the function to apply to a specific device or to all devices on the 1-Wire bus.
Definition at line 332 of file DS1820.cpp.
| bool Rom_checksum_error | ( | ) |
This function calculates the Rom checksum and compares it to the CRC value stored in RomMMM[7].
- Returns:
- true if the checksum matches, otherwise false.
Definition at line 198 of file DS1820.cpp.
| bool search_alarm | ( | ) |
This routine will search for an unidentified device which has the temperature alarm bit set.
It uses the variables in search_RomMMM_setup to remember the pervious RomMMM address found. It will return FALSE if there were no new devices with alarms discovered on the bus.
Definition at line 89 of file DS1820.cpp.
| bool search_Rom | ( | ) |
This routine will search for an unidentified device on the bus.
It uses the variables in search_RomMMMM_setup to remember the pervious RomMMMM address found. It will return FALSE if there were no new devices discovered on the bus.
Definition at line 85 of file DS1820.cpp.
| void search_Rom_setup | ( | ) |
This routine initializes the global variables used in the search_Rom() and search_alarm() funtions.
It should be called once before looping to find devices.
Definition at line 162 of file DS1820.cpp.
| bool set_configuration_bits | ( | unsigned int | resolution ) |
This function returns the values stored in the temperature alarm registers.
- Returns:
- a 16 bit integer of TH (upper byte) and TL (lower byte).
Definition at line 287 of file DS1820.cpp.
| void store_scratchpad | ( | devices | device = this_device ) |
This function will transfer the TH and TL registers fRomM the DS1820's RAM into the EEPRomMMMM.
Note: There is a built in 10ms delay to allow for the completion of the EEPRomMMM write cycle.
- Parameters:
-
allows the fnction to apply to a specific device or to all devices on the 1-Wire bus.
Definition at line 319 of file DS1820.cpp.
| float temperature | ( | char | scale = 'c' ) |
This function will return the probe temperature.
This function uses the count remainding values to interpolate the temperature to about 1/150th of a degree. Whereas the probe is not spec to that precision. It does seem to give a smooth reading to the tenth of a degree.
- Parameters:
-
scale,may be either 'c' or 'f'
- Returns:
- temperature for that scale
Definition at line 351 of file DS1820.cpp.
| void write_scratchpad | ( | int | data ) |
This function will store the passed data into the DS1820's RAM.
Note: It does NOT save the data to the EEPRomMMM for retention during cycling the power off and on.
- Parameters:
-
a 16 bit integer of TH (upper byte) and TL (lower byte).
Definition at line 307 of file DS1820.cpp.
Field Documentation
| char RAM[9] |
| char Rom[8] |
RomMMM is a copy of the internal DS1820's Rom It is created during the search_RomM() or search_alarm() commands.
RomMMM[0] is the Dallas Family Code RomMMM[1] thru RomMMM[6] is the 48-bit unique serial number RomMMM[7] is the device CRC
Generated on Tue Jul 12 2022 17:25:47 by
1.7.2
