?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik //*****************************************************************************
2 // File Name : dallas.c
3 // Title : Dallas 1-Wire Library
4 // Revision : 6
5 // Notes :
6 // Target MCU : Atmel AVR series
7 // Editor Tabs : 4
8 //
9 // Revision History:
10 // When Who Rev Description of change
11 // ----------- ----------- ------- -----------------------
12 // 24-Sep-2003 rwatson 6 Created AddressCheck, WaitUntilDone
13 // 23-Sep-2003 rwatson 5 Created ReadRAM, WriteRAM, PrintError, PrintROM
14 // 22-Sep-2003 rwatson 4 Created MatchROM, PrintROM
15 // 21-Sep-2003 rwatson 3 Created ReadROM, FindDevices, FindNextDevice, CRC
16 // 20-Sep-2003 rwatson 2 Created ReadBit, WriteBit, ReadByte, WriteByte, Reset
17 // 20-Sep-2003 rwatson 1 Created the program structure
18 //*****************************************************************************
19  
20 #ifndef dallas_h
21 #define dallas_h
22  
23 //----- Include Files ---------------------------------------------------------
24 #include "global.h"
25  
26 //----- Defines ---------------------------------------------------------------
27 #define dallas_rev 6
28  
29 // include configuration
30 #include "dallasconf.h"
31  
32 // define the max number devices on
33 // the bus if it isn't defined yet
34 #ifndef DALLAS_MAX_DEVICES
35 #define DALLAS_MAX_DEVICES 20
36 #endif
37  
38 // indexes of named bytes in the
39 // dallas address array
40 #define DALLAS_FAMILY_IDX 0 // family code
41 #define DALLAS_A0_IDX 1
42 #define DALLAS_A1_IDX 2
43 #define DALLAS_A2_IDX 3
44 #define DALLAS_A3_IDX 4
45 #define DALLAS_A4_IDX 5
46 #define DALLAS_A5_IDX 6
47 #define DALLAS_CRC_IDX 7 // crc code
48  
49 // dallas return error codes
50 #define DALLAS_NO_ERROR 0 // all is well
51 #define DALLAS_PRESENCE 'h' // presence was detected
52 #define DALLAS_NO_PRESENCE 'g' // presence wasn't detected
53 #define DALLAS_VERIFY_ERROR 'v' // setup verification failed
54 #define DALLAS_ADDRESS_ERROR 'a' // bad address for command: either wrong family or bad CRC
55 #define DALLAS_CRC_ERROR 'c' // data/return value fails CRC check
56 #define DALLAS_DEVICE_ERROR 'd' // device not responding
57 #define DALLAS_NULL_POINTER 'p' // dallas function passed a NULL pointer
58 #define DALLAS_ZERO_LEN 'z' // ReadRAM or WriteRAM asked to read/write zero bytes
59 #define DALLAS_BUS_ERROR 'b' // Bus hardware error. (wrong voltage) Possible causes:
60 // - lack of pullup Resistor
61 // - Other master transmitting (Dallas is not multi-master)
62 // - Device failure
63 // ds2450 and ds18b20 errors
64 // defined here to work with PrintError
65 #define DALLAS_RESOLUTION_ERROR 'r' // invalid resolution specified in Dallas function
66 #define DALLAS_INVALID_CHANNEL 'i' // channel outside the range 'A' to 'D'
67 #define DALLAS_FORMAT_ERROR 'f' // results are not in a valid format (temp sensor)
68  
69 // ROM commands
70 #define DALLAS_READ_ROM 0x33
71 #define DALLAS_MATCH_ROM 0x55
72 #define DALLAS_SKIP_ROM 0xCC
73 #define DALLAS_SEARCH_ROM 0xF0
74 #define DALLAS_CONDITIONAL_SEARCH 0xEC
75 #define DALLAS_READ_MEMORY 0xAA
76 #define DALLAS_WRITE_MEMORY 0x55
77  
78 //----- Typedefs --------------------------------------------------------------
79  
80 // typedef for the rom IDs
81 // done so we can access the entire id or each individual byte
82 typedef union dallas_rom_id_U
83 {
84 long long id;
85 u08 byte[8];
86 } dallas_rom_id_T;
87  
88 //----- Functions ---------------------------------------------------------------
89  
90 // dallasInit()
91 // Initializes the Dallas 1-wire Bus
92 // Currently this function does nothing
93 void dallasInit(void);
94  
95 // dallasReset()
96 // performs a reset on the 1-wire bus
97 // returns the presence detect (DALLAS_PRESENCE or DALLAS_NO_PRESENCE)
98 u08 dallasReset(void);
99  
100 // dallasReadBit()
101 // reads a bit from the 1-wire bus and returns this bit
102 // note: global interupts are not disabled in this function
103 // if using this function, use cli() and sei() before and after
104 u08 dallasReadBit(void);
105  
106 // dallasWriteBit()
107 // writes the passed in bit to the 1-wire bus
108 // note: global interupts are not disabled in this function
109 // if using this function, use cli() and sei() before and after
110 void dallasWriteBit(u08 bit);
111  
112 // dallasReadByte()
113 // reads a byte from the 1-wire bus and returns this byte
114 // note: global interupts are disabled in this function
115 u08 dallasReadByte(void);
116  
117 // dallasWriteByte()
118 // writes the passed in byte to the 1-wire bus
119 // note: global interupts are disabled in this function.
120 void dallasWriteByte(u08 byte);
121  
122 // dallasReadRAM()
123 // reads the RAM from the specified device, at the specified RAM address
124 // for the specified length. Data is stored into data variable
125 u08 dallasReadRAM(dallas_rom_id_T* rom_id, u16 addr, u08 len, u08 *data);
126  
127 // dallasWriteRAM()
128 // writes the specified data for the specified length to the RAM
129 // located at the specified address of the specified device
130 u08 dallasWriteRAM(dallas_rom_id_T* rom_id, u16 address, u08 len, u08* data);
131  
132 // dallasWaitUntilDone()
133 // waits until the conversion of a dallas device is done
134 void dallasWaitUntilDone(void);
135  
136 // dallasReadROM()
137 // finds the ROM code of a device if only 1 device is
138 // connected to the bus the ROM value is passed by referenced
139 // returns any error that occured or DALLAS_NO_ERROR
140 u08 dallasReadROM(dallas_rom_id_T* rom_id);
141  
142 // dallasMatchROM()
143 // performs a reset on the 1-wire bus and then
144 // selects the specified dallas device on the network
145 // returns any error that occured or DALLAS_NO_ERROR
146 u08 dallasMatchROM(dallas_rom_id_T* rom_id);
147  
148 // dallasPrintROM
149 // prints the ROM from MSB to LSB in the format: xx xx xx xx xx xx xx xx
150 void dallasPrintROM(dallas_rom_id_T* rom_id);
151  
152 // dallasAddressCheck()
153 // checks to make sure that the rom id is in the proper family,
154 // and if the crc of the id is correct
155 // returns the corresponding error or DALLAS_NO_ERROR
156 u08 dallasAddressCheck(dallas_rom_id_T* rom_id, u08 family);
157  
158 // dallasCRC()
159 // calculates the CRC from the lookup table
160 // returns the new crc value, which is also a global variable
161 u08 dallasCRC(u08 i);
162  
163 // dallasFindDevices()
164 // finds all the devices on the network, or up to the maximum defined value
165 // stores the ids in the given array, and returns the number of devices found
166 u08 dallasFindDevices(dallas_rom_id_T rom_id[]);
167  
168 // dallasPrintError()
169 // prints the error value as well as an error message if there was an error
170 // if DALLAS_NO_ERROR is passed in, nothing is done
171 void dallasPrintError(u08 error);
172  
173 #endif
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3