Serial Data Issue


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Serial Data Issue

    Hi,

    I'm messing about with some old code for an Aquairum lighting controller that I build a few yesr back. Basically adding some functionality that I could now do with, and the ability to set the timings etc up via serial communications (using a bluetooth module). I have a simple method that when the PBP code detects the connecion it will send data when it receives a request from the PCB application. Then changes can be made and the controller updated at the click of a button, So the process is R is sent to the PIC and the PIC transmitts data, S is sent and the PIC receives data.

    The problam I'm having is that the PC application sends the correct PC time as a 6 byte string tagged to the end of the data string, but the PIC is not reading this string, but reads data that is at the end of the main string. I've used a comm sniffer, and the PIC is sending 96 bytes of data, and the data checks out as it should, and populates the text boxes in the application. When sending data back to the PIC, 96 bytes of data is sent, plus the 6 bytes of HH MM SS. (see screen capture attached)

    The RX section of the PBP code is
    Code:
    Term_RX:
    
    For Counter = 0 to 1
    HSERIN 1000, RX_Bombed, [DEC2 LightSetHR[Counter], DEC2 LightSetMN[Counter]]    'receive light on HR and MN for all 4 channels
    NEXT
    
    For Counter = 0 to 1
    HSERIN 1000, RX_Bombed, [DEC2 lightoffHR[Counter], DEC2 lightoffMN[Counter]]    'receive light off HR and MN for all 4 channels
    next
    
    For Counter = 0 to 3
    HSERIN 1000, RX_Bombed, [DEC2 fadesetHR[Counter], DEC2 fadesetMN[Counter]]                                'receive fade in HR value for all 4 channels
    NEXT
    
    For Counter = 0 to 3
    HSERIN 1000, RX_Bombed, [DEC2 fadeoutHR[Counter], DEC2 fadeoutMN[Counter]]                               'receive fade out HR value for all four channels
    NEXT
    
    HSERIN 1000, RX_Bombed, [DEC4 CH1_Min]                                          'receive min brightness value for all four channels
    HSERIN 1000, RX_Bombed, [DEC4 CH2_Min]
    HSERIN 1000, RX_Bombed, [DEC4 CH3_Min]
    HSERIN 1000, RX_Bombed, [DEC4 CH4_Min]
    
    HSERIN 1000, RX_Bombed, [DEC4 CH1_Max]                                          'receive max brightness value for all four channels
    HSERIN 1000, RX_Bombed, [DEC4 CH2_Max]
    HSERIN 1000, RX_Bombed, [DEC4 CH3_Max]
    HSERIN 1000, RX_Bombed, [DEC4 CH4_Max]
    
    HSERIN 1000, RX_Bombed, [dec2 TimeH]                                            'receive HR value from PC
    HSERIN 1000, RX_Bombed, [dec2 TimeM]                                            'receive Mn value from PC
    HSERIN 1000, RX_Bombed, [dec2 SS]
    
    lcdout $FE,$94,"HH ",dec TimeH
    lcdout $FE,$94+8,"MM ",dec TimeM
    I've added the lcdout commands to debug (try to) what values are being placed into TimeH and TimeM variables. I get 40 and 95 respectivly, which would be associated with the CHx_Max values as can be seen in the screen capture of the application. Adding up the bytes in the PBP code this comes to 102 which matches that being sent by the PC application

    I have a very similar application for my Vivarium controller that Tabsoft helped me with, so I know the application works, and have tried cutting and pasting the same section from that code and just change the variables accordingly, but still getting the 4095 value placed in the HHMM variable rather than the correct time.

    Any pointers as to what's going wrong ?
    Attached Images Attached Images   

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Data Issue

    OK seems it might be user error
    Code:
    For Counter = 0 to 1
    should be
    Code:
    For Counter = 0 to 3
    I'll test this later to confirm (thanks Tabsoft for checking the code) - I guess this is what happens when taking breaks from long sessions of coding and being distracted in-between testing !

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: Serial Data Issue

    Hi,
    I've only looked at this briefly but it looks to me as if you're sending 96 bytes but you are grabbing the data from the 86 first bytes of those:
    Code:
    Term_RX:
    
    ' 4 bytes per iteration, 2 iterations   =   8bytes
    For Counter = 0 to 1
      HSERIN 1000, RX_Bombed, [DEC2 LightSetHR[Counter], DEC2 LightSetMN[Counter]]    'receive light on HR and MN for all 4 channels
    NEXT
    
    ' 4 bytes per iteration, 2 iterations   =   8bytes
    For Counter = 0 to 1
      HSERIN 1000, RX_Bombed, [DEC2 lightoffHR[Counter], DEC2 lightoffMN[Counter]]    'receive light off HR and MN for all 4 channels
    next
    
    ' 4 bytes per iteration, 4 iterations   =   16bytes
    For Counter = 0 to 3
      HSERIN 1000, RX_Bombed, [DEC2 fadesetHR[Counter], DEC2 fadesetMN[Counter]]                                'receive fade in HR value for all 4 channels
    NEXT
    
    ' 4 bytes per iteration, 4 iterations   =   16bytes
    For Counter = 0 to 3
      HSERIN 1000, RX_Bombed, [DEC2 fadeoutHR[Counter], DEC2 fadeoutMN[Counter]]                               'receive fade out HR value for all four channels
    NEXT
    
    ' 4 x 4 bytes = 16 bytes
    HSERIN 1000, RX_Bombed, [DEC4 CH1_Min]                                          'receive min brightness value for all four channels
    HSERIN 1000, RX_Bombed, [DEC4 CH2_Min]
    HSERIN 1000, RX_Bombed, [DEC4 CH3_Min]
    HSERIN 1000, RX_Bombed, [DEC4 CH4_Min]
    
    ' 4 x 4 bytes = 16 bytes
    HSERIN 1000, RX_Bombed, [DEC4 CH1_Max]                                          'receive max brightness value for all four channels
    HSERIN 1000, RX_Bombed, [DEC4 CH2_Max]
    HSERIN 1000, RX_Bombed, [DEC4 CH3_Max]
    HSERIN 1000, RX_Bombed, [DEC4 CH4_Max]
    
    ' 3 x 2 bytes = 6 bytes
    HSERIN 1000, RX_Bombed, [dec2 TimeH]                                            'receive HR value from PC
    HSERIN 1000, RX_Bombed, [dec2 TimeM]                                            'receive Mn value from PC
    HSERIN 1000, RX_Bombed, [dec2 SS]
    
    lcdout $FE,$94,"HH ",dec TimeH
    lcdout $FE,$94+8,"MM ",dec TimeM
    /Henrik.

    EDIT: Ok, seems you found it while I was looking/typing....

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Serial Data Issue

    LOL - thanks anyway !

Similar Threads

  1. EEPROM or DATA issue with 16F1503
    By scasale in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th October 2013, 04:46
  2. Issue using DATA statement with 16F1933 in PBP2.60
    By bcd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th August 2010, 01:36
  3. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  4. Storing Data Issue
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2005, 13:40
  5. Multiplex serial data
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 19th May 2004, 00:28

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