OWI.h File Reference


Detailed Description

Header file for OWI.c.

Contains definitions used in the polled 1-Wire(R) driver.

Application Note:
AVR458: Charging Li-Ion Batteries with BC100
AVR463: Charging NiMH Batteries with BC100
One-wire protocol based on AVR318 - Dallas 1-Wire(R) master.
Documentation:
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Original author:
$Name$
Revision
2335
$RCSfile$
URL
http://revisor.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/trunk/code/IAR/OWI.h
Date
2007-09-07 10:11:19 +0200 (fr, 07 sep 2007)

Definition in file OWI.h.

#include <ioavr.h>

Include dependency graph for OWI.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define CPU_FREQUENCY   8.000
 CPU clock frequency.
#define OWI_CRC_ERROR   0x01
 CRC check failed.
#define OWI_CRC_OK   0x00
 CRC check succeded.
#define OWI_DDR   DDRA
 1-Wire Data direction register.
#define OWI_DELAY_A_STD_MODE   (unsigned long)((6 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_B_STD_MODE   (unsigned long)((64 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_C_STD_MODE   (unsigned long)((60 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_D_STD_MODE   (unsigned long)((10 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_E_STD_MODE   (unsigned long)((9 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_F_STD_MODE   (unsigned long)((55 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_H_STD_MODE   (unsigned long)((480 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_I_STD_MODE   (unsigned long)((70 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_J_STD_MODE   (unsigned long)((410 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
#define OWI_DELAY_OFFSET_CYCLES   13
 Timing delay when pulling bus low and releasing bus.
#define OWI_PIN   PINA
 1-Wire Input pin register.
#define OWI_PIN_0   0x01
#define OWI_PIN_1   0x02
#define OWI_PIN_2   0x04
#define OWI_PIN_3   0x08
#define OWI_PIN_4   0x10
#define OWI_PIN_5   0x20
#define OWI_PIN_6   0x40
#define OWI_PIN_7   0x80
#define OWI_PORT   PORTA
 Use internal pull-up resistor on 1-Wire buses.
#define OWI_PULL_BUS_LOW(bitMask)
 Pull 1-Wire bus low.
#define OWI_RELEASE_BUS(bitMask)
 Release the bus.
#define OWI_ROM_MATCH   0x55
 MATCH ROM command code.
#define OWI_ROM_READ   0x33
 READ ROM command code.
#define OWI_ROM_SEARCH   0xf0
 SEARCH ROM command code.
#define OWI_ROM_SEARCH_FAILED   0xff
 Search failed return code.
#define OWI_ROM_SEARCH_FINISHED   0x00
 Search finished return code.
#define OWI_ROM_SKIP   0xcc
 SKIP ROM command code.

Functions

unsigned char OWI_CheckRomCRC (unsigned char *romValue)
 Calculate and check the CRC of a 64 bit ROM identifier.
unsigned int OWI_ComputeCRC16 (unsigned char inData, unsigned int seed)
 Compute the CRC16 value of a data set.
unsigned char OWI_ComputeCRC8 (unsigned char inData, unsigned char seed)
 Compute the CRC8 value of a data set.
unsigned char OWI_DetectPresence (unsigned char pins)
 Send a Reset signal and listen for Presence signal. (software only driver).
void OWI_Init (unsigned char pins)
 Initialization of the one wire bus(es). (Software only driver).
void OWI_MatchRom (unsigned char *romValue, unsigned char pins)
 Sends the MATCH ROM command and the ROM id to match against.
unsigned char OWI_ReadBit (unsigned char pins)
 Read a bit from the bus(es). (Software only driver).
void OWI_ReadRom (unsigned char *romValue, unsigned char pin)
 Sends the READ ROM command and reads back the ROM id.
unsigned char OWI_ReceiveByte (unsigned char pin)
 Receives one byte of data from the 1-Wire(R) bus.
unsigned char OWI_SearchRom (unsigned char *bitPattern, unsigned char lastDeviation, unsigned char pin)
 Sends the SEARCH ROM command and returns 1 id found on the 1-Wire(R) bus.
