PDA

View Full Version : Serial Data Issue



Scampy
- 9th September 2015, 23:53
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


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 ?

Scampy
- 10th September 2015, 08:30
OK seems it might be user error


For Counter = 0 to 1


should be


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 !

HenrikOlsson
- 10th September 2015, 08:42
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:


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....

Scampy
- 10th September 2015, 11:02
LOL - thanks anyway !