-
Notifications
You must be signed in to change notification settings - Fork 1
/
onewire.h
94 lines (71 loc) · 2.68 KB
/
onewire.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef ONEWIRE_H_
#define ONEWIRE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/*******************************************/
/* Hardware connection */
/*******************************************/
/* Define OW_ONE_BUS if only one 1-Wire-Bus is used
in the application -> shorter code.
If not defined make sure to call ow_set_bus() before using
a bus. Runtime bus-select increases code size by around 300
bytes so use OW_ONE_BUS if possible */
#define OW_ONE_BUS
#ifdef OW_ONE_BUS
#define OW_PIN PD2
#define OW_IN PIND
#define OW_OUT PORTD
#define OW_DDR DDRD
#define OW_CONF_DELAYOFFSET 0
#else
#if ( F_CPU < 1843200 )
#warning | Experimental multi-bus-mode is not tested for
#warning | frequencies below 1,84MHz. Use OW_ONE_WIRE or
#warning | faster clock-source (i.e. internal 2MHz R/C-Osc.).
#endif
#define OW_CONF_CYCLESPERACCESS 13
#define OW_CONF_DELAYOFFSET ( (uint16_t)( ((OW_CONF_CYCLESPERACCESS) * 1000000L) / F_CPU ) )
#endif
// Recovery time (T_Rec) minimum 1usec - increase for long lines
// 5 usecs is a value give in some Maxim AppNotes
// 30u secs seem to be reliable for longer lines
//#define OW_RECOVERY_TIME 5 /* usec */
//#define OW_RECOVERY_TIME 300 /* usec */
#define OW_RECOVERY_TIME 10 /* usec */
// Use AVR's internal pull-up resistor instead of external 4,7k resistor.
// Based on information from Sascha Schade. Experimental but worked in tests
// with one DS18B20 and one DS18S20 on a rather short bus (60cm), where both
// sensores have been parasite-powered.
#define OW_USE_INTERNAL_PULLUP 1 /* 0=external, 1=internal */
/*******************************************/
#define OW_MATCH_ROM 0x55
#define OW_SKIP_ROM 0xCC
#define OW_SEARCH_ROM 0xF0
#define OW_SEARCH_FIRST 0xFF // start new search
#define OW_PRESENCE_ERR 0xFF
#define OW_DATA_ERR 0xFE
#define OW_LAST_DEVICE 0x00 // last device found
// rom-code size including CRC
#define OW_ROMCODE_SIZE 8
extern uint8_t ow_reset(void);
extern uint8_t ow_bit_io( uint8_t b );
extern uint8_t ow_byte_wr( uint8_t b );
extern uint8_t ow_byte_rd( void );
extern uint8_t ow_rom_search( uint8_t diff, uint8_t *id );
extern void ow_command( uint8_t command, uint8_t *id );
extern void ow_command_with_parasite_enable( uint8_t command, uint8_t *id );
extern void ow_parasite_enable( void );
extern void ow_parasite_disable( void );
extern uint8_t ow_input_pin_state( void );
#ifndef OW_ONE_BUS
extern void ow_set_bus( volatile uint8_t* in,
volatile uint8_t* out,
volatile uint8_t* ddr,
uint8_t pin );
#endif
#ifdef __cplusplus
}
#endif
#endif