Sets the 1-Wire communication speed for the DS1WM to overdrive. Note that this only changes the communication speed of the DS1WM; the 1-Wire slave device must be instructed to make the switch when going from normal to overdrive. The 1-Wire slave will always revert to standard speed when it encounters a standard-speed 1-Wire reset.
OverdriveDisable
Sets the 1-Wire communication speed for the DS1WM to standard. Note that this only changes the communication speed of the DS1WM; a standard-speed 1-Wire reset is required for slave devices to exit overdrive.
MatchROM
Selects device by issuing the Match ROM command followed by the 64-bit ROM ID selected.
SetClockFrequency
Sets the clock frequency for the DS1WM.
InterruptEnableRegisterWrite
Writes a single byte of data to the DS1WM Interrupt Enable register.
InterruptRegisterRead
Reads a single byte of data from the DS1WM Interrupt register.
ReceiveBufferRead
Reads a single byte of data from the DS1WM Receive Buffer register.
//----------------------------------------------------------------------------------------------------
//Start of initialization example
SetClockFrequency(16); //Set clock frequency to 16MHz (power-on default)
InterruptEnableRegisterWrite(0x00); //Clear interrupts
//Flush receive buffer
InterruptRegisterData = InterruptRegisterRead();
ReceiveBufferRead();
//End of initialization example
//----------------------------------------------------------------------------------------------------
Result = OWReset();
if(!Result){
switch(ErrorStatus){
case -1: //DS1WM did not recognize 1-Wire reset (PD=0)
//To do: add your error code here
break;
case -2: //No device found (PDR=1)
//To do: add your error code here
break;
case -7: //1-Wire IO is shorted (OW_SHORT=1)
//To do: add your error code here
break;
case -8: //1-Wire IO is shorted (OW_LOW=1)
//To do: add your error code here
break;
}
}
//----------------------------------------------------------------------------------------------------
//Start of DS1WM search ROM accelerator example
//Devices on the 1-Wire IO are:
//DS28EA00 Family Code = 42h (6900000004E8C842)
//DS2431 Famliy Code = 2Dh (5A0000000FDE052D)
//Find all devices on 1-Wire line and populate ROMCodes array
Result = OWSearch(ROMCodes); //Returns number of devices found if successful
//Set number of 1-Wire devices found
if(Result)
NumberOfDevices = Result;
if(!Result){
switch(ErrorStatus){
case -1: //DS1WM did not recognize 1-Wire Reset (PD=0)
//To do: add your error code here
break;
case -2: //No device found (PDR=1)
//To do: add your error code here
break;
case -7: //1-Wire IO is shorted (OW_SHORT=1)
//To do: add your error code here
break;
case -8: //1-Wire IO is shorted (OW_LOW=1)
//To do: add your error code here
break;
case -9: //Invalid CRC for device
//To do: add your error code here
break;
case -10: //ROMCodes array too small (Edit MaxNumberDevices in DS1WM.h)
//To do: add your error code here
break;
}
}
//Note: This function is intended to be used when there is only one device with the same
//Family Code present on the line
for(i=0;i<NumberOfDevices;i++){
if(ROMCodes[i][0] == 0x42){
DS28EA00 = i; //Save off array index for DS28EA00
continue;
}
if(ROMCodes[i][0] == 0x2D){
DS2431 = i; //Save off array index for DS2431
continue;
}
}
//----------------------------------------------------------------------------------------------------
//Start of DS28EA00 example
Result = OWReset();
if(!Result){
switch(ErrorStatus){
case -1: //DS1WM did not recognize 1-Wire reset(PD=0)
//To do: add your error code here
break;
case -2: //No device found(PDR=1)
//To do: add your error code here
break;
case -7: //1-Wire IO is shorted(OW_SHORT=1)
//To do: add your error code here
break;
case -8: //1-Wire IO is shorted(OW_LOW=1)
//To do: add your error code here
break;
}
}
//Set temperature resolution
Result = MatchROM(ROMCodes,DS28EA00); //Select device
Result = OWWriteByte(0x4E); //Issue Write Scratchpad command
Result = OWWriteByte(0x00); //TH register data
Result = OWWriteByte(0x00); //TL degister data
Result = OWWriteByte(0x1F); //Config. reg. data (set 9-bit temp. resolution)
OWReset(); //Error code removed for conciseness
MatchROM(ROMCodes,DS28EA00); //Select device
OWWriteByte(0x48); //Issue Copy Scratchpad command
//To do: add microprocessor-specific code delay to allow copy to complete
//Delay(10MS);
//Psuedo code
OWReset(); //1-Wire reset
MatchROM(ROMCodes,DS28EA00); //Select device
OWWriteByte(0x44); //Issue Convert Temperature command
//To do: add microprocessor-specific code delay to allow temperature conversion to complete
//Delay(100MS);
//Psuedo code
//Read temperature results from scratchpad
OWReset(); //1-Wire reset
MatchROM(ROMCodes,DS28EA00); //Select device
OWWriteByte(0xBE); //Issue Read Scratchpad command
TempLSB = OWReadByte(); //Read byte
TempMSB = OWReadByte(); //Read byte
//End of DS28EA00 example
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
//Start of DS2431 example
Result = OWReset(); //Error code removed for conciseness
Result = OWWriteByte(0x3C); //Overdrive Skip ROM (all devices are now in overdrive)
OverdriveEnable(); //Enable Overdrive Mode
//Write scratchpad with data
//First method
TA1 = 0x00;
TA2 = 0x00;
Result = OWReset(); //1-Wire reset
Result = MatchROM(ROMCodes,DS2431); //Select device
Result = OWWriteByte(0x0F); //Issue Write Scratchpad command
Result = OWWriteByte(TA1); //Send target address 1 (TA1)
Result = OWWriteByte(TA2); //Send target address 2 (TA2)
//Write 8 Bytes of Data
Result = OWWriteByte(0x11); //Send Data Byte for all
Result = OWWriteByte(0x22);
Result = OWWriteByte(0x33);
Result = OWWriteByte(0x44);
Result = OWWriteByte(0x55);
Result = OWWriteByte(0x66);
Result = OWWriteByte(0x77);
Result = OWWriteByte(0x88);
//It is recommended that the CRC16 be read back and verified
//CRC16 code was left out for conciseness
Result = OWReset(); //1-Wire Reset
Result = MatchROM(ROMCodes,DS2431); //Select device
Result = OWWriteByte(0xAA); //Issue Read Scratchpad command
Result = OWReadByte(); //Read TA1
if(Result != TA1){
//To do: Add your error code here
}
Result = OWReadByte(); //Read TA2
if(Result != TA2){
//To do: Add your error code here
}
ES = OWReadByte(); //Read ES
//To do: add your error code after reads
Result = OWReadByte(); //Read Data Byte (0x11)
Result = OWReadByte(); //Read Data Byte (0x22)
Result = OWReadByte(); //Read Data Byte (0x33)
Result = OWReadByte(); //Read Data Byte (0x44)
Result = OWReadByte(); //Read Data Byte (0x55)
Result = OWReadByte(); //Read Data Byte (0x66)
Result = OWReadByte(); //Read Data Byte (0x77)
Result = OWReadByte(); //Read Data Byte (0x88)
//It is recommended that the CRC16 be read back and verified
//CRC16 code was left out for conciseness
//Second method
TA1 = 0x00;
TA2 = 0x00;
WriteBytes[0] = TA1;
WriteBytes[1] = TA2;
for(i=2;i<10;i++){
WriteBytes[i] = i;
}
Result = OWReset(); //1-Wire reset
Result = MatchROM(ROMCodes,DS2431); //Select device
Result = OWWriteByte(0x0F); //Issue Write Scratchpad command
//Write 10 bytes of data (TA1, TA2 & 8 bytes of data)
OWWriteBytes(WriteBytes,10); //Write data bytes
//It is recommended that the CRC16 be read back and verified
//CRC16 code was left out for conciseness
Result = OWReset(); //1-Wire reset
Result = MatchROM(ROMCodes,DS2431); //Select device
Result = OWWriteByte(0xAA); //Issue Read Scratchpad command
//Read 13 bytes of data (TA1, TA2, ES, CRC16 & 8 bytes of data)
OWReadBytes(ReadBytes,13); //Read data bytes
//It is recommended that the CRC16 be read back and verified
//CRC16 code was left out for conciseness
//Exit overdrive
OverdriveDisable();
Result = OWReset(); //Std. reset issued (all devices are now in standard speed)
//End of DS2431 example
//----------------------------------------------------------------------------------------------------