void OWI_SendByte (unsigned char data, unsigned char pins)
 Sends one byte of data on the 1-Wire(R) bus(es).
void OWI_SkipRom (unsigned char pins)
 Sends the SKIP ROM command to the 1-Wire bus(es).
void OWI_WriteBit0 (unsigned char pins)
 Write a '0' to the bus(es). (Software only driver).
void OWI_WriteBit1 (unsigned char pins)
 Write a '1' bit to the bus(es). (Software only driver).


Define Documentation

#define CPU_FREQUENCY   8.000

CPU clock frequency.

This define is used to calculate delays when the software only driver is used. The CPU frequency must be at least 2.170 MHz to be able to generate the shortest delays.

Definition at line 52 of file OWI.h.

#define OWI_CRC_ERROR   0x01

CRC check failed.

Definition at line 40 of file OWI.h.

Referenced by OWI_CheckRomCRC().

#define OWI_CRC_OK   0x00

CRC check succeded.

Definition at line 39 of file OWI.h.

Referenced by OWI_CheckRomCRC().

#define OWI_DDR   DDRA

1-Wire Data direction register.

Definition at line 68 of file OWI.h.

#define OWI_DELAY_A_STD_MODE   (unsigned long)((6 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 91 of file OWI.h.

Referenced by OWI_ReadBit(), and OWI_WriteBit1().

#define OWI_DELAY_B_STD_MODE   (unsigned long)((64 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 92 of file OWI.h.

Referenced by OWI_WriteBit1().

#define OWI_DELAY_C_STD_MODE   (unsigned long)((60 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 93 of file OWI.h.

Referenced by OWI_WriteBit0().

#define OWI_DELAY_D_STD_MODE   (unsigned long)((10 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 94 of file OWI.h.

Referenced by OWI_WriteBit0().

#define OWI_DELAY_E_STD_MODE   (unsigned long)((9 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 95 of file OWI.h.

Referenced by OWI_ReadBit().

#define OWI_DELAY_F_STD_MODE   (unsigned long)((55 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 96 of file OWI.h.

Referenced by OWI_ReadBit().

#define OWI_DELAY_H_STD_MODE   (unsigned long)((480 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 98 of file OWI.h.

Referenced by OWI_DetectPresence(), and OWI_Init().

#define OWI_DELAY_I_STD_MODE   (unsigned long)((70 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 99 of file OWI.h.

Referenced by OWI_DetectPresence().

#define OWI_DELAY_J_STD_MODE   (unsigned long)((410 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)

Definition at line 100 of file OWI.h.

Referenced by OWI_DetectPresence().

#define OWI_DELAY_OFFSET_CYCLES   13

Timing delay when pulling bus low and releasing bus.

Definition at line 88 of file OWI.h.

#define OWI_PIN   PINA

1-Wire Input pin register.

Definition at line 67 of file OWI.h.

Referenced by OWI_DetectPresence(), and OWI_ReadBit().

#define OWI_PIN_0   0x01

Definition at line 74 of file OWI.h.

#define OWI_PIN_1   0x02

Definition at line 75 of file OWI.h.

#define OWI_PIN_2   0x04

Definition at line 76 of file OWI.h.

#define OWI_PIN_3   0x08

Definition at line 77 of file OWI.h.

#define OWI_PIN_4   0x10

Definition at line 78 of file OWI.h.

#define OWI_PIN_5   0x20

Definition at line 79 of file OWI.h.

#define OWI_PIN_6   0x40

Definition at line 80 of file OWI.h.

#define OWI_PIN_7   0x80

Definition at line 81 of file OWI.h.

#define OWI_PORT   PORTA

Use internal pull-up resistor on 1-Wire buses.

If this symbol is defined, the internal pull-up resister on the GPIO pins of the AVR will be used to generate the necessary pull-up on the bus. If an external pull-up resistor is used, uncomment this define. 1-Wire PORT Data register.

Definition at line 66 of file OWI.h.

