Bstart
Source: Positron16 Compiler User Manual, PDF page 138
Syntax
Bstart
Overview
Send a Start condition to the I2C bus.
Notes.
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.
Example
' Interface to a 24LC32 serial EEPROM
Device = 24FJ64GA002
' Select the device to compile for
Declare Xtal = 8
Declare Hserial_Baud = 9600 ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Declare SCL_Pin = PORTB.3
' Select the pin for I2C SCL
Declare SDA_Pin = PORTB.4
' Select the pin for I2C SDA
Dim bLoop as Byte
Dim MyString as String * 20
RPOR7 = 3
' Make PPS Pin RP14 U1TX
'
' Transmit bytes to the I2C bus
'
Bstart
' Send a Start condition
Busout %10100000
' 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 bLoop = 48 to 57
' Create a loop containing ASCII 0 to 9
Busout bLoop
' Send the value of Loop to the EEPROM
Next
' Close the loop
Bstop
' Send a Stop condition
DelayMs 5
' Wait for data to be entered into EEPROM matrix
'
' Receive bytes from the I2C bus
'
Clear MyString
' Clear the string before we start
Bstart
' Send a Start condition
Busout %10100000
' 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 %10100001
' Target an EEPROM, and send a Read command
For bLoop = 0 to 9
' Create a loop
MyString[bLoop] = Busin ' Load a string with bytes received
If bLoop = 9 Then Bstop : Else : BusAck ' Ack or Stop ?
Next
' Close the loop
Hrsout MyString , 13
' Display the String