comparison onewire.h @ 0:8705acff2494

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