OneWire Communication Library

OneWire Communication Library

Overview

1-Wire® products provide combinations of memory, mixed signal, and secure authentication functions via a single contact serial interface. With both power and communication delivered over the serial protocol, 1-Wire devices are unmatched in their ability to provide key functions to systems where interconnect must be minimized.

This is a library written for the mikroPascal compilers to interface to these devices on a single bus. The library also includes functions that allows the master device to discover the number of slave devices on the bus and read there serial numbers.

Library functions

The oneWire library exports the following functions that can be used directly in your main program

         1.  procedure oneWire_Init(var aPort : word; aPin : word);

This procedure initializes the oneWire library on the given Port and Pin.
It must be called before any other library functions are used.

            2.  function oneWire_Reset : word;

Issues a reset signal on the oneWire bus.

        3.  function oneWire_ReadByte : word;

Returns one byte from the oneWire bus.

        4.  procedure oneWire_WriteByte(aData : word);

Writes one byte to the oneWire bus.

        5.  function oneWire_Search(aFirst : boolean; var aAddress : array[0..7] of byte) : boolean;

This function searches for active devices on the oneWire bus. When the result is TRUE, the device's address is available in the aAddress variable.
The function should be used in a recursive loop to find all the devices on the oneWire bus.

Usage Example

For a complete example on how to use the library, please download the source code from the attacement section at the bottom of the page

begin
  ADPCFG := 0xFFFF;                    // Configure AN pins as digital I/O
  LCD_Init(PortD, 2, 3, 4, 5, 6, 7);   // Init the LCD to show the temp
  oneWire_Init(PortD, 10);             // Init the one wire library

  LCD_Cmd(LCD_Clear);
  Lcd_Out(1, 2, 'Temperature:   ');

  Lcd_Chr(2,13, 223);                  // Print degree character,
  Lcd_Chr(2,14, 'C');                  // 'C' for Centigrades

  while (TRUE) do
  begin
    oneWire_Reset();                 // Onewire reset signal
    oneWire_WriteByte(0xCC);         // Issue command SKIP_ROM
    oneWire_WriteByte(0x44);         // Issue command CONVERT_T
    Delay_us(120);

    oneWire_Reset();                 // Onewire reset signal
    oneWire_WriteByte(0xCC);         // Issue command SKIP_ROM
    oneWire_WriteByte(0xBE);         // Issue command READ_SCRATCHPAD
    Delay_ms(400);

    temp :=  oneWire_ReadByte();
    temp := (oneWire_ReadByte() shl 8) + temp;

    Display_Temperature(temp);       // Show the temp on the LCD
  end;
end.

Attachments

File name File version File size
OneWire library for mikroPascal v1.0 12.03 KB
OneWire search documentation 185.24 KB

 
Shopping Cart
0 items
 
Riecktron Electronics © 2012