OWReset
Sends the 1-Wire reset stimulus and checks for the pulses of 1-Wire slave devices that are present on the bus.
OWWriteByte/OWReadByte
Sends or receives a single byte of data from the 1-Wire bus.
OWWriteBytes/OWReadBytes
Sends or receives multiple bytes of data from the 1-Wire bus.
OWSearch
Performs the 1-Wire Search Algorithm (see application note 187, "1-Wire Search Algorithm").
OverdriveEnable
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.*该表涵盖了示例中用到的子程序,详细说明请参见DS1WM.c文件。
//End of initialization example
//----------------------------------------------------------------------------------------------------
1-Wire复位(OWReset API函数)初始化完成后,主机必须确定1-Wire总线上是否接有设备。主机调用OWReset函数,以实现该目的。如果检测到器件存在脉冲,该函数返回1;如果没有检测到器件或发送错误,则函数返回0。如果返回值为0,需要检查ErrorStatus变量,以确定故障状态。1-Wire复位的优先级高于所有1-Wire命令(例如,Match ROM、Skip ROM、Read ROM),但调用OWSearch函数时除外,该函数自身带有复位。软件设计人员应当在程序中加入适当的故障处理代码,在发生故障时能够触发执行这些代码。ErrorStatus值意味着发生了如下错误中的一种:没有进行在线检测;没有检测到器件;存在1-Wire短路;1-Wire总线始终处于低电平状态。
Result = OWReset();
if(!Result){
switch(ErrorStatus){
case -1: //DS1WM did not recognize 1-Wire reset (PD=0)
//To d add your error code here
break;
case -2: //No device found (PDR=1)
//To d add your error code here
break;
case -7: //1-Wire IO is shorted (OW_SHORT=1)
//To d add your error code here
break;
case -8: //1-Wire IO is shorted (OW_LOW=1)
//To d 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 d add your error code here
break;
case -2: //No device found (PDR=1)
//To d add your error code here
break;
case -7: //1-Wire IO is shorted (OW_SHORT=1)
//To d add your error code here
break;
case -8: //1-Wire IO is shorted (OW_LOW=1)
//To d add your error code here
break;
case -9: //Invalid CRC for device
//To d add your error code here
break;
case -10: //ROMCodes array too small (Edit MaxNumberDevices in DS1WM.h)
//To d 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
利用DS1WM API函数控制DS28EA00该示例利用之前搜索到的ROM ID与DS28EA00进行通信。OWReset之后发送Match ROM命令。ROM码数组连同被访问的器件索引一起,传递到Match ROM函数。1-Wire总线上的器件会在Match ROM命令0x55h之后收到一个64位ROM码,可以使总线主机在多点总线上寻址到特定的DS28EA00。只有与64位ROM序列完全匹配的DS28EA00才能响应接下来的命令,其它的从器件将等待下一个复位脉冲。
//----------------------------------------------------------------------------------------------------
//Start of DS28EA00 example
Result = OWReset();
if(!Result){
switch(ErrorStatus){
case -1: //DS1WM did not recognize 1-Wire reset(PD=0)
//To d add your error code here
break;
case -2: //No device found(PDR=1)
//To d add your error code here
break;
case -7: //1-Wire IO is shorted(OW_SHORT=1)
//To d add your error code here
break;
case -8: //1-Wire IO is shorted(OW_LOW=1)
//To d 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)
//----------------------------------------------------------------------------------------------------
//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 d Add your error code here
}
Result = OWReadByte(); //Read TA2
if(Result != TA2){
//To d Add your error code here
}
ES = OWReadByte(); //Read ES
//To d 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