개요: DS2482는 1-Wire 네트워크 프로토콜 I²C 브리지이다. 브리지로서 DS2482는 I²C 통신 기능이 있는 모든 호스트에서 적절한 타이밍 및 슬루 제어를 갖는 1-Wire 파형을 발생시킬 수 있도록 한다. 이 애플리케이션 노트는 DS2482 I²C 1-Wire 라인 드라이버에 대한 사용자 가이드로, 일반적인 1-Wire 마스터 동작을 위한 상세한 통신 세션을 제공한다.
1. 머리말
1-Wire 통신 프로토콜은 I²C 통신과 1-Wire 네트워크를 연결하는 브리지인 DS2482를 사용하여 발생시킬 수 있다. 이 브리지는 I²C를 갖는 모든 호스트에서 적절한 타이밍의 1-Wire 파형을 발생시키도록 한다. 그림 1에는 DS2482 구성을 보여주는 간략한 다이어그램이 나와 있다. 이러한 프로토콜을 구현하고 사용 가능한 DS2482 명령을 찾는 데에는 많은 시간이 걸리고 복잡할 수 있다. 이 문서에서는 DS2482를 사용하는 기본 및 확장 1-Wire 동작의 효율적인 구현 방법을 제공하며, 1-Wire 통신을 지원하도록 I²C 입력 패킷을 구성하는 방법에 대해 설명한다. 이러한 동작은 현재 나와 있거나 앞으로 출시될 1-Wire 소자의 모든 기능을 수행하는 완벽한 기초가 된다. 이와 같은 방식으로 1-Wire 동작을 개념화한다면 1-Wire 마스터 유형과 상관없이 모든 1-Wire 애플리케이션에 적용할 수 있을 것이다.
이 문서는 DS2482 데이터 시트를 보완하기 위해 작성되었으며, 이 데이터 시트를 대신하지는 않는다. DS2482는 단일 채널 1-Wire 마스터(DS2482-100) 및 8채널 1-Wire 마스터(DS2482-800)의 두 가지 구성으로 제공된다.
 그림 1. I²C 통신과 1-Wire 네트워크를 위한 브리지로서 DS2482 기능을 보여주는 간략한 다이어그램
