LibDriver DS18B20
Loading...
Searching...
No Matches
driver_ds18b20.c File Reference

driver ds18b20 source file More...

#include "driver_ds18b20.h"
Include dependency graph for driver_ds18b20.c:

Go to the source code of this file.

Macros

#define CHIP_NAME   "Maxim Integrated DS18B20"
 chip information definition
#define MANUFACTURER_NAME   "Maxim Integrated"
#define SUPPLY_VOLTAGE_MIN   3.0f
#define SUPPLY_VOLTAGE_MAX   5.5f
#define MAX_CURRENT   4.0f
#define TEMPERATURE_MIN   -55.0f
#define TEMPERATURE_MAX   125.0f
#define DRIVER_VERSION   2000
#define DS18B20_CMD_SEARCH_ROM   0xF0
 chip command definition
#define DS18B20_CMD_READ_ROM   0x33
#define DS18B20_CMD_MATCH_ROM   0x55
#define DS18B20_CMD_SKIP_ROM   0xCC
#define DS18B20_CMD_ALARM_SEARCH   0xEC
#define DS18B20_CMD_CONVERT_T   0x44
#define DS18B20_CMD_WRITE_SCRATCHPAD   0x4E
#define DS18B20_CMD_READ_SCRATCHPAD   0xBE
#define DS18B20_CMD_COPY_SCRATCHPAD   0x48
#define DS18B20_CMD_RECALL_EE   0xB8
#define DS18B20_CMD_READ_POWER_SUPPLY   0xB4

Functions

uint8_t ds18b20_set_mode (ds18b20_handle_t *handle, ds18b20_mode_t mode)
 set the chip mode
uint8_t ds18b20_get_mode (ds18b20_handle_t *handle, ds18b20_mode_t *mode)
 get the chip mode
uint8_t ds18b20_set_rom (ds18b20_handle_t *handle, uint8_t rom[8])
 set the handle rom
uint8_t ds18b20_get_rom (ds18b20_handle_t *handle, uint8_t rom[8])
 get the chip rom
uint8_t ds18b20_scratchpad_set_resolution (ds18b20_handle_t *handle, ds18b20_resolution_t resolution)
 set the resolution in the scratchpad
uint8_t ds18b20_scratchpad_get_resolution (ds18b20_handle_t *handle, ds18b20_resolution_t *resolution)
 get the resolution in the scratchpad
uint8_t ds18b20_scratchpad_set_alarm_threshold (ds18b20_handle_t *handle, int8_t threshold_high, int8_t threshold_low)
 set the alarm threshold in the scratchpad
uint8_t ds18b20_scrachpad_get_alarm_threshold (ds18b20_handle_t *handle, int8_t *threshold_high, int8_t *threshold_low)
 get the alarm threshold in the scratchpad
uint8_t ds18b20_copy_scratchpad_to_eeprom (ds18b20_handle_t *handle)
 copy the scratchpad content to the eeprom
uint8_t ds18b20_copy_eeprom_to_scratchpad (ds18b20_handle_t *handle)
 copy the eeprom content to the scratchpad
uint8_t ds18b20_alarm_convert_to_register (ds18b20_handle_t *handle, float temp, int8_t *reg)
 convert the alarm temperature to the register data
uint8_t ds18b20_alarm_convert_to_data (ds18b20_handle_t *handle, int8_t reg, float *temp)
 convert the register data to the alarm temperature
uint8_t ds18b20_init (ds18b20_handle_t *handle)
 initialize the chip
uint8_t ds18b20_deinit (ds18b20_handle_t *handle)
 close the chip
uint8_t ds18b20_read (ds18b20_handle_t *handle, int16_t *raw, float *temp)
 read data from the chip