#define OWI_PULL_BUS_LOW ( bitMask   ) 

Value:

OWI_DDR |= (bitMask); \
                        OWI_PORT &= ~(bitMask)
Pull 1-Wire bus low.

This macro sets the direction of the 1-Wire pin(s) to output and pull the line(s) low.

Parameters:
bitMask A bitmask of the buses to pull low.

Definition at line 129 of file OWI.h.

Referenced by OWI_DetectPresence(), OWI_ReadBit(), OWI_WriteBit0(), and OWI_WriteBit1().

#define OWI_RELEASE_BUS ( bitMask   ) 

Value:

OWI_DDR &= ~(bitMask); \
                        OWI_PORT &= ~(bitMask)
Release the bus.

This macro releases the bus and enables the internal pull-up if it is used.

Parameters:
bitMask A bitmask of the buses to release.

Definition at line 151 of file OWI.h.

Referenced by OWI_DetectPresence(), OWI_Init(), OWI_ReadBit(), OWI_WriteBit0(), and OWI_WriteBit1().

#define OWI_ROM_MATCH   0x55

MATCH ROM command code.

Definition at line 108 of file OWI.h.

Referenced by OWI_MatchRom().

#define OWI_ROM_READ   0x33

READ ROM command code.

Definition at line 106 of file OWI.h.

Referenced by BatteryDataRefresh(), and OWI_ReadRom().

#define OWI_ROM_SEARCH   0xf0

SEARCH ROM command code.

Definition at line 109 of file OWI.h.

Referenced by OWI_SearchRom().

#define OWI_ROM_SEARCH_FAILED   0xff

Search failed return code.

Definition at line 116 of file OWI.h.

Referenced by OWI_SearchRom().

#define OWI_ROM_SEARCH_FINISHED   0x00

Search finished return code.

Definition at line 115 of file OWI.h.

#define OWI_ROM_SKIP   0xcc

SKIP ROM command code.

Definition at line 107 of file OWI.h.

Referenced by OWI_SkipRom().


Function Documentation

unsigned char OWI_CheckRomCRC ( unsigned char *  romValue  ) 

Calculate and check the CRC of a 64 bit ROM identifier.

This function computes the CRC8 value of the first 56 bits of a 64 bit identifier. It then checks the calculated value against the CRC value stored in ROM.

Parameters:
*romValue A pointer to an array holding a 64 bit identifier.
Return values:
OWI_CRC_OK The CRC's matched.
OWI_CRC_ERROR Calculated and stored CRC did not match.

Definition at line 501 of file OWI.c.

References OWI_ComputeCRC8(), OWI_CRC_ERROR, and OWI_CRC_OK.

00502 {
00503         unsigned char i;
00504         unsigned char crc8 = 0;
00505         
00506         for (i = 0; i < 7; i++) {
00507                 crc8 = OWI_ComputeCRC8(*romValue, crc8);
00508                 romValue++;
00509         }
00510         
00511         if (crc8 == (*romValue)) {
00512                 return OWI_CRC_OK;
00513         }
00514         
00515         return OWI_CRC_ERROR;
00516 }

Here is the call graph for this function:

unsigned int OWI_ComputeCRC16 ( unsigned char  inData,
unsigned int  seed 
)

Compute the CRC16 value of a data set.

This function will compute the CRC16 of inData using seed as inital value for the CRC.

Parameters:
inData One byte of data to compute CRC from.
seed The starting value of the CRC.
Returns:
The CRC16 of inData with seed as initial value.
Note:
Setting seed to 0 computes the crc16 of the inData.

Constantly passing the return value of this function As the seed argument computes the CRC16 value of a longer string of data.

Definition at line 467 of file OWI.c.

00468 {
00469         unsigned char bitsLeft;
00470         unsigned char temp;
00471         
00472         for (bitsLeft = 8; bitsLeft > 0; bitsLeft--) {
00473                 temp = ((seed ^ inData) & 0x01);
00474                 
00475                 if (temp == 0) {
00476                         seed >>= 1;
00477           } else {
00478                         seed ^= 0x4002;
00479                         seed >>= 1;
00480                         seed |= 0x8000;
00481                 }
00482 
00483                 inData >>= 1;
00484         }
00485         
00486         return seed;    
00487 }