2. 1-Wire 인터페이스
1-Wire 동작을 수행하기 위해서는 애플리케이션이 반드시 갖추어야 하는 원시 함수(primitives)라고 하는 몇 가지 기본 1-Wire 함수가 있다. 이러한 원시 함수 중 첫 번째 함수는 버스상의 모든 1-Wire 슬레이브를 리셋하여 1-Wire 마스터의 모든 명령에 준비할 수 있게 한다. 두 번째 함수는 1-Wire 마스터로부터 슬레이브에 1비트를 쓰며, 세 번째 함수는 1-Wire 슬레이브로부터 1비트를 읽는다. 1-Wire 마스터는 모든 1-Wire 비트 통신을 시작해야 하기 때문에 '읽기'는 샘플링된 결과를 갖는 단일 비트의 '쓰기'와 기술적으로 같다. 대부분의 다른 1-Wire 동작은 이러한 3가지 동작으로부터 구성할 수 있다. 예를 들어, 1-Wire 버스에 쓰여지는 1바이트는 8번의 단일 비트 쓰기와 같다.
1-Wire 검색 알고리즘은 이와 같은 동일한 3개의 원시 함수를 사용하여 구성할 수 있다. DS2482는 1-Wire 트리플렛 명령을 사용하여 검색을 통합하므로, 검색을 수행하는 데 필요한 통신을 크게 줄여준다.
표 1은 3개의 기본 원시 함수 (OWReset, OWWriteBit/OWReadBit, OWWriteByte/OWReadByte)를 포함하여 기본 1-Wire 동작의 코어 세트를 함께 구성하는 3개의 다른 유용한 함수 (OWBlock, OWSearch, msDelay)를 보여준다. 이 동작 이름은 앞으로 이 문서의 전체에서 사용된다.
표 1. 기본 1-Wire 동작
| Operation |
Description |
| OWReset |
Sends the 1-Wire reset stimulus and check for pulses of 1-Wire slave devices. |
| OWWriteBit/OWReadBit |
Sends or receives a single bit of data to the 1-Wire bus. |
| OWWriteByte/OWReadByte |
Sends or receives a single byte of data to the 1-Wire bus. |
| OWBlock |
Sends and receives multiple bytes of data to and from the 1-Wire bus. |
| OWSearch |
Performs the 1-Wire Search Algorithm (see Application Note 187 mentioned above). |
| msDelay |
Delays at least the specified number of milliseconds. |
오버드라이브 통신 함수와 같은 확장된 1-Wire 함수는 위의 테이블의 기본 동작에 포함되어 있지 않다. 일부 1-Wire 슬레이브 소자는 표준 및 오버드라이브의 두 가지 통신 속도로 동작할 수 있다. 모든 소자는 표준 속도를 지원하며, 오버드라이브는 표준보다 약 10배 더 빠르다. DS2482는 두 가지 1-Wire 속도를 모두 지원한다.
1-Wire 소자는 일반적으로 1-Wire 버스에서 일부 또는 모든 동작 에너지를 공급 받는다. 그러나 일부 소자는 프로토콜의 특정 위치에서 추가적인 전력 공급을 필요로 한다. 예를 들어, 어떤 소자는 온도 변환이나 SHA-1 해시 계산을 수행할 필요가 있다. 이를 수행하기 위한 전력은 1-Wire 버스에 더 강한 풀 업을 인에이블링하여 공급된다. 이러한 전력이 공급되는 동안에는 일반 통신이 발생해서는 안 된다. DS2482는 1-Wire 통신의 다음 바이트/비트 후에 강력한 풀 업을 발생시키는 Strong Pullup (SPU) 플래그를 설정하여 전력을 공급한다. DS2482-100에는 보충적인 대전류의 강한 풀 업을 제어하기 위해 외부 핀(PCTLZ)이 제공된다.
표 2에는 1-Wire 속도, 전력 공급 및 프로그래밍 펄스를 위한 확장 1-Wire 동작이 나와 있다.
표 2. 확장 1-Wire 동작
| Operation |
Description |
| OWSpeed |
Sets the 1-Wire communication speed, either standard or overdrive. Note that this only changes the communication speed of the 1-Wire master; 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. |
| OWLevel |
Sets the 1-Wire power level (normal or power delivery). |
| OWReadBitPower |
Reads a single bit of data from the 1-Wire bus and optionally applies power delivery immediately after the bit is complete. |
| OWWriteBytePower |
Sends a single byte of data to the 1-Wire bus and applies power delivery immediately after the byte is complete. |
3. 호스트 구성
DS2482 호스트에는 I²C 통신 포트가 있어야 한다. 호스트의 구성에 대해서는 여기에서 다루지 않는다. 호스트는 반드시 표준 인터페이스 I²C 동작을 제공해야 한다. 필요한 동작은 표 3에 나와 있다.
표 3. 필수 I²C 호스트 동작
| Operation |
Description |
| InitI2C |
Sets the I²C communication speed and selects the DS2482 device. The I2C_clock_delay is the time between clock pulses for I²C communication. The DS2482_slave_address is the I²C address for the DS2482. |
| I2CBus_write |
Writes an I²C byte to the selected DS2482. The byte is passed to the function to write. |
| I2CBus_write_packet |
Writes a packet of I²C bytes to the selected DS2482. The buffer of bytes along with the length of the buffer is passed to the function. |
| I2CBus_read |
Reads an I²C byte from the DS2482. The byte that was read is returned. |
3.1. DS2482 구성
모든 1-Wire 동작을 수행하기 전에 호스트가 설정되어 DS2482 I²C 1-Wire 라인 드라이버로 동기화되어야 한다. DS2482와 통신하기 위해서는 슬레이브 어드레스를 알아야 한다. 그림 2는 DS2482-100 및 DS2482-800의 슬레이브 어드레스를 보여준다.
 그림 2. DS2482 I²C 슬레이브 어드레스