uint8_t ds18b20_search_rom (ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
 search the ds18b20 rom
uint8_t ds18b20_search_alarm (ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
 search the ds18b20 alarm rom
uint8_t ds18b20_get_power_mode (ds18b20_handle_t *handle, ds18b20_power_mode_t *power_mode)
 get the power mode
uint8_t ds18b20_info (ds18b20_info_t *info)
 get chip's information

Variables

const uint8_t gc_ds18b20_crc_table [256]
 crc table

Detailed Description

driver ds18b20 source file

Copyright (c) 2015 - present LibDriver All rights reserved

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Version
2.0.0
Author
Shifeng Li
Date
2021-04-06

history

Date Version Author Description
2021/04/06 2.0 Shifeng Li format the code
2020/12/20 1.0 Shifeng Li first upload

Definition in file driver_ds18b20.c.

Macro Definition Documentation

◆ CHIP_NAME

#define CHIP_NAME   "Maxim Integrated DS18B20"

chip information definition

chip name

Definition at line 43 of file driver_ds18b20.c.

◆ DRIVER_VERSION

#define DRIVER_VERSION   2000

driver version

Definition at line 50 of file driver_ds18b20.c.

◆ DS18B20_CMD_ALARM_SEARCH

#define DS18B20_CMD_ALARM_SEARCH   0xEC

alarm search command

Definition at line 59 of file driver_ds18b20.c.

◆ DS18B20_CMD_CONVERT_T

#define DS18B20_CMD_CONVERT_T   0x44

convert command

Definition at line 60 of file driver_ds18b20.c.

◆ DS18B20_CMD_COPY_SCRATCHPAD

#define DS18B20_CMD_COPY_SCRATCHPAD   0x48

copy scratchpad command

Definition at line 63 of file driver_ds18b20.c.

◆ DS18B20_CMD_MATCH_ROM

#define DS18B20_CMD_MATCH_ROM   0x55

match rom command

Definition at line 57 of file driver_ds18b20.c.

◆ DS18B20_CMD_READ_POWER_SUPPLY

#define DS18B20_CMD_READ_POWER_SUPPLY   0xB4

read power supply command

Definition at line 65 of file driver_ds18b20.c.

◆ DS18B20_CMD_READ_ROM

#define DS18B20_CMD_READ_ROM   0x33

read rom command

Definition at line 56 of file driver_ds18b20.c.

◆ DS18B20_CMD_READ_SCRATCHPAD

#define DS18B20_CMD_READ_SCRATCHPAD   0xBE

read scratchpad command

Definition at line 62 of file driver_ds18b20.c.

◆ DS18B20_CMD_RECALL_EE

#define DS18B20_CMD_RECALL_EE   0xB8

recall ee command

Definition at line 64 of file driver_ds18b20.c.

◆ DS18B20_CMD_SEARCH_ROM

#define DS18B20_CMD_SEARCH_ROM   0xF0

chip command definition

search rom command

Definition at line 55 of file driver_ds18b20.c.

◆ DS18B20_CMD_SKIP_ROM

#define DS18B20_CMD_SKIP_ROM   0xCC

skip rom command

Definition at line 58 of file driver_ds18b20.c.

◆ DS18B20_CMD_WRITE_SCRATCHPAD

#define DS18B20_CMD_WRITE_SCRATCHPAD   0x4E

write scratchpad command

Definition at line 61 of file driver_ds18b20.c.

◆ MANUFACTURER_NAME

#define MANUFACTURER_NAME   "Maxim Integrated"

manufacturer name

Definition at line 44 of file driver_ds18b20.c.

◆ MAX_CURRENT

#define MAX_CURRENT   4.0f

chip max current

Definition at line 47 of file driver_ds18b20.c.

◆ SUPPLY_VOLTAGE_MAX

#define SUPPLY_VOLTAGE_MAX   5.5f

chip max supply voltage

Definition at line 46 of file driver_ds18b20.c.

◆ SUPPLY_VOLTAGE_MIN

#define SUPPLY_VOLTAGE_MIN   3.0f

chip min supply voltage

Definition at line 45 of file driver_ds18b20.c.

◆ TEMPERATURE_MAX

#define TEMPERATURE_MAX   125.0f

chip max operating temperature

Definition at line 49 of file driver_ds18b20.c.

◆ TEMPERATURE_MIN

#define TEMPERATURE_MIN   -55.0f

chip min operating temperature

Definition at line 48 of file driver_ds18b20.c.

Variable Documentation

◆ gc_ds18b20_crc_table

const uint8_t gc_ds18b20_crc_table[256]
Initial value:
=
{
0X00, 0X5E, 0XBC, 0XE2, 0X61, 0X3F, 0XDD, 0X83, 0XC2, 0X9C, 0X7E, 0X20, 0XA3,
0XFD, 0X1F, 0X41, 0X9D, 0XC3, 0X21, 0X7F, 0XFC, 0XA2, 0X40, 0X1E, 0X5F, 0X01,
0XE3, 0XBD, 0X3E, 0X60, 0X82, 0XDC, 0X23, 0X7D, 0X9F, 0XC1, 0X42, 0X1C, 0XFE,
0XA0, 0XE1, 0XBF, 0X5D, 0X03, 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B, 0X88, 0XD6, 0X34, 0X6A, 0X2B, 0X75,
0X97, 0XC9, 0X4A, 0X14, 0XF6, 0XA8, 0X74, 0X2A, 0XC8, 0X96, 0X15, 0X4B, 0XA9,
0XF7, 0XB6, 0XE8, 0X0A, 0X54, 0XD7, 0X89, 0X6B, 0X35,
}

crc table

Definition at line 70 of file driver_ds18b20.c.