unsigned char OWI_ComputeCRC8 ( unsigned char  inData,
unsigned char  seed 
)

Compute the CRC8 value of a data set.

This function will compute the CRC8 or DOW-CRC of inData using seed as inital value for the CRC.

Parameters:
inData One byte of data to compute CRC from.
seed The starting value of the CRC.
Returns:
The CRC8 of inData with seed as initial value.
Note:
Setting seed to 0 computes the crc8 of the inData.

Constantly passing the return value of this function As the seed argument computes the CRC8 value of a longer string of data.

Definition at line 428 of file OWI.c.

Referenced by BatteryDataRefresh(), and OWI_CheckRomCRC().

00429 {
00430         unsigned char bitsLeft;
00431         unsigned char temp;
00432         
00433         for (bitsLeft = 8; bitsLeft > 0; bitsLeft--) {
00434                 temp = ((seed ^ inData) & 0x01);
00435                 
00436                 if (temp == 0) {
00437                 seed >>= 1;
00438                 } else {
00439                         seed ^= 0x18;
00440                         seed >>= 1;
00441                         seed |= 0x80;
00442                 }
00443                 
00444                 inData >>= 1;
00445         }
00446         return seed;    
00447 }

unsigned char OWI_DetectPresence ( unsigned char  pins  ) 

Send a Reset signal and listen for Presence signal. (software only driver).

Generates the waveform for transmission of a Reset pulse on the 1-Wire(R) bus and listens for presence signals.

Parameters:
pins A bitmask of the buses to send the Reset signal on.
Returns:
A bitmask of the buses where a presence signal was detected.

Definition at line 160 of file OWI.c.

References OWI_DELAY_H_STD_MODE, OWI_DELAY_I_STD_MODE, OWI_DELAY_J_STD_MODE, OWI_PIN, OWI_PULL_BUS_LOW, and OWI_RELEASE_BUS.

Referenced by BatteryDataRefresh().

00161 {
00162         unsigned char intState;
00163         unsigned char presenceDetected;
00164         
00165         // Disable interrupts.
00166         intState = __save_interrupt();
00167         __disable_interrupt();
00168         
00169         // Drive bus low and delay.
00170         OWI_PULL_BUS_LOW(pins);
00171         __delay_cycles(OWI_DELAY_H_STD_MODE);
00172         
00173         // Release bus and delay.
00174         OWI_RELEASE_BUS(pins);
00175         __delay_cycles(OWI_DELAY_I_STD_MODE);
00176         
00177         // Sample bus to detect presence signal and delay.
00178         presenceDetected = ((~OWI_PIN) & pins);
00179         __delay_cycles(OWI_DELAY_J_STD_MODE);
00180         
00181         // Restore interrupts.
00182         __restore_interrupt(intState);
00183         
00184         return presenceDetected;
00185 }

void OWI_Init ( unsigned char  pins  ) 

Initialization of the one wire bus(es). (Software only driver).

This function initializes the 1-Wire bus(es) by releasing it and waiting until any presence signals are finished.

Parameters:
pins A bitmask of the buses to initialize.

Definition at line 52 of file OWI.c.

References OWI_DELAY_H_STD_MODE, and OWI_RELEASE_BUS.

Referenced by Initialize().

00052                                  {
00053         OWI_RELEASE_BUS(pins);
00054         // The first rising edge can be interpreted by a slave as the end of a
00055         // Reset-pulse. Delay for the required reset recovery time (H) to be 
00056         // sure that the real reset is interpreted correctly.
00057         __delay_cycles(OWI_DELAY_H_STD_MODE);
00058 }

void OWI_MatchRom ( unsigned char *  romValue,
unsigned char  pins 
)

Sends the MATCH ROM command and the ROM id to match against.

Parameters:
romValue A pointer to the ID to match against.
pins A bitmask of the buses to perform the MATCH ROM command on.