3.2. DS2482 I²C 명령
다음의 범례는 DS2482 데이터 시트에서 가져온 것으로, 소자와의 I²C 통신 시퀀스를 설명하는 간단한 기호를 나타낸다. 다음에서는 이러한 통신 시퀀스가 반복적으로 사용되며, 기본 및 확장 1-Wire 동작을 구현하기 위한 추가 설명 및 C 코드 예제가 제공된다.
I²C 통신 시퀀스 — 범례
| SYMBOL |
DESCRIPTION |
| S |
START Condition |
| AD, 0 |
Select DS2482 for Write Access |
| AD, 1 |
Select DS2482 for Read Access |
| Sr |
Repeated START Condition |
| P |
STOP Condition |
| A |
Acknowledged |
| A\ |
Not acknowledged |
| (Idle) |
Bus not busy |
| <byte> |
Transfer of one byte |
| DRST |
Command 'Device Reset', F0h |
| WCFG |
Command 'Write Configuration', D2h |
| SRP |
Command 'Set Read Pointer', E1h |
| 1WRS |
Command '1-Wire Reset', B4h |
| 1WWB |
Command '1-Wire Write Byte', A5h |
| 1WRB |
Command '1-Wire Read Byte', 96h |
| 1WSB |
Command '1-Wire Single Bit', 87h |
| 1WT |
Command '1-Wire Triplet', 78h |
3.3. 데이터 방향 코드
본문 많은 그림에서 볼 수 있는 데이터 방향 코드는 마스터에서 슬레이브로(회색) 또는 그 반대 방향인 슬레이브에서 마스터로(흰색)의 통신을 보여준다. 각 코드의 진하게 표시된 부분을 보면 통신 방향을 쉽게 알 수 있다.
4. 소자 리셋
그림 3은 소자 리셋 I²C 통신의 예이다. 리셋 예제 1은 소자의 스테이트 머신 로직에 대한 글로벌 리셋을 수행하고, 진행 중인 모든 1-Wire 통신을 종료하는 DS2482 리셋 명령을 보여준다. 소자 리셋의 명령 코드는 0xF0이다.
 그림 3. 파워 업 후 소자 리셋. 이 예에는 명령이 성공적으로 수행되었는지 확인하는 읽기 액세스 옵션이 포함되어 있다.
// initialize the I2C port
if(!InitI2C(I2C_clock_delay,DS2482_slave_address))
{
// Report an error that occurred
}
// reset the DS2482
// DRST is 0xF0
if(!I2CBus_write(DRST))
{
// Report an error that occurred
}
예제 1. 소자 리셋 코드
5. DS2482 1-Wire 동작
다음은 DS2482에 전송되는 명령들로 1-Wire 통신에 영향을 미친다.
5.1. OWReset
리셋 명령(0xB4)은 1-Wire 라인에 1-Wire 리셋/존재 검출을 발생시킨다. 1-Wire 라인의 상태는 상태 레지스터에 있는 PPD (Presence-Pulse Detect) 및 SD (Short Detected) 필드를 통해 샘플링되고 보고된다. 그림 4는 1-Wire 리셋 명령을 위한 I²C 통신을 보여준다. 예제 2는 전송된 명령과 존재 펄스에 대해 확인된 상태 레지스터를 보여준다.
 그림 4. 1-Wire 리셋. 1-Wire 통신을 시작 또는 종료한다. 1-Wire Idle(1WB = 0), 1-Wire 명령이 완료될 때까지 busy 폴링되며, 그런 다음 결과를 읽는다.
// OWReset
//
// Resets the 1-Wire using I2C through the DS2482.
//
// returns Success or Failure
//
uchar OWReset()
{
uchar buffer;
uchar test;
// reset the 1-Wire line
// resetOneWireCommand is 0xB4
if(!I2CBus_write(resetOneWireCommand))
{
// Report an error that occurred
}
for(;;)// checking if 1-Wire busy
{
// checking LSB of status register
// to see if 1-Wire is busy.
test = I2CBus_read()| 0xFE;
if(test == 0xFE)
{break;}
}
// checking for presence pulse detect
test = I2CBus_read() | 0xFC;
if(test == 0xFE)
{
return Success; // Presence Pulse found
}
else
{
return Failure; // No presence pulse
}
}
예제 2. OWReset 코드
5.2. OWWriteBit/OWReadBit
1-Wire 비트 명령(0x87)은 단일 1-Wire 비트 타임 슬롯을 발생시킨다. 그림 5는 1-Wire 단일 비트 명령을 위한 I²C 통신 코드를 보여준다. 그림 6은 비트 할당 바이트이며, 여기서 V가 1b이면 write-one time 슬롯이 발생되고, V가 0b이면 write-zero time 슬롯이 발생된다. 예제 3과 예제 4는 각각 OWWriteBit 코드와 OWReadBit 코드를 보여준다.
 그림 5. 1-Wire 단일 비트. 1-Wire 라인에 단일 타임 슬롯을 발생시킨다. 1WB이 1에서 0으로 전환되면, 상태 레지스터는 1-Wire 단일 비트 명령의 유효한 결과를 갖고 있다.
 그림 6. 1-Wire 단일 비트. 1-Wire 라인에 단일 타임 슬롯을 발생시킨다.
