BusOneWire
Base OneWire bus interface to be used by devices. Concrete implementations in MCU drivers should be passed to drivers.
Ref.: Maxim’s Application Note 187 1-Wire Seach Algorithm Ref.: Maxim’s Appliaction Note 27 Understanding and using Cyclic Rendundancy Checks
Const
NoError* = 0;
ErrorNoDevice* = -1;
ErrorTimeout* = -2;
ErrorBus* = -3;
SendReset* = 1;
NoReset* = 2;
ReadSlot* = 0FFX;
NoRead* = 0FFH;
CMD_RSCRATCHPAD* = 0BEX;
CMD_WSCRATCHPAD* = 04EX;
CMD_CPYSCRATCHPAD* = 048X;
CMD_RECEEPROM* = 0B8X;
CMD_RPWRSUPPLY* = 0B4X;
CMD_SEARCHROM* = 0F0X;
CMD_READROM* = 033X;
CMD_MATCHROM* = 055X;
CMD_SKIPROM* = 0CCX;
Types
Bus* = RECORD
ROM_NO*: ARRAY 8 OF CHAR; (* 8-byte ROM addres last found device *)
LastDiscrepancy*: UNSIGNED8;
LastFamilyDiscrepancy*: UNSIGNED8;
LastDeviceFlag*: BOOLEAN;
error*: INTEGER; (* last transfer error code or NoError if success *)
timeout*: UNSIGNED32; (* transfere timeout in ms. 0 or lower disable timeout check *)
END;
Procedures
Bus.Enable
Enable 1-wire bus
PROCEDURE (VAR bus- : Bus) Enable*;
Bus.Disable
Disable 1-wire bus
PROCEDURE (VAR bus- : Bus) Disable*;
Bus.Reset
Send reset slot and return true if devices is present on bus
PROCEDURE (VAR bus : Bus) Reset*(): BOOLEAN;
Bus.WriteBit
Write bit to 1-wire bus
PROCEDURE (VAR bus- : Bus) WriteBit*(bit : BOOLEAN);
Bus.ReadBit
Read bit from 1-wire bus
PROCEDURE (VAR bus- : Bus) ReadBit*(): BOOLEAN;
Bus.SendReceive
Send and optinal receive data on 1-wire bus * sendReset : Send reset signal at the start. SendReset or NoReset. * cmd : Address to array of bytes commands. Use ReadSlot to specify reading. * clen : Length of command array. * data : Address to optional array of read buffer. * dlen : Length of read buffer. * rStart : Index for reading to start (from 0). NoRead to disable reading.
Return TRUE if no error occured.
PROCEDURE (VAR bus : Bus) SendReceive*(sendReset : INTEGER; cmd : ADDRESS; clen : LENGTH; data : ADDRESS; dlen, rStart: LENGTH): BOOLEAN;
Bus.ResetSearch
Reset ROM search
PROCEDURE (VAR bus : Bus) ResetSearch*;
Bus.Search
Search ROM Ref. Maxim APPLICATION NOTE 187
PROCEDURE (VAR bus : Bus) Search*(cmd : BYTE): BOOLEAN;
Bus.Next
Find next device on 1-wire bus
PROCEDURE (VAR bus : Bus) Next*(): BOOLEAN;
Bus.ReadROM
Write ROM to memory area
PROCEDURE (VAR bus : Bus) ReadROM*(adr : ADDRESS);
Bus.GetROM
Write ROM to array
PROCEDURE (VAR bus : Bus) GetROM*(VAR x : ARRAY OF BYTE);
Crc8
Calculate (MAXIM-DOW) CRC8 of memory array
PROCEDURE Crc8*(adr : ADDRESS; len : LENGTH): CHAR;
Crc16
TODO : Verify if working crrectly
PROCEDURE Crc16*(adr : ADDRESS; len : LENGTH): UNSIGNED16;