Definition at line 291 of file OWI.c.

References OWI_ROM_MATCH, and OWI_SendByte().

00292 {
00293         unsigned char bytesLeft = 8;   
00294         
00295         // Send the MATCH ROM command.
00296         OWI_SendByte(OWI_ROM_MATCH, pins);
00297         
00298         // Do once for each byte.
00299         while (bytesLeft > 0) {
00300                 // Transmit 1 byte of the ID to match.
00301                 OWI_SendByte(*romValue++, pins);
00302                 bytesLeft--;
00303         }
00304 }

Here is the call graph for this function:

unsigned char OWI_ReadBit ( unsigned char  pins  ) 

Read a bit from the bus(es). (Software only driver).

Generates the waveform for reception of a bit on the 1-Wire(R) bus(es).

Parameters:
pins A bitmask of the bus(es) to read from.
Returns:
A bitmask of the buses where a '1' was read.

Definition at line 122 of file OWI.c.

References OWI_DELAY_A_STD_MODE, OWI_DELAY_E_STD_MODE, OWI_DELAY_F_STD_MODE, OWI_PIN, OWI_PULL_BUS_LOW, and OWI_RELEASE_BUS.

Referenced by OWI_ReceiveByte(), and OWI_SearchRom().

00123 {
00124         unsigned char intState;
00125         unsigned char bitsRead;
00126         
00127         // Disable interrupts.
00128         intState = __save_interrupt();
00129         __disable_interrupt();
00130         
00131         // Drive bus low and delay.
00132         OWI_PULL_BUS_LOW(pins);
00133         __delay_cycles(OWI_DELAY_A_STD_MODE);
00134         
00135         // Release bus and delay.
00136         OWI_RELEASE_BUS(pins);
00137         __delay_cycles(OWI_DELAY_E_STD_MODE);
00138         
00139         // Sample bus and delay.
00140         bitsRead = OWI_PIN & pins;
00141         __delay_cycles(OWI_DELAY_F_STD_MODE);
00142         
00143         // Restore interrupts.
00144         __restore_interrupt(intState);
00145         
00146         return bitsRead;
00147 }

void OWI_ReadRom ( unsigned char *  romValue,
unsigned char  pin 
)

Sends the READ ROM command and reads back the ROM id.

Parameters:
romValue A pointer where the id will be placed.
pin A bitmask of the bus to read from.

Definition at line 269 of file OWI.c.

References OWI_ReceiveByte(), OWI_ROM_READ, and OWI_SendByte().

00270 {
00271         unsigned char bytesLeft = 8;
00272         
00273         // Send the READ ROM command on the bus.
00274         OWI_SendByte(OWI_ROM_READ, pin);
00275         
00276         // Do 8 times.
00277         while (bytesLeft > 0) {
00278                 // Place the received data in memory.
00279                 *romValue++ = OWI_ReceiveByte(pin);
00280                 bytesLeft--;
00281         }
00282 }

Here is the call graph for this function:

unsigned char OWI_ReceiveByte ( unsigned char  pin  ) 

Receives one byte of data from the 1-Wire(R) bus.

This function automates the task of receiving a complete byte of data from the 1-Wire bus.

Parameters:
pin A bitmask of the bus to read from.
Returns:
The byte read from the bus.

Definition at line 228 of file OWI.c.

References OWI_ReadBit().

Referenced by BatteryDataRefresh(), and OWI_ReadRom().

00229 {
00230         unsigned char data;
00231         unsigned char i;
00232         
00233         // Clear the temporary input variable.
00234         data = 0x00;
00235         
00236         // Do once for each bit
00237         for (i = 0; i < 8; i++) {
00238                 // Shift temporary input variable right.
00239                 data >>= 1;
00240                 
00241                 // Set the MSB if a '1' value is read from the bus.
00242                 // Leave as it is ('0') else.
00243                 if (OWI_ReadBit(pin)) {
00244                         data |= 0x80;
00245                 }
00246         }
00247         
00248         return data;
00249 }

