FPGA/ASIC技术

| Operation* | Description |
| 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. |
//---------------------------------------------------------------------------------------------------- //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 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才能响应接下来的命令,其它的从器件将等待下一个复位脉冲。
OWWriteByte和OWReadByte API函数用来产生存储器命令(例如,Write/Copy/Read Scratchpad命令)。DS1WM通过发送Write Scratchpad命令(0x4Eh)以及随后的高温、低温和配置寄存器设置值,来设定温度报警以及分辨率。上述操作完成后,发送OWReset以及Match ROM命令、ROM ID和Copy Scratchpad命令(0x48h) (将暂存器的内容复制到寄存器存储器),完成温度分辨率设置。必须为CPU主机增加10ms的延时,以完成复制操作。考虑到微处理器延时子程序的差异,API仅提供了注释伪码。
复制操作完成后,再次执行OWReset,然后发送Match ROM、ROM ID和转换温度命令(0x44h)。需要增加100ms的延时,以完成温度转换。最后,发送OWReset和Match ROM、ROM ID和Read Scratchpad命令(0xBEh),读取两字节温度数据。需要注意的是,选择DS28EA00时,必须始终遵循OWReset之后发送Match ROM命令和ROM ID的命令格式。当总线上仅有一个器件时,才能够使用Skip ROM命令(即无需Search ROM)。
//----------------------------------------------------------------------------------------------------
//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)
OWReset(); //Error code removed for conciseness
MatchROM(ROMCodes,DS28EA00); //Select device
OWWriteByte(0x48); //Issue Copy Scratchpad command
//To d 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 d 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
//----------------------------------------------------------------------------------------------------
利用DS1WM API函数控制高速模式下的DS2431
该示例利用之前搜索到的ROM ID与DS2431进行通信。OWReset之后发送Overdrive Skip ROM命令(0x3Ch),将所有支持高速模式的1-Wire器件置于高速模式。调用OverdriveEnable函数激活DS1WM高速时序。此时所有1-Wire器件工作在高速模式。标准速率模式和高速模式下的1-Wire时序请参见应用笔记126:“用软件实现1-Wire®通信”。
使用目标地址TA1和TA2变量
在第一个示例方法中,变量TA1和TA2设置为DS2431期望的存储器地址。发送OWReset,之后是Match ROM、DS2431 ROM ID、Write Scratchpad命令(0x0Fh)、目标地址1 & 2以及要写入DS2431 64位暂存器的8字节数据。推荐进行回读及CRC16校验操作。关于CRC16的详细讨论,请参考应用笔记27:“理解和运用Maxim iButton®产品中的循环冗余校验(CRC)”。
OWWriteBytes和OWReadBytes
在第二个示例方法中,调用了两个新的API函数:OWWriteBytes和OWReadBytes。这两个API函数简化了大量数据至暂存器的读写操作。
写暂存器的方法是:设置目标地址1 & 2、将数据写入WriteBytes数组、执行OWReset、然后发送Match ROM、DS2431 ROM ID、Write Scratchpad命令(0x0Fh)、目标地址1 & 2、利用OWWriteBytes函数写入保存在WriteBytes的所有10个字节、回读CRC16并对CRC16进行校验。
读暂存器的方法是:执行OWReset、发送Match ROM、DS2431 ROM ID、Read Scratchpad命令(0xAAh)、利用OWReadBytes函数读取所有13个字节(TA1、TA2、ES、CRC16 & 8字节数据)并保存到ReadBytes。
调用API函数OverdriveDisable,并随后发送标准OWReset,可以退出高速模数,使所有器件返回至标准速率。
//----------------------------------------------------------------------------------------------------
//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
//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
//----------------------------------------------------------------------------------------------------
结论
本应用笔记给出了使用API函数控制DS1WM的示例,无需主机CPU产生1-Wire时序。用户现在应该对选择和访问总线上多个1-Wire器件的通用API函数有了一定的了解。本文给出了DS28EA00和DS2431总线示例器件的控制和访问示例,此外还演示了高速模式以及单字节/多字节数据的读写操作。
全部0条评论
快来发表一下你的评论吧 !