Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_ow2482.h
Go to the documentation of this file.
1 
69 #ifndef NZ_OW2482_H
70 #define NZ_OW2482_H
71 
72 #if defined(NZ_OW2482_ENABLED)
73 
75 
76 //Default address is 0x30. This is the case if both AD0 and AD1 pins of the DS2482
77 //are tied to 0V. By connecting AD0, AD1, or both AD0 and AD1 to Vcc, the address
78 //could also be 0x31, 0x32 or 0x33
79 #define DS2482_ADDRESS_00 0x30 //DS2482 address if AD0=0V and AD1=0V
80 #define DS2482_ADDRESS_01 0x31 //DS2482 address if AD0=Vcc and AD1=0V
81 #define DS2482_ADDRESS_10 0x32 //DS2482 address if AD0=0V and AD1=Vcc
82 #define DS2482_ADDRESS_11 0x33 //DS2482 address if AD0=Vcc and AD1=Vcc
83 
84 #define DS2482_COMMAND_RESET 0xF0 //Device Reset command
85 #define DS2482_COMMAND_WR_CONF 0xD2 //Write Configuration command
86 #define DS2482_COMMAND_SET_RD_PTR 0xE1 //Set Read Pointer command
87 #define DS2482_COMMAND_1W_RESET 0xB4 //1-Wire Reset command
88 #define DS2482_COMMAND_1W_WR_BYTE 0xA5 //1-Wire Write Byte command
89 #define DS2482_COMMAND_1W_RD_BYTE 0x96 //1-Wire Read Byte command
90 #define DS2482_COMMAND_1W_SINGLE_BIT 0x87 //1-Wire Single Bit command
91 #define DS2482_COMMAND_1W_TRIPLET 0x78 //1-Wire Triplet command
92 
93 #define DS2482_CONFIG_APU 0x01 //Active Pullup enabled
94 #define DS2482_CONFIG_PPM 0x02 //Presence-Pulse Masking enabled
95 #define DS2482_CONFIG_SPU 0x04 //Strong Pullup enabled
96 #define DS2482_CONFIG_1WS 0x08 //1-Wire Speed High Speed enabled
97 
98 #define DS2482_STATUS_1WB 0x01 //1-Wire Busy
99 #define DS2482_STATUS_PPD 0x02 //Presence-Pulse Detect
100 #define DS2482_STATUS_SD 0x04 //Short Detected
101 #define DS2482_STATUS_LL 0x08 //Logic Level
102 #define DS2482_STATUS_RST 0x10 //Device Reset
103 #define DS2482_STATUS_SBR 0x20 //Single Bit Result
104 #define DS2482_STATUS_TSB 0x40 //Triplet Second Bit
105 #define DS2482_STATUS_DIR 0x80 //Branch Direction Taken
106 
107 #define DS2482_TIMEOUT 100 //100ms
108 
109 typedef struct DS2482_INFO_
110 //typedef struct __attribute__((__packed__)) DS2482_INFO_
111 //typedef struct __attribute__((aligned(2), packed)) DS2482_INFO_
112 {
113  void* pI2CInfo; //Pointer to I2C_INFO structure of I2C bus used for this DS2482
114  WORD timeout;
115  BYTE sm;
116  BYTE i2cAdr; //The I2C address of this DS2482. Use a DS2482_ADDRESS_xx define
117  BYTE status; //The status of the last transmission, 0=Success, 0xff=Busy, else error code
118  BYTE readByte; //Byte read from DS2482
119  BYTE param; //Parameter used for passing data between states
120 
121  //Required for search
122  BYTE adr64[8];
123  BYTE lastDiscrepancy;
124  BYTE lastFamilyDiscrepancy;
125  BYTE idBitNumber;
126  BYTE lastZero;
127  BYTE romByteNnumber;
128  BYTE romByteMask;
129 
130  BYTE crc8;
131 
132  union {
133  struct
134  {
135  unsigned char lastDevice : 1;
136  unsigned char searchResult : 1;
137  unsigned char idBit : 1;
138  unsigned char cmpIdBit : 1;
139  unsigned char searchDirection : 1;
140  } flags;
141  BYTE flagsVal;
142  };
143 
144  //The DS2482 status register
145  union {
146  struct
147  {
148  unsigned int OWB : 1; //1-Wire Busy
149  unsigned int PPD : 1; //Presence-Pulse Detect
150  unsigned int SD : 1; //Short Detected
151  unsigned int LL : 1; //Logic Level
152  unsigned int RST : 1; //Device Reset
153  unsigned int SBR : 1; //Single Bit Result
154  unsigned int TSB : 1; //Triplet Second Bit
155  unsigned int DIR : 1; //Branch Direction Taken
156  } statusReg;
157  BYTE statusRegVal;
158  };
159 
160  union {
161  struct
162  {
163  unsigned int APU : 1; //Active Pullup = Bit 0 of Configuration Register
164  unsigned int PPM : 1; //Presence-Pulse Masking = Bit 1 of Configuration Register
165  unsigned int SPU : 1; //Strong Pullup = Bit 2 of Configuration Register
166  unsigned int OWS : 1; //1-Wire Speed = Bit 3 of Configuration Register
167  unsigned int fill : 4; //Fill
168  } configReg;
169  BYTE configRegVal;
170  };
171 } DS2482_INFO;
172 
173 
175 
192 BYTE ds2482_init(DS2482_INFO* pObj, BYTE i2cBus, BYTE i2cAdr);
193 
194 
200 void ds2482_task(DS2482_INFO* pObj);
201 
202 
211 #define ds2482_isBusy(pObj) ((pObj)->sm!=0)
212 
223 #define ds2482_getStatus(pObj) ((pObj)->status)
224 
232 BYTE ds2482_getStatusWait(DS2482_INFO* pObj);
233 
234 
235 #define ds2482_resetStatus(pObj) ((pObj)->status = 0)
236 
244 #define ds2482_getStatusReg(pObj) ((pObj)->statusRegVal)
245 
258 #define ds2482_getStatusRegPPD(pObj) ((pObj)->statusReg.PPD)
259 
271 #define ds2482_getStatusRegSD(pObj) ((pObj)->statusReg.SD)
272 
273 
286 BOOL ds2482_reset(DS2482_INFO* pObj);
287 
288 
302 BOOL ds2482_writeConfig(DS2482_INFO* pObj, BYTE config);
303 
304 
324 BYTE owReset(DS2482_INFO* pObj);
325 
342 BYTE owResetWATE(DS2482_INFO* pObj);
343 
344 
359 BYTE owReadWriteBit(DS2482_INFO* pObj, BOOL bVal);
360 
366 #define owGetBit(pObj) ((pObj)->statusReg.SBR)
367 
368 
374 #define owGetByte(pObj) ((pObj)->readByte)
375 
376 
389 BYTE owReadByte(DS2482_INFO* pObj);
390 
408 BYTE owReadByteWATE(DS2482_INFO* pObj);
409 
410 
425 BYTE owWriteByte(DS2482_INFO* pObj, BYTE val);
426 
427 
445 BYTE owWriteByteWATE(DS2482_INFO* pObj, BYTE val);
446 
447 
466 BYTE owWriteBytePower(DS2482_INFO* pObj, BYTE val);
467 
468 
486 BYTE owWriteBytePowerWATE(DS2482_INFO* pObj, BYTE val);
487 
488 
504 BYTE owSpeed(DS2482_INFO* pObj, BOOL speed);
505 
506 
526 BYTE owLevel(DS2482_INFO* pObj, BOOL level);
527 
528 
532 void owSearchReset(DS2482_INFO* pObj);
533 
534 
553 BOOL owSearch(DS2482_INFO* pObj);
554 
555 
575 BYTE* owSearchWATE(DS2482_INFO* pObj);
576 
577 
586 #define owGetAdr64(pObj) (pObj->flags.searchResult?pObj->adr64:0)
587 
588 
604 BYTE owSelect(DS2482_INFO* pObj, BYTE* adr64);
605 
606 
624 BYTE owSelectWATE(DS2482_INFO* pObj, BYTE* adr64);
625 
626 #endif //#if defined(NZ_OW2482_ENABLED)
627 #endif //#ifndef NZ_OW2482_H