Positron Compiler Documentation

Bstart

Positron8 · Revision 4.0.6.5 · PDF page 122

Bstart

Send a Start condition to the I2C bus.

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

' Interface to a 24LC32 serial EEPROM
  Device = 16F1829        ' Select the device to compile for
  Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
  Declare Hserial_Baud = 9600  ' Set the Baud rate for HRsoutLn

  Dim MyLoop as Byte
  Dim Array[10] as Byte
'
' Transmit bytes to the I2C bus
'
  Bstart                  ' Send a Start condition
  Busout 0b10100000       ' Target an EEPROM, and send a Write command
  Busout 0                ' Send the High Byte of the address
  Busout 0                ' Send the Low Byte of the address
  For MyLoop = 48 to 57   ' Create a loop containing ASCII 0 to 9
     Busout MyLoop        ' Send the value of MyLoop to the EEPROM
  Next                   ' Close the loop
  Bstop                   ' Send a Stop condition
  DelayMs 10              ' Wait for the data to be entered into EEPROM matrix
'
' Receive bytes from the I2C bus
'
  Bstart                    ' Send a Start condition
  Busout 0b10100000         ' Target an EEPROM, and send a Write command
  Busout 0                   ' Send the High Byte of the address
  Busout 0                   ' Send the Low Byte of the address
  Brestart                   ' Send a Restart condition
  Busout 0b10100001         ' Target an EEPROM, and send a Read command
  For MyLoop = 0 to 9       ' Create a loop
     Array[MyLoop] = Busin   ' Load an array with bytes received
     If MyLoop = 9 Then Bstop : Else : BusAck ' Ack or Stop ?
  Next                     ' Close the loop
  HRsoutLn Str Array       ' Display the Array as a String
  Stop

See also: Bstop, Brestart, BusAck, Busin, Busout, HbStart, HbRestart, HbusAck,

Hbusin, Hbusout.

View original PDF page 122Open page in PDFOriginal PDF page 122