Hi Chris,
Thanks for your very kind offer!
I have not yet written a full set of routines to drive the I2C bus. I
have just been trying to get the controller to do something. Namely
perform a start and transer and address byte.
So All I have at the moment is a button on screen that when clicked
ends up calling the code below.
The Class Anbeyon.IOPOinter takes the Physical address and a size and
reseves and maps virtual memory. It contains two routines -> One to
read a 32 bit int and one to write a 32 bit int. They take an offfset
into the resevered/mapped memory and in the case of the write the data
to write.
As I explained - I know the read works as I can correctly detect the
state of the I2C bus. Also I know the write works as I can drive a a
couple of LEDS on my board.
I have been working from section 9.6.1 of the PXA255 deverlopers
manual.
Thanks
Anbeyon.....Code follows..
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Class I2C
' I2C Physical Location
Private Const I2C_PHYSICAL_ADDRESS As Long = &H40301680
' I2C Register Offsets
Private Const I2C_REG_IBMR As Integer = &H0 'Bus Monitor Register
Private Const I2C_REG_IDBR As Integer = &H8 'Data Bus Register
Private Const I2C_REG_ICR As Integer = &H10 'Control Register
Private Const I2C_REG_ISR As Integer = &H18 'Status Register
Private Const I2C_REG_ISAR As Integer = &H20 'Slave Address Register
' I2C Register Bits
' Bus Monitor Register Bits
Private Const I2C_IBMR_SDAS As Integer = &H1
Private Const I2C_IBMR_SCLS As Integer = &H2
' Databus Register Bits
Private Const I2C_IDBR_0 As Integer = &H1
Private Const I2C_IDBR_1 As Integer = &H2
Private Const I2C_IDBR_2 As Integer = &H4
Private Const I2C_IDBR_3 As Integer = &H8
Private Const I2C_IDBR_4 As Integer = &H10
Private Const I2C_IDBR_5 As Integer = &H20
Private Const I2C_IDBR_6 As Integer = &H40
Private Const I2C_IDBR_7 As Integer = &H80
' Control Register Bits
Private Const I2C_ICR_START As Integer = &H1
Private Const I2C_ICR_STOP As Integer = &H2
Private Const I2C_ICR_ACKNAK As Integer = &H4
Private Const I2C_ICR_TB As Integer = &H8
Private Const I2C_ICR_MA As Integer = &H10
Private Const I2C_ICR_SCLE As Integer = &H20
Private Const I2C_ICR_IUE As Integer = &H40
Private Const I2C_ICR_GCD As Integer = &H80
Private Const I2C_ICR_ITEIE As Integer = &H100
Private Const I2C_ICR_IRFIE As Integer = &H200
Private Const I2C_ICR_BEIE As Integer = &H400
Private Const I2C_ICR_SSDIE As Integer = &H800
Private Const I2C_ICR_ALDIE As Integer = &H1000
Private Const I2C_ICR_SADIE As Integer = &H2000
Private Const I2C_ICR_UR As Integer = &H4000
Private Const I2C_ICR_FM As Integer = &H8000
' Status Register Bits
Private Const I2C_ISR_RWM As Integer = &H1
Private Const I2C_ISR_ACKNACK As Integer = &H2
Private Const I2C_ISR_UB As Integer = &H4
Private Const I2C_ISR_IBB As Integer = &H8
Private Const I2C_ISR_SSD As Integer = &H10
Private Const I2C_ISR_ALD As Integer = &H20
Private Const I2C_ISR_ITE As Integer = &H40
Private Const I2C_ISR_IRF As Integer = &H80
Private Const I2C_ISR_GCAD As Integer = &H100
Private Const I2C_ISR_SAD As Integer = &H200
Private Const I2C_ISR_BED As Integer = &H400
'Slave Address
Private Const I2C_SLAVE_ADDRESS As Integer = &HFE
' I2C set up
Private Const I2C_SETUP As Integer = &H40E0
Function I2C_Open() as integer
Dim I2C_Regs As New Anbeyon.IOPointer(I2C_PHYSICAL_ADDRESS, &H28) '
resevere and map to virtual memory
Dim iBusState As Integer
Dim iCmd As Integer
' read bus monitor lines
iBusState = I2C_Regs.ReadInt32(I2C_REG_IBMR) ' This returns the state
of the bus
' set slave adddress
I2C_Regs.WriteInt32(I2C_SLAVE_ADDRESS, I2C_REG_ISAR)
' write control word
I2C_Regs.WriteInt32(I2C_SETUP, I2C_REG_ICR)
' put slave address byte in i2c buffer
I2C_Regs.WriteInt32(&HAA, I2C_REG_IDBR)
' write to control reg with i2C start bit set an transmit set
' this should transfer address byte
iCmd = I2C_SETUP Or I2C_ICR_START Or I2C_ICR_TB
I2C_Regs.WriteInt32(iCmd, I2C_REG_ICR)
End Function
End Class