Thanks I noticed that one later but have left it out so I can call my routine with the packet start byte value pre-loaded into checksum now.
So I call the routine after loading checksum with either $AA or $87 (My 12 byte packet start byte) I then run the routine on the array and store the checksum in the last byte making twelve in all.
My main program - onfigs now looks like this. The checksum is commented out at present during some other testing.
Code:
'Main Program Start
Commloop: 'Start of Communications Loop
HSERIN [WAIT($87), STR BCMDATA\11] 'Wait for packet start $87 then Receive 11 bytes into array BCMDATA
'CheckSum = $87 'Load Checksum with packet start byte value
'Gosub CalcSum 'Gosub CalcSum to Calculate Checksum
HSEROUT [$87,str BCMDATA\11] 'Transmit 12 bytes inc packet start byte $87
HSERIN [WAIT($AA), STR BCMDATA\11] 'Wait for packet start $AA then Receive 11 bytes into array BCMDATA
'CheckSum = $AA 'Load Checksum with packet start byte value
'Gosub CalcSum 'Gosub CalcSum to Calculate Checksum
HSEROUT [$AA,str BCMDATA\11] 'Transmit 12 bytes inc packet start byte $AA
'Data txd/rxd test outputs known values below to check transmission & reception
Pause 32 'Pause for 16ms
HSEROUT [$AA,$10,$00,$00,$00,$20,$40,$61,$10,$01,$00,$74] 'Transmit 12 bytes
pause 32 'Pause for 16ms
HSEROUT [$87,$40,$58,$15,$6E,$10,$01,$32,$2F,$2F,$04,$39] 'Transmit 12 bytes
pause 32 'Pause for 16ms
goto CommlooP 'Goto Loop
CalcSum: 'Calculate Packet CheckSum Routine
For Count1 = 0 to 10 'For Count1 = 0 to 10 (Start 11 byte loop)
CheckSum = CheckSum + BCMDATA[Count1] 'Add Bytes
Next Count1 'Repeat until 11 bytes added
CheckSum = NOT CheckSum 'Not CheckSum
CheckSum = CheckSum + 1 'Add 1 to CheckSum
BCMDATA[11] = CheckSum AND $7F 'AND result
Return 'Return
Bookmarks