After finally resolving the USB TX interface from the PIC to the PC I am now trying to resolve the RX interface at the PIC from the PC. I am seeing a strange anomaly that I have not been able to trace. Any advice or help on this would be greatly appreciated.
I can see that the Buffers being sent by the PC are correct. But the values received at the PIC don't match what was sent by the PC....I know this because I stepped the PBPro code with MCSP ICD to see what each corresponding buffer value was when received. Here is a table showing the transmitted and corresponding received values:
Sent by PC Rcvd by PIC
1 1
05 4
04 3
03 5
05 3
04 9
09 0
It is almost like the sent values were scrambled onto different receive buffers.
Here is the PC VB6 code that is transmitting the buffers and I will also list the PBPro code for the PIC's receiving buffers:
Code:
' Send BCD clock setting via USB to the FillMonitor to reset real-time-clock
' BufferOut(0) = Report id => always 0
'Set FM reset flag if resetting EEPROM data & restarting the MCU
If FMReset = True Then
BufferOut(1) = 1
Else
BufferOut(1) = 0
End If
BufferOut(2) = CInt(strTime_hr) ' first data item, etc etc
BufferOut(3) = CInt(strTime_mins)
BufferOut(4) = CInt(strTime_secs)
BufferOut(5) = CInt(strDate_Month)
BufferOut(6) = CInt(strDate_Day)
BufferOut(7) = CInt(strDate_ Year)
' BufferOut(8) = n/a = 0
Here is the PIC PBPro code on the receive side:
Code:
' BufferIn (PC to PIC) Structure
'BufferIn(0) = ReportID => always 0
'BufferIn(1) is sent by PC as PORTB settings but used as a Flag
'ResetFM = BufferIn(1) ' PORTB is FM Reset flag..if set restarts MCU
'corHr = BufferIn(2) ' Corrected Hr setting from PC
'corMINs = BufferIn(3) ' Corrected MINs setting from PC
'corSecs = BufferIn(4) ' Corrected Secs setting from PC
'corMon = BufferIn(5) ' Corrected Mon setting from PC
'corDate = BufferIn(6) ' Corrected Date from PC
'corYr = BufferIn(7) ' Corrected Yr from PC
' Receive corrected FMReset flag/time/date from PC
ARRAYREAD USBRXBuffer,[ReportID,ResetFM,corHr,corMINs,corSecs, _
corMon,corDate,corYr]
IF ReportID = 0 Then ' Check for valid RX report
Write 224,ResetFM ' Record FM Reset flag state in EEPROM
WRITE 225,corMon ' Update PIC date/time from PC corrections
WRITE 226,corDate
WRITE 227,corYr
WRITE 228,corHr
Write 229,corMINS
Write 230,corSecs
Endif
' If FMReset flag set, reset RTC time to corrected time
HIGH ext_pwr ' Temporarily turn on power to SRF02 for I2C bus use
PAUSE 70 ' Delay to let I2C bus stabilize after SRF02 turn on
'I2CWrite SDA, SCL, RTCdevice, SecReg,[corSecs,corMINs,Corhr,day, _
' corDate,corMon,corYr]
Bookmarks