// OWWriteBit - Writes a single bit to 1-Wire using the DS2482.
//
// value - bit to be written to the 1-Wire (0 or 1)
//
// Return Success or Failure
//
uchar OWWriteBit(uchar value)
{
uchar buff[3];
uchar test;
buff[0] = onewireBitCommand; // 1-Wire bit command
if(value)
{
buff[1] = 0xFF;
}
else
{
buff[1] = 0x7F;
}
if(!I2CBus_write(&buff[0],2))
{
return FAILURE;
}
// checking if 1-Wire busy
// Check here to make sure the 1-Wire isn’t
// busy so other commands don’t have to check
// before proceeding.
for(;;)
{
if(!I2CBus_read(&buff[0],1))
{
return FAILURE;
}
test = buff[0] | 0xFE;
if(test == 0xFE)
{
break;
}
}
return SUCCESS;
}
예제 3. OWWriteBit 코드
// OWReadBit
//
// Returns 0 or 1 for the bit read.
uchar OWReadBit()
{
uchar buff[3];
OWWriteBit(1);
buff[0] = setReadPointerCommand;
buff[1] = statusRegister;
if(!I2CBus_write(&buff[0],2))
{
// Report an error that occurred
}
else if(!I2CBus_read(&buff[2],1))
{
// Report an error that occurred
}
if(buff[2] & 0x20)
{
return 1;
}
else
{
return 0;
}
}
예제 4. OWReadBit 코드
5.3. OWWriteByte
1-Wire 쓰기 바이트 명령(0xA5)은 1-Wire 라인에 단일 데이터 바이트를 쓴다. 1-Wire 활동이 먼저 종료되어야 DS2482가 이 명령을 처리할 수 있다. 그림 7은 I²C 쓰기 1-Wire 바이트 케이스를 보여준다. 코드 예제 5는 쓰기 바이트 명령을 발생시키기 전에 1-Wire 활동을 검사한다.
 그림 7. 1-Wire 쓰기 바이트. 1-Wire 라인에 명령 코드를 전송한다. 1WB가 1에서 0으로 전환되면, 1-Wire 쓰기 바이트 명령이 완료된다.
// OWWriteByte
//
// Writes a 1-Wire byte using I2C commands sent to the DS2482.
//
// wrByte - The byte to be written to the 1-Wire.
//
void OWWriteByte(uchar wrByte)
{
uchar buffer[2];
uchar test;
// set the read pointer to the status
// register to check 1-Wire busy
buffer[0] = setReadPointerCommand; // 0xE1
buffer[1] = statusRegister; // 0xF0
if(!I2CBus_write(buffer,2))
{
// Report an error that occurred
}
// checking if 1-Wire busy
for(;;)
{
test = I2CBus_read() | 0xFE;
if(test == 0xFE)
{
break;
}
}
buffer[0] = writeByteCommand; // 0xA5
buffer[1] = wrByte;
if(!I2CBus_write_packet(buffer,2))
{
// Report an error that occurred
}
// checking if 1-Wire busy
for(;;)
{
test = I2CBus_read() | 0xFE;
if(test == 0xFE)
{
break;
}
}
}
예제 5. OWWriteByte 코드
5.4. OWReadByte
1-Wire 읽기 바이트 명령(0x96)은 1-Wire 라인에 단일 데이터 바이트를 읽는다. 1-Wire 활동이 먼저 종료되어야 DS2482가 이 명령을 처리할 수 있다. 그림 8은 I²C 케이스를 보여준다. 1-Wire 읽기 바이트 명령을 위한 코드는 예제 6에 나와 있다. 읽기 바이트 명령을 발생시키기 전에 1-Wire 활동을 검사한다.
 그림 8. 1-Wire 읽기 바이트. 1-Wire 라인에서 1바이트를 읽는다. 1WB 비트가 1에서 0으로 전환될 때까지 상태 레지스터를 폴링한다. 그런 다음 읽기 포인터를 데이터 읽기 레지스터(코드 E1h)로 설정하고 소자에 다시 액세스하여 1-Wire 라인에서 가져온 데이터 바이트를 읽는다.
