PIC received buffers don't match PC sent buffers via USB


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default PIC received buffers don't match PC sent buffers via USB

    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]

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    Jellis00,

    If you are using the EasyHID software you need to send the whole array of data, which is 8 bytes of data at a time. I have been using using this method for my latest project without any problems.

    Now, this is what I found out. The range of an array of data that you sent in VB6 would be between 1 an 8. The same array of data would have a range between 0 and 7 in PBP. In other words, a byte Data[1] in VB6 is the byte Data[0] in PBP, a byte Data[2] in VB6 is the byte Data[1] in PBP, and so on. Don't ask me why, I didn't write the EasyHID program.

    I hope that this helps. Let us know if you have any problems.

    Robert

  3. #3
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378


    Did you find this post helpful? Yes | No

    Default This solved this problem!

    Quote Originally Posted by rsocor01 View Post
    Jellis00,
    Now, this is what I found out. The range of an array of data that you sent in VB6 would be between 1 an 8. The same array of data would have a range between 0 and 7 in PBP. In other words, a byte Data[1] in VB6 is the byte Data[0] in PBP, a byte Data[2] in VB6 is the byte Data[1] in PBP, and so on. Don't ask me why, I didn't write the EasyHID program.
    By incrementing the index by one on my VB6 buffers for the data the PBPro incoming buffers picked up the right data. Thanks for solving this problem for me!

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts