This article describes simple wireless Dallas one-wire device ROM reader. It is intended as a base code for some more sophisticated access control system. We try some kind of access system in followings articles. Now, we are going to read 1-wire ROM code.
We use DDC-SE-01-dallas.c from DDC examples as a template for our project. In fact, we use functions for one-wire handling only and throw away the rest of the code. The main code periodically checks one wire device presence on DQ pin of IQRF module (PC3). If device is present, it checks, if previous readings was more than 1s ago, and then it reads ROM code, which is sent to another module. At the end of reading, startDelay(100) is executed and flag released = FALSE; is set. It’s protection against multiple reading.
Another part of main code checks if C8 handling packer arrived. If yes, pin C8 is set or cleared. It can be used for simple electromechanical lock door manipulation. There are three types of packets:
- “S1” – set C8.
- “C2” – clear C8.
- “C3” – set C8 for 100ms and then clear C8.
Source code for packet handling
// if some RF packet incoming if (checkRF(5)) { // read it.. if (RFRXpacket()) { // indicate incoming packet pulseLEDG(); if (bufferRF[0] == 'S') { // set output pin against the command if (bufferRF[1] == '1') _C8_OUT = 1; if (bufferRF[1] == '0') _C8_OUT = 0; if (bufferRF[1] == 'X') { _C8_OUT = 1; waitMS(100); _C8_OUT = 0; waitMS(10); } } } } |
Source code for One wire device manipulation
// if some OneWire device is present // READ ROM code if (OneWireReadRom()) { // if there some free time space between readings... if (released == TRUE) { // ...copy it to RF buffer and send it copyBufferCOM2RF(); DLEN = 8; PIN = 0; RFTXpacket(); pulseLEDR(); released = FALSE; startDelay(100); } } else { // if delay elapsed, allow ROM code sending if (isDelay()==FALSE) released = TRUE; } |
The most important function in this post is OneWireReadRom() function. It checks if any one-wire device is present and then reads the ROM code. It has boolean returned value. If device is present, TRUE value is returned. In other cases FALSE value I returned
// ********************************************************************* bit OneWireReadRom() // ********************************************************************* { // Setting the pin once to low is enough OneWire_IO_OUT = 0; // Reset pulse OneWireData0(); Delay5us( 500 / 5 ); // Reset pulse end OneWireData1(); // Next sequence is time precision critical GIE = 0; // Wait for presence pulse Delay5us( 70 / 5 ); // End of time precision critical sequence GIE = 1; // Presence pulse? if ( OneWire_IO_IN ) { // No presence, finish initialization sequence Delay5us( ( 500 - 70 ) / 5 ); return FALSE; } else { // Presence OK, finish initialization sequence Delay5us( ( 500 - 70 ) / 5 ); // OneWire: Read ROM OneWireWriteByte( 0x33 ); // Read 8 ROM bytes bufferCOM[0] = OneWireReadByte(); bufferCOM[1] = OneWireReadByte(); bufferCOM[2] = OneWireReadByte(); bufferCOM[3] = OneWireReadByte(); bufferCOM[4] = OneWireReadByte(); bufferCOM[5] = OneWireReadByte(); bufferCOM[6] = OneWireReadByte(); bufferCOM[7] = OneWireReadByte(); return TRUE; } } |
The full IQRF IDE project is attached. I tested it on TR-52D modules with OS 3.03, but I expect, the newer OS should works too. You can use E03-TR.c from basic examples for second module inserted to CK-USB-04, or you can use simple UART-IQRF adapter.
Hardware
I used DK-EVAL-04 as main board. It this case, DQ pin (1-wire data pin) is placed on C6, it means DK-EVAL-04 pin number 3. You have to use pull-up for this pin, so you can do it on small breadboard, as you can see on the picture. Additionaly there is 220R resistor between IQRF C8 pin (DK-EVAL-04, pin 1) and iButton probe LED. I used original Dallas DS9092L+, but you can use of course some cheap China product.

iButton reader prototype