Loopback problem.
StephenMoore
Posts: 188
This I know is one of the most basic microcontroller problems and yet it is also one of the most time consuming.... asynchronous serial data comm.
I have Pin 0 jumped to Pin 1 on a Prop USB Protoboard.
Code Ex 1 one works, code Ex 2 gives gibberish.
Ex 1:
Ex 2:
Also, I really need to talk to a drill that is RS-232. Does anyone have any suggestions for a reliable and cheap CMOS to RS-232 converter?
sm
I have Pin 0 jumped to Pin 1 on a Prop USB Protoboard.
Code Ex 1 one works, code Ex 2 gives gibberish.
Ex 1:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 drillRx = 0 drillTx = 1 VAR byte char[128] OBJ pst: "Parallax Serial Terminal" drill: "FullDuplexSerial" PUB main | i, k pst.Start(115200) drill.Start(drillRx, drillTx, 0, 115200) waitcnt(clkfreq * 2 + cnt) repeat drill.str(@x2) i := 0 repeat strsize(@x1) char[i++] := drill.rx pst.str(@char) waitcnt(clkfreq+cnt) DAT x1 byte "0020000000001000", $0D,0 y1 byte "0000002000001000", $0D,0 rot1 byte "0000000000301000", $0D,0 x2 byte "-020000000001000", $0D,0 y2 byte "0000-02000001000", $0D,0 rot2 byte "00000000-0301000", $0D,0
Ex 2:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 drillRx = 0 drillTx = 1 VAR byte char[128] OBJ pst: "Parallax Serial Terminal" drill: "FullDuplexSerial" PUB main | i, k pst.Start(115200) drill.Start(drillRx, drillTx, 0, 115200) waitcnt(clkfreq * 2 + cnt) repeat drill.str(@x2) i := 0 waitcnt(clkfreq / 1000 + cnt) repeat while (char[i++] := drill.rxcheck) <> -1 pst.str(@char) waitcnt(clkfreq+cnt) DAT x1 byte "0020000000001000", $0D,0 y1 byte "0000002000001000", $0D,0 rot1 byte "0000000000301000", $0D,0 x2 byte "-020000000001000", $0D,0 y2 byte "0000-02000001000", $0D,0 rot2 byte "00000000-0301000", $0D,0
Also, I really need to talk to a drill that is RS-232. Does anyone have any suggestions for a reliable and cheap CMOS to RS-232 converter?
sm
Comments
>> repeat while (char[i++] := drill.rxcheck) <> -1
:= sets char[i++] to the value of drill.rxcheck
should that not be a comparison ( == ) ?
Never mind, I see what you are trying to do.
I don't think he wants a comparison there.
@sm,
What do you mean by "gibberish". I'm not sure how your comparison will work since "char" is a byte array and "-1" is only meaningful as a long.
I'd suggest using a long in the comparison with "-1" and then save the long to the byte array if it's not "-1".
I'm not sure about it either.
FullDuplexSerial.rxcheck says it returns a -1 if no byte available. I took -1 to be a signed twos complement byte value ($FF).
By gibberish I mean not the string I sent out.
Also, do char..char[i+3] receive the return value from rxcheck?
You have a conditional expression with side-effects, usually a bad idea. The ++ operator is incrementing i everytime round the loop stomping $FF bytes all over memory. Separate condition from effects:
rxcheck is trying to be both a predicate and a data-transfer operation, hence the confusion.
I changed Baud Rate to 9600 and get the following:
Which is better than gibberish but still short of the mark. Hasn't anyone tested FullDuplexSerial in loopback mode?
sm
Thanks for that subtlety.
Still, the program only works with the millisecond delay inserted between character reads. That does not seem right.
I may have the numbers off by 1 or 2, but you need to shorten the test string or increase the buffer sizes for this program to work properly.
For debugging the system I was using rxcheck to avoid locking up the program.
I still can't tell the difference between hardware problems and FullDuplexSerial problems in loopback mode. As I say, I can't read anything at all at 115200 baud in loopback mode.
Mike is pretty sharp, isn't he?
You might want to consider using a four port serial object. Tracy Allen's version is pretty slick and lets you easily set any size of buffers.
Here are my improvements:
1) Changed code to proper method for receiving characters:
2) Switched to "FullDuplexSerial4portPlus_0v3" and increased the rx/tx buffer sizes to eliminate character collisions
3) Downloaded SimpleIDE version 0.8.1 to take advantage of the project feature using the SPIN compiler and the built in console... very nice piece of software.
As it turns out I have three serial ports that are needed in this project:
1) Xbee to receive commands and report status with remote laptop
2) Arduino to control CNC moves (the Propeller does its own share of machine control too)
3) RoboteQ drill motor
So as it turns out I have saved 2 cogs by using Mr. Allen's 4 port Serial Driver. Thank you very much Duane.
Sincerely,
sm