Here is the call graph for this function:

unsigned char OWI_SearchRom ( unsigned char *  bitPattern,
unsigned char  lastDeviation,
unsigned char  pin 
)

Sends the SEARCH ROM command and returns 1 id found on the 1-Wire(R) bus.

Parameters:
bitPattern A pointer to an 8 byte char array where the discovered identifier will be placed. When searching for several slaves, a copy of the last found identifier should be supplied in the array, or the search will fail.
lastDeviation The bit position where the algorithm made a choice the last time it was run. This argument should be 0 when a search is initiated. Supplying the return argument of this function when calling repeatedly will go through the complete slave search.
pin A bit-mask of the bus to perform a ROM search on.
Returns:
The last bit position where there was a discrepancy between slave addresses the last time this function was run. Returns OWI_ROM_SEARCH_FAILED if an error was detected (e.g. a device was connected to the bus during the search), or OWI_ROM_SEARCH_FINISHED when there are no more devices to be discovered.
Note:
See main.c for an example of how to utilize this function.

Definition at line 333 of file OWI.c.

References OWI_ReadBit(), OWI_ROM_SEARCH, OWI_ROM_SEARCH_FAILED, OWI_SendByte(), OWI_WriteBit0(), and OWI_WriteBit1().

00335 {
00336         unsigned char currentBit = 1;
00337         unsigned char newDeviation = 0;
00338         unsigned char bitMask = 0x01;
00339         unsigned char bitA;
00340         unsigned char bitB;
00341         
00342         // Send SEARCH ROM command on the bus.
00343         OWI_SendByte(OWI_ROM_SEARCH, pin);
00344         
00345         // Walk through all 64 bits.
00346         while (currentBit <= 64) {
00347                 // Read bit from bus twice.
00348                 bitA = OWI_ReadBit(pin);
00349                 bitB = OWI_ReadBit(pin);
00350                 
00351                 if (bitA && bitB) {
00352                         // Both bits 1 (Error).
00353                         newDeviation = OWI_ROM_SEARCH_FAILED;
00354                         return newDeviation;
00355                 } else if (bitA ^ bitB) {
00356                         // Bits A and B are different. All devices have the same bit here.
00357                         // Set the bit in bitPattern to this value.
00358                         if (bitA) {
00359                                 (*bitPattern) |= bitMask;
00360                         } else {
00361                                 (*bitPattern) &= ~bitMask;
00362                         }
00363                 } else {
00364                         // If this is where a choice was made the last time,
00365                         // a '1' bit is selected this time.
00366                         if (currentBit == lastDeviation) {
00367                                 (*bitPattern) |= bitMask;
00368                         }
00369                         
00370                         // For the rest of the id, '0' bits are selected when
00371                         // discrepancies occur.
00372                         else if (currentBit > lastDeviation) {
00373                                 (*bitPattern) &= ~bitMask;
00374                                 newDeviation = currentBit;
00375                         }
00376                         
00377                         // If current bit in bit pattern = 0, then this is
00378                         // out new deviation.
00379                         else if ( !(*bitPattern & bitMask)) {
00380                                 newDeviation = currentBit;
00381                         }
00382                         
00383                 // IF the bit is already 1, do nothing.
00384                         else {
00385                         }
00386                 }
00387                 
00388                 // Send the selected bit to the bus.
00389                 if ((*bitPattern) & bitMask) {
00390                         OWI_WriteBit1(pin);
00391                 } else {
00392                         OWI_WriteBit0(pin);
00393                 }
00394                 
00395                 // Increment current bit.    
00396                 currentBit++;
00397                 
00398                 // Adjust bitMask and bitPattern pointer.    
00399                 bitMask <<= 1;
00400                 if (!bitMask) {
00401                         bitMask = 0x01;
00402                         bitPattern++;
00403                 }
00404         }
00405         
00406         return newDeviation;
00407 }

Here is the call graph for this function:

void OWI_SendByte ( unsigned char  data,
unsigned char  pins 
)

Sends one byte of data on the 1-Wire(R) bus(es).