// OWReadByte
//
// Reads a 1-Wire byte using I2C commands to the DS2482.
//
// returns the byte read
//
uchar OWReadByte
{
uchar buffer[2];
uchar test;
// set the read pointer to the status
// register to check 1-Wire busy
buffer[0] = setReadPointerCommand; // 0xE1
buffer[1] = statusRegister; // 0xF0
if(!I2CBus_write_packet(buffer,2))
{
// Report an error that occurred
}
// checking if 1-Wire busy
for(;;)
{
test = I2CBus_read() | 0xFE;
if(test == 0xFE)
{
break;
}
}
// readByteCommand is 0x96
if(!I2CBus_write(readByteCommand))
{
// Report an error that occurred
}
buffer[0] = setReadPointerCommand; // 0xE1
buffer[1] = readDataRegister; // 0xE1
if(!I2CBus_write_packet(buffer,2))
{
// Report an error that occurred
}
// gets the byte that was read
else
{
buffer[2] = I2CBus_read();
}
return buffer[2];
}
예제 6. OWReadByte 코드
5.5. OWBlock
OWBlock 동작은 바이트 명령을 사용하지 않고 데이터 블록을 전달할 수 없기 때문에 단지 바이트 동작을 호출하기 위한 명령이다. 예제 7은 OWBlock의 코드 예제이다.
// OWBlock – writes/reads a block of data
// block – block of data
// return – Success or failure of the operation.
uchar OWBlock (uchar *block, uchar len)
{
uchar buffer[2];
int i;
for(i=0;i<len;i++)
{
owWriteByte(block[i]);
buffer[0] = setReadPointerCommand; // The read pointer value is 0xE1
buffer[1] = readDataRegister; // The read data register value is 0xE1
if(!I2CBus_write(&buffer[0],2))
{
return FAILURE;
}
else
block[i] = I2CBus_read();
}
return SUCCESS;
}
예제 7. OWBlock 코드
5.6 OWSearch/1-WIRE 트리플렛 명령
트리플렛 (Triplet) 명령(0x78)은 1-Wire 라인에 3개의 타임 슬롯, 2개의 읽기 타임 슬롯 및 1개의 쓰기 타임 슬롯을 발생시킨다. 방향 바이트(DIR)는 쓰기 타임 슬롯의 유형을 결정한다(그림 9). 예제 8은 1개의 소자만 연결되어 있는 경우 검색 명령을 사용한 1-Wire 트리플렛 명령을 보여준다. 1-Wire 검색 알고리즘의 자세한 설명은 1-Wire 트리플렛 명령을 위한 I²C 구성이 설명되어 있는 애플리케이션 노트 187을 참조한다.
 그림 9. 1-Wire 트리플렛. 1-Wire 라인에서 ROM 검색 함수를 수행한다. 1-Wire 함수를 완료하려면 아이들 시간이 필요하다. 그런 다음 읽기 모드에서 소자에 액세스하여 1-Wire 트리플렛 명령으로부터 결과를 가져온다.
