Hi. I am trying to read poll then read the data off a RoboteQ motor controller. I can not use the hardware UART, its already being used for the main com. I have it working OK, its just not working great. It misses every now and again. The issue is any data sent to the RoboteQ is echoed back. So I transmit the request, then jump down and read the request. I think what is happening is I am not always getting down to read the entire echo. I have tried waiting for the carrage return too, with mixed results since there are a couple carrage returns echoed. The RoboteQ is 9600, 7 bit data, 1 start bit, 1 stop bit, even parity. I think I have it set up right. Once it goes into error it seems to keep erroring (timing out). Is there a way to clear the buffer (even though there really isn't any). I don't know I have been messing with this too long have tried a bunch of stuff with no total luck
Here are the relavent pieces of code.
'Roboteq Serial
RoboteQ_Baud con 8276 '9600 baud, even parity
'define ser2_CLROERR 1 (this seemed to have no effect)
define ser2_even 1
define ser2_bits 9 (I have tried 8 here too, same results??)
RoboteQ_TX var PORTC.5
RoboteQ_RX var PORTC.0
mainloop:
Motor_Val_L = 10
'command motor 2 forward (this works fine, it does echo back the command though, I ignor it)
SEROUT2 RoboteQ_TX, RoboteQ_Baud, ["!B", hex2 Motor_Val_L, 13]' endif
'qry the encoder, stores in the mailbox, sends the value back, but is
SEROUT2 RoboteQ_TX, RoboteQ_Baud, ["?Q0", 13]'querry encoder1
'qry to read counter MSB Mailbox
SEROUT2 RoboteQ_TX, RoboteQ_Baud, ["*88", 13]
'this is where I timeout from time to time. I have tried waiting for 13, "8", "*88", all with the same inconsitent results.
SERIN2 RoboteQ_RX, RoboteQ_Baud, 15 ,RoboteQ_timeout2,[WAIT("88"), hex2 Encoder1(0)]
... read other bytes here, don't seem to have as many issues with these, they are called with "*89", "*8A", and "*8B", so I only wait for the last digit, the 88 is hard since its two of the same, sometime I suspect I only get on, other times I get both 8s.
RoboteQ_timeout2_Return:
...
trasmit data back via hserial port. When it does not timeout, the value is correct.
goto mainloop
RoboteQ_timeout2:
high L3
pause 20
low L3
goto RoboteQ_timeout2_Return
Bookmarks