This function automates the task of sending a complete byte of data on the 1-Wire bus(es).

Parameters:
data The data to send on the bus(es).
pins A bitmask of the buses to send the data to.

Definition at line 197 of file OWI.c.

References OWI_WriteBit0(), and OWI_WriteBit1().

Referenced by BatteryDataRefresh(), OWI_MatchRom(), OWI_ReadRom(), OWI_SearchRom(), and OWI_SkipRom().

00198 {
00199         unsigned char temp;
00200         unsigned char i;
00201         
00202         // Do once for each bit
00203         for (i = 0; i < 8; i++) {
00204                 // Determine if LSB is '0' or '1' and transmit corresponding
00205                 // waveform on the bus.
00206                 temp = data & 0x01;
00207                 
00208                 if (temp) {
00209                         OWI_WriteBit1(pins);
00210                 } else {
00211                         OWI_WriteBit0(pins);
00212                 }
00213         
00214                 data >>= 1;  // Right shift the data to get next bit.
00215         }
00216 }

Here is the call graph for this function:

void OWI_SkipRom ( unsigned char  pins  ) 

Sends the SKIP ROM command to the 1-Wire bus(es).

Parameters:
pins A bitmask of the buses to send the SKIP ROM command to.

Definition at line 256 of file OWI.c.

References OWI_ROM_SKIP, and OWI_SendByte().

00257 {
00258         // Send the SKIP ROM command on the bus.
00259         OWI_SendByte(OWI_ROM_SKIP, pins);
00260 }

Here is the call graph for this function:

void OWI_WriteBit0 ( unsigned char  pins  ) 

Write a '0' to the bus(es). (Software only driver).

Generates the waveform for transmission of a '0' bit on the 1-Wire(R) bus.

Parameters:
pins A bitmask of the buses to write to.

Definition at line 94 of file OWI.c.

References OWI_DELAY_C_STD_MODE, OWI_DELAY_D_STD_MODE, OWI_PULL_BUS_LOW, and OWI_RELEASE_BUS.

Referenced by OWI_SearchRom(), and OWI_SendByte().

00095 {
00096         unsigned char intState;
00097         
00098         // Disable interrupts.
00099         intState = __save_interrupt();
00100         __disable_interrupt();
00101         
00102         // Drive bus low and delay.
00103         OWI_PULL_BUS_LOW(pins);
00104         __delay_cycles(OWI_DELAY_C_STD_MODE);
00105         
00106         // Release bus and delay.
00107         OWI_RELEASE_BUS(pins);
00108         __delay_cycles(OWI_DELAY_D_STD_MODE);
00109         
00110         // Restore interrupts.
00111         __restore_interrupt(intState);
00112 }

void OWI_WriteBit1 ( unsigned char  pins  ) 

Write a '1' bit to the bus(es). (Software only driver).

Generates the waveform for transmission of a '1' bit on the 1-Wire bus.

Parameters:
pins A bitmask of the buses to write to.

Definition at line 68 of file OWI.c.

References OWI_DELAY_A_STD_MODE, OWI_DELAY_B_STD_MODE, OWI_PULL_BUS_LOW, and OWI_RELEASE_BUS.

Referenced by OWI_SearchRom(), and OWI_SendByte().

00068                                       {
00069         unsigned char intState;
00070         
00071         // Disable interrupts.
00072         intState = __save_interrupt();
00073         __disable_interrupt();
00074         
00075         // Drive bus low and delay.
00076         OWI_PULL_BUS_LOW(pins);
00077         __delay_cycles(OWI_DELAY_A_STD_MODE);
00078         
00079         // Release bus and delay.
00080         OWI_RELEASE_BUS(pins);
00081         __delay_cycles(OWI_DELAY_B_STD_MODE);
00082         
00083         // Restore interrupts.
00084         __restore_interrupt(intState);
00085 }


Generated on Fri Jul 25 12:42:26 2008 for AVR458 Charging Li-Ion Batteries with ATAVRBC100 by  doxygen 1.5.6