main:
do
inc counter 'loop counter, just for testing
high B.4 'just to see something on the scope
hserptr = 0 : ptr = 0 'reset pointers
hserout 0,($AA,$01,$1E,$02) 'ask for yaw angle data [Start byte,Read,RegAddr,Length)
pauseus 800 'anything below 100us (800@64MHz) makes the device very unhappy
; SerTxd( "Starting...", CR,LF )
; Do While ptr <> hSerPtr
; SerTxd( "Got ", #@ptrInc, CR, LF )
; Loop
; SerTxd( "---", CR, LF )
; ptr = 0
if hserinflag <> 0 and hserptr = 4 then 'only want new and complete data
if @ptr = $BB then 'valid response header
get 2, H_L_byte, H_H_byte 'load low and high bytes in the correct order into H_Word
hserinflag = 0 'reset hserinflag for next loop
low B.4
sertxd("Loop#: ",#counter," | Heading: ",#H_Word,CR,LF)
counter = 0 'reset loop counter, just for testing
else
sertxd("Heading error",CR,LF)
if @ptr = $EE then gosub UART_Error
endif
endif
pause 1000
loop
}
UART_Error:
get 1, data_byte
Select case data_byte
case $01
sertxd("WRITE SUCCESS",CR,LF)
case $03
sertxd("WRITE FAIL",CR,LF)
case $04
sertxd("REGMAP INVALID ADDRESS",CR,LF)
case $05
sertxd("REGMAP WRITE DISABLED",CR,LF)
case $06
sertxd("WRONG START BYTE",CR,LF)
case $07
sertxd("BUS OVER RUN ERROR",CR,LF)
case $08
sertxd("MAX LENGTH ERROR",CR,LF)
case $09
sertxd("MIN LENGTH ERROR",CR,LF)
case $0A
sertxd("RECEIVE CHARACTER TIMOUT",CR,LF)
endselect
return