Positron Compiler Documentation

HbStart

Source: Positron8 Compiler User Manual, PDF page 137

Syntax

HbStart

Overview

Send a Start condition to the I2C bus using the microcontroller's MSSP module.

Notes

Because of the subtleties involved in interfacing to some I2C devices, the compiler's standard Hbusin, and Hbusout commands were found lacking. Therefore, individual pieces of the I2C protocol may be used in association with the new structure of Hbusin, and Hbusout. See relevant sections for more information.

Example

' Interface to a 24LC32 serial EEPROM
'
  Device = 16F1829
                             ' Use a device with an MSSP module
  Declare Xtal = 16 ' Tell the compiler the device will be operating at 16MHz
  Declare Hserial_Baud = 9600 ' Set the Baud rate for HRsoutLn
  Dim bMyLoop as Byte
  Dim bArray[10] as Byte
'
' Transmit bytes to the I2C bus
'
  HbStart
                             ' Send a Start condition
  Hbusout 0b10100000
                             ' Target an EEPROM, and send a Write command
  Hbusout 0
                             ' Send the HighByte of the address
  Hbusout 0
                             ' Send the LowByte of the address
  For bMyLoop = 48 to 57
                             ' Create a loop containing ASCII 0 to 9
     Hbusout bMyLoop
                             ' Send the value of MyLoop to the EEPROM
  Next
                             ' Close the loop
  HbStop
                             ' Send a Stop condition
  DelayMs 10
                             ' Wait for the data to be entered into EEPROM matrix
'
' Receive bytes from the I2C bus
'
  HbStart
                             ' Send a Start condition
  Hbusout 0b10100000
                             ' Target an EEPROM, and send a Write command
  Hbusout 0
                             ' Send the HighByte of the address
  Hbusout 0
                             ' Send the LowByte of the address
  HbRestart
                             ' Send a Restart condition
  Hbusout 0b10100001
                             ' Target an EEPROM, and send a Read command
  For bMyLoop = 0 to 9
                             ' Create a loop
     bArray[bMyLoop] = Hbusin ' Load an array with bytes received
     If bMyLoop = 9 Then HbStop : Else : HbusAck ' Ack or Stop ?
  Next
                             ' Close the loop
  HRsoutLn Str bArray
                             ' Display the Array as a String

See also : HbusAck, HbRestart, HbStop, Hbusin, Hbusout.

Important Note.

The Hbus commands are now classed as legacy within the compiler, meaning they will not be supported for newer devices. This is because the new devices have so many different ways of performing I2C with their built-in peripherals, it would be a logistic nightmare to cater for all the differences per device family and still keep it simple for the user. Now that the Positron8 compiler has true procedures, it will be a straightforward case to create a set of libraries to use I2C from the chip’s hardware. The Bus commands and the I2Cin and I2Cout commands work just as good as the Hbus commands, and sometimes better.