This is my first 'proper' go with Swordfish - so be gentle.
I've checked electrical bits on my pcb several times - looks OK. Note my pcb also has an SD/MMC connector - that bit works perfectly.
I have been trying to move my code from my tests in ME dsBasic where it worked OK.
My code starts:
Code: Select all
// device and clock...
Device = 18F2520
Clock = 8
' Include Libraries:-
Include "SI2C.bas"
Include "SDFileSystem.bas"
Include "usart.bas"
Include "Convert.bas"
// SD file system settings, usart and soft I2C port numbers
#option SD_SPI = MSSP //
#option I2C_SCL = PORTA.4 // Use Software I2C
#option I2C_SDA = PORTA.5
Code: Select all
// Initialise
Sub InitStart()
SetBaudrate(br9600)
Address = 0
SI2C.Initialize
'adcon1=%1111
End Sub
Code: Select all
// Set Time to DS3232
Sub Set_Time()'ByRef TimData() As Byte)
SI2C.Start ' Do a write so that we
SI2C.WriteByte(%11010000) ' can set to byte (0)
SI2C.WriteByte($00)
SI2C.WriteByte(TimData(2)) ' Seconds All in Hex
SI2C.WriteByte(TimData(1)) ' Minutes
SI2C.WriteByte(TimData(0)) ' Hours
SI2C.WriteByte($01) ' Day 1
SI2C.WriteByte(TimData(3)) ' Date
SI2C.WriteByte(TimData(4)) ' Month
SI2C.WriteByte(TimData(5)) ' Year
SI2C.WriteByte($10) ' Set 1Hz pulse on SQWOUT
SI2C.Stop
End Sub
// READ DS3232 RTC registers for time and temp
Sub Get_Time()
SI2C.Start
SI2C.WriteByte(%11010000) ' Do a write so that we
SI2C.WriteByte($00) ' can set to byte (0)
SI2C.Restart ' Restart
SI2C.WriteByte(%11010001) ' Send Read command
For I=0 To 20 ' Read first 20 bytes
I2CData(I)= SI2C.ReadByte
SI2C.Acknowledge(I2C_ACKNOWLEDGE)
Next
I = I+1
I2CData(I)= SI2C.ReadByte
SI2C.Acknowledge(I2C_NOT_ACKNOWLEDGE)
SI2C.Stop
' Now the temp bytes
TempHB = I2CData(17)<<1 ' Shift back and forward by
TempHB=TempHB>>1 ' one byte to remove bit 8
TempLB=I2CData(18)>>6 ' Only top 2 bits used
TempLB = TempLB * 3
TempSign = I2CData(17)>>7 ' Get bit 8 of first byte
If TempSign = 1 Then ' Negative temp
TempHB = I2CData(17) Xor $FF ' Twos compliment convert
End If ' Bit 8 now 0
End Sub
Code: Select all
InitStart()
USART.Write("Starting..", 13, 10)
' Set time HH:MM:SS DD:mm:YY
TimData(0) = $12
TimData(1) = $00
TimData(2) = $00
TimData(3) = $09
TimData(4) = $06
TimData(5) = $07
Set_Time()
Get_Time()
For I = 0 To 20
GenByte = I2CData(I)
USART.Write("Time Val: ",DecToStr(GenByte,3), 13, 10)
Next
Sorry for great long listing, but this forum doesn't seem to give the scroll bars for code inserts like the Proton forum. Please excuse the comments and odd code, they are leftover from all sorts of trials-and-errors.
Anyway, when I print out the array TimData() all I get is 255 followed by a pile of zeroes.
So, I 'scoped the pins A.4 and A.5 directly on the PIC which I had configured for soft SCL and SDA. Nothing. There seems to be no activity at these pins.
SCL and SDA are tied high via 5k6 res. Please note: I have touched SCL and SDA down to ground via 4K7 res and viewed scope to poved that the pins weren't accidentally shorted high. All OK. Power and ground OK. Backup battery connected - yes, I have read DS3232 data sheet.
Any idea what's gone wrong?
Am I missing anything other than a brain?
Thanks.
P.S. Typing is very tricky here as keystroke characters keep being ignored, so please excuse any typos. I blame Explorer.