// Global value for the current serial number
uchar SearchSerialNum[8];
// oneWireSearch
//
// Does a 1-Wire search using the 1-Wire Triplet command.
//
// resetSearch – Reset the search(1) or not(0).
// lastDevice - If the last device has been found(1) or not(0).
// deviceAddress – The returned serial number.
//
// returns SUCCES or FAILURE
//
uchar OWSearch(uchar resetSearch, uchar *lastDevice, uchar *deviceAddress)
{
uchar retVal = FAILURE;
uchar bit_number = 1;
uchar last_zero = 0;
uchar serial_byte_number = 0;
uchar serial_byte_mask = 1;
uchar firstBit, secondBit, dir;
uchar i = 0;
if(resetSearch)
{
lastDevice = 0;
LastDiscrepancy = 0;
}
// if the last call was not the last one
if (!(*lastDevice))
{
// reset the 1-wire
// if there are no parts on 1-wire, return FALSE
if(!OWReset())
{
// reset the search
lastDevice = 0;
LastDiscrepancy = 0;
return FAILURE;
}
// Issue the Search ROM command
OWWireByte(0xF0);
// loop to do the search
do
{
if (bit_number < LastDiscrepancy)
{
if(SearchSerialNum[serial_byte_number] & serial_byte_mask)
dir = 1;
else
dir = 0;
}
else
{
// if equal to last pick 1, if not then pick 0
if(bit_number==LastDiscrepancy)
dir = 1;
else
dir = 0;
}
if(!owTriplet(&dir, &firstBit, &secondBit))
{
return FAILURE;
}
// if 0 was picked then record its position in LastZero
if (firstBit==0 && secondBit==0 && dir == 0)
{
last_zero = bit_number;
}
// check for no devices on 1-wire
if (firstBit==1 && secondBit==1)
break;
// set or clear the bit in the SerialNum byte serial_byte_number
// with mask serial_byte_mask
if (dir == 1)
SearchSerialNum[serial_byte_number] |= serial_byte_mask;
else
SearchSerialNum[serial_byte_number] &= ~serial_byte_mask;
// increment the byte counter bit_number
// and shift the mask serial_byte_mask
bit_number++;
serial_byte_mask <<= 1;
// if the mask is 0 then go to new SerialNum[portnum] byte serial_byte_number
// and reset mask
if (serial_byte_mask == 0)
{
serial_byte_number++;
serial_byte_mask = 1;
}
}
while(serial_byte_number < 8); // loop until through all SerialNum[portnum]
retVal = FAILURE;
// if the search was successful then
if (bit_number == 65)//|| crcl))
{
// search successful so set LastDiscrepancy,LastDevice
LastDiscrepancy = last_zero;
if(LastDiscrepancy==0)
*lastDevice = SUCCESS;
else
*lastDevice = FAILURE;
for(i=0; i<8; i++)
{
deviceAddress[i] = SearchSerialNum[i];
}
return SUCCESS;
}
}
// if no device found then reset counters so next 'next' will be
// like a first
if (!retVal || !SearchSerialNum[0])
{
LastDiscrepancy = 0;
*lastDevice = FAILURE;
retVal = FAILURE;
}
return retVal;
}
// oneTriplet
//
// Uses the 1-Wire Triplet command.
//
// dir – Returns the direction that was chosen (1) or (0).
// firstBit - Returns the first bit of the search (1) or (0).
// secondBit – Returns the complement of the first bit (1) or (0).
//
// returns SUCCES or FAILURE
//
uchar owTriplet(uchar *dir, uchar *firstBit, uchar *secondBit)
{
uchar buff[3];
uchar test;
buff[0] = 0x78;
if(*dir>0)
*dir = (uchar)0xFF;
buff[1] = *dir;
if(!I2CBus_write(&buff[0],2))
{
lcd_putchar('f');
}
if(!I2CBus_read(&buff[2],1))
{
return FAILURE;
}
else
{
test = buff[2] & 0x20;
if(test == 0x20)
*firstBit = 1;
else
*firstBit = 0;
test = buff[2] & 0x40;
if(test == 0x40)
*secondBit = 1;
else
*secondBit = 0;
test = buff[2] & 0x80;
if(test == 0x80)
*dir = 1;
else
*dir = 0;
return SUCCESS;
}
return FAILURE;
}
예제 8. OWSearch 코드
6. 확장 1-WIRE 동작
6.1. OWSpeed
예제 9는 DS2482를 사용하여 1-Wire 버스의 속도를 변경하는 방법을 보여준다. 오버드라이브 또는 표준 속도를 사용할 수 있다.
// OWSpeed – changes the 1-Wire speed to normal or overdrive.
// A Overdrive match rom or overdrive skip rom will be needed.
//
// speed – overdrive (Overdrive) or standard (Standard) speed.
// state_config – The current configuration byte settings.
//
// return – success or failure of the operation.
//
uchar OWSpeed(uchar speed, uchar state_config)
{
uchar buffer[2];
buffer[0] = writeConfigCommand;
if(speed == Overdrive)
buffer[1] = (state_config | 0x08) & 0x7F;
else
buffer[1] = (state_config | 0x80) & 0xF7;
if(!I2CBus_write_packet(buffer,2))
{
return FAILURE;
}
return SUCCESS;
}
예제 9. OWSpeed 코드
6.2. OWLevel
예제 10은 DS2482를 사용하여 1-Wire 버스의 레벨을 변경하는 방법을 보여준다. 일반 또는 전력 공급 모드를 사용할 수 있다.
// OWLevel
//
// level – Normal or Power Delivery mode
// state_config – The current configuration settings
//
// Returns if the operation was Successful or not.
//
uchar OWLevel(uchar level, uchar state_config)
{
uchar buffer[2];
buffer[0] = writeConfigCommand;
// NORMAL = 0, POWER_DELIV = 1
if(level == NORMAL)
buffer[1] = (state_config | 0x01) & 0xEF;
else
buffer[1] = (state_config | 0x10) & 0xFE;
if(!I2CBus_write_packet(buffer,2))
{
return FAILURE;
}
return SUCCESS;
}
예제 10. OWLevel 코드
6.3. OWReadBitPower
예제 11은 1-Wire 비트를 읽고 전력 공급을 구현하는 OWReadBitPower를 위해 사용되는 코드를 보여준다. 구성 레지스터에서 강한 풀 업 (SPU) 비트를 인에이블하면 DS2482는 다음 비트 또는 바이트 통신 후 능동적으로 1-Wire 라인을 하이(high)로 올려놓는다.
// OWReadBitPower
//
// config_byte – current configuration settings
// delay – ms delay used before disabling active pullup
//
// Returns the bit information read.
//
uchar OWReadBitPower(uchar config_byte)
{
uchar buffer[2];
uchar return_bit;
buffer[0] = writeConfigCommand;
buffer[1] = (config_byte | 0x04) & 0xBF;
// Sets strong pullup active so after the next byte or bit
// strong pullup will be active
if(!I2CBus_write_packet(buffer,2))
{
Error;
}
return OWReadBit();
}
예제 11. OWReadBitPower 코드
6.4. OWWriteBytePower
예제 12는 1-Wire 바이트를 쓰고 전력 공급을 구현하는 OWWriteBytePower에 사용되는 코드이다. 구성 레지스터에서 강한 풀 업 (SPU) 비트를 인에이블하면, DS2482는 다음 비트 또는 바이트 통신 후 능동적으로 1-Wire 라인을 하이(high)로 올려놓는다.
// OWWriteBytePower
//
// config_byte – current configuration settings.
// wrbyte – byte to be written before the strong pullup is active
// delay – ms delay used before disabling active pullup
//
// Returns failure or success of the operation.
//
uchar OWWriteBytePower(uchar config_byte, uchar wrbyte)
{
uchar buffer[2];
buffer[0] = writeConfigCommand;
buffer[1] = (config_byte | 0x04) & 0xBF;
// Sets strong pullup active so after the next byte or bit
// strong pullup will be active
if(!I2CBus_write_packet(buffer,2))
{
return FAILURE;
}
OWWriteByte(wrbyte);
return SUCCESS;
}
예제 12. OWWriteBytePower 코드
결론
DS2482는 I²C 명령을 1-Wire 통신으로 변환한다는 것을 성공적으로 입증하였다. 본문에서는 DS2482 I²C 1-Wire 라인 드라이버를 사용하여 구현되는 완벽한 1-Wire 인터페이스 솔루션이 제시되었다. 코드 예제는 I²C 통신 포트가 있는 모든 호스트 시스템에서 쉽게 구현할 수 있으며, 완벽한 C 구현도 다운로드할 수 있다.
1-Wire는 Maxim Integrated Products, Inc.의 등록상표이다.
의견을 보내주세요! 위 내용이 도움이 되셨나요? 여러분의 의견을 기다립니다 — Maxim은 보내주신 정정이나 제안사항을 반영하고 있습니다.
이 페이지를 평가하고 의견을 보내주십시오.
자동 업데이트
관심있는 분야의 애플리케이션 노트가 나올 때 자동으로 업데이트 받고 싶으세요? 그렇다면 EE-Mail™을 신청하십시오.
| 추가 정보 | |
APP 3684: Mar 20, 2008
|
|
|
|
다운로드, PDF 형식 (102kB)
AN3684,
AN 3684,
APP3684,
Appnote3684,
Appnote 3684
|
|