IOIOlib 3.2 Tested and is good for I2C
:sign0060:
IOIOlib 3.2 Tested and is good for I2C with DS1307. pin25 & 26 used.
code:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim period As Int
Dim TimerLoop As Timer
Dim btnSend As Button
Dim btnSetUp As Button
Dim Label1 As Label
Dim Label10 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Label5 As Label
Dim Label6 As Label
Dim Label7 As Label
Dim Label8 As Label
Dim Label9 As Label
Dim rbtn_loop As RadioButton
Dim rbtn_Single As RadioButton
Dim spn_TWIRate As Spinner
Dim spn_Twimode As Spinner
Dim spn_Addbit As Spinner
Dim txt_Readbytelength As EditText
Dim txt_Writebytelength As EditText
Dim spn_Period As Spinner
Dim txtRX As EditText
Dim txtAddress As EditText
Dim PeriodMap As Map
Dim p_uart As Panel
Dim lbStatus As Label
Dim YOYO As IOIO
Dim led As DigitalOutput
Dim go As Boolean
Dim TPeriod As Int
Dim looped As Boolean
Dim LedFlag As Boolean
Dim TWI As TwiMaster
Dim chk_SMBUS As CheckBox
Dim smBUS As Boolean
Dim TWIMODE As Int
Dim TWIRATE
Dim WriteByteLength As Int
Dim ReadByteLength As Int
Dim tenbitadd As Boolean
Dim TWIaddress As Int
'Dim TWI As TwiMaster
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("aI2C")
activity.Title="IOIO I2C TEST READ DS1307"
If FirstTime Then
activity.AddMenuItem("UART","aUART")
activity.AddMenuItem("I2C","aI2C")
activity.AddMenuItem("SPI","aSPI")
activity.AddMenuItem("IO","aIO")
activity.AddMenuItem("ADC","aADC")
SetSpinner
'default mode0,DA=4, CL=5, rate=100KH)
spn_Twimode.SelectedIndex=2
spn_TWIRate.SelectedIndex=0
spn_Period.SelectedIndex=4
spn_Addbit.SelectedIndex=0
txt_WriteByteLength.text=1
txt_ReadByteLength.text=7
txtAddress.Text="104"
TimerLoop.Initialize("TimerLoop",1000)
go=False
looped=False
rbtn_Single.Checked=True
YOYO.Initialize
YOYO.WaitForConnect()
led = YOYO.OpenDigitalOutput(0,led.OP_NORMAL ,True) ' Enable LED_PIN for output
getSetUPValue
TWI=yoy
penTwiMaster(2,Twi.RATE_100KHz,False)
Dim i As Int
Dim wBuffer(2) As Byte
Dim rBuffer(7) As Byte
Dim Rs() As Boolean
Dim suc As Boolean
Dim tmp As String
For i=1 To 5
wBuffer(0)=0
If twi.IsInitialized=True Then
result=TWI.WriteRead(0x68,False,wbuffer,1,rBuffer,0)
result=TWI.WriteRead(0x68,False,wbuffer,0,rBuffer,7)
If result=True Then
lbStatus.Text="Read " & 7 & " bytes. @ " & DateTime.Time(DateTime.Now)
txtRX.Text= Bit.ToHexString(rbuffer(6)) & "/" & _ 'sec
Bit.ToHexString(rbuffer(5)) & "/" & _ 'min
Bit.ToHexString(rbuffer(4)) & " " & _ 'hour
Bit.ToHexString(rbuffer(2)) & ":" & _ 'day
Bit.ToHexString(rbuffer(1)) & ":" & _ 'month
Bit.ToHexString(rbuffer(0)) 'year
End If
Else
Msgbox("NOT ready","")
End If
waitms(1000)
Next
End If
End Sub
Project will be posted later.
Best,
Eric