PDA

View Full Version : Trouble with RS-232 BS2px on Professional Development board.



Firestone1
01-27-2006, 02:46 AM
Hi.

This is my first post on this forum, but i have been looking for a while.

Im trying to send commands to a external modem using serin, serout through the extra rs232 port om pro development board.

The problem is that its not reliable. Some times it working fine and sometimes i get what looks like the signal out of sync.

I've tried everything I can think of now. Switching powersupplies, cables, extra grounding etc.
I have stripped the code for everything, without success.

This is what debugwindow should look like and some times it does:

+IPR: (0,300,1200,2400,4800,9600,19200,38400,57600,11520 0)



OK

But most of the time it looks like:

Hh) bš‚‚bŠ’‚‚b
’‚‚b‚‚bʲ‚‚bŠ’‚‚bš¢‚‚b‚‚bŠŠ’‚‚Jj


OK

... The strange thing is that its not garbage. when it dont work it always looks like this. Also that OK at the end always is correct.

I have set the modem to Fixed 1200 baudrate and flowcontrol off. I've also tried flowcontrol RTS/CTR But with the same result.
I've tried autobaud.. I've tried other speeds, 2400 always produce garbage, 9600 dont seem to work at all.
When connecting the modem to a computer using hyperterminal everything works perfect.

Code:



' {$STAMP BS2px}
' {$PBASIC 2.5}

test VAR Byte
start:
PAUSE 3000
SEROUT 14, 3313, ["AT+IPR=?", CR, LF ]

main:
SERIN 12, 3313,[test]
DEBUG test
GOTO main




Does anyone have an idea? Is the goto command to slow even for 1200 baud? Why does it works sometimes..
Please anyone, help!

Modem type is: GPRS Terminal Modem, Ter-gx101 S from Round Solutions.

/ Rickard

Bruce Bates
01-27-2006, 03:39 AM
Rickard -

You are sending the command once, then fetching the reply once. That apears to work okay, but then you go back to re-fetch the reply again and again, without issuing another command. Is that what you really want to be doing. or do you want to send the command, receive a reply, and then go back and repeat the ENTIRE process? If so, the last instruction should be GOTO Start, not GOTO Main.

Regards,

Bruce Bates

Jon Williams
01-27-2006, 03:52 AM
Since you're using a BS2px I suggest you use the SPSTR modifier to buffer the modem output into the Scratchpad;trying to catch characters one at a time in a loop like you're doing is not going to be reliable.

You might want to add a Conditional Compilation block to set the baudmode as well -- this will make it easier to experiment with different baud rates and ensure you get the right values in the program. I've attached a StampWorks 2 program that uses the external serial port on the PDB (with flow control). It has a CC block that you can paste write into your program.

In the end, you might end up with something like this:

SERIN Rx, Baud, (SPSTR 58) ' capture 58 characters from modem
FOR idx = 0 TO 57' display capture
GET idx, char
DEBUG char
NEXT

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Firestone1
01-27-2006, 04:14 AM
Thanks for the rapid answers!

Bruce: Yes I know. This was just a test loop but thanks for the note. I have restarted the program for every run.

Jon:Many thanks for the tip.I'll try that and see what I get. (Its 9pm here in sweden and I have promised my family some really late dinner..:-))

I'll get back...

/Rickard

Firestone1
01-27-2006, 06:59 AM
Still no luck..

I thougt I noticed a change when I hade the board turned off for a while. Then I got three correct answers in a row before getting a wrong one. It's like the stamp doesn't get the first bit and then go wild for a while. Then there is a small break before the modem writes OK and the stamp have time to catch up.

Can I in some way se if the flowcontrol works as it should? I cant see any kind of difference.

Wrote the output in hex to see if it is a bit swap of some kind but I haven't found a pattern yet anyway..

Faulty:

48 68 29 A 25 A5 2 42 82 62 9A 82 82 62 8A 92 82 82 62 92 A2 82 82 62 A2 C2
82 82 62 CA B2 82 82 62 8A CA 92 82 82 62 9A C2 A2 82 82 62 AA BA B2 82 82 6
2 8A 8A AA 92 82 82 4A 6A A

Correct:

A 2B 49 50 52 3A 20 28 30 2C 33 30 30 2C 31 32 30 30 2C 32 34 30 30 2C 34 38
30 30 2C 39 36 30 30 2C 31 39 32 30 30 2C 33 38 34 30 30 2C 35 37 36 30 30
2C 31 31 35 32 30 30 29 D A




' {$STAMP BS2px}
' {$PBASIC 2.5}

test VAR Byte
idx VAR Byte
start:
PAUSE 3000
SEROUT 3, 3313, ["AT+IPR=?", CR, LF ]
SERIN 1\2, 3313, 2000,GoOn, [SPSTR 61] ' capture 58 characters from modem
GoOn:
FOR idx = 0 TO 60 ' display capture
GET idx, test
DEBUG test
NEXT

DEBUG CR,LF
GOTO start




As usual I thougt this should be the easy part...

/Rickard

Jon Williams
01-27-2006, 09:45 AM
If you use flow control then you can receive one character at a time and forego SPSTR -- I think that you're going to want that in both directions to get this to work. I suspect the modem is responding before the Stamp is ready with SERIN. You may also need a pull-up or pull-down on the CTS pin (from the Stamp) so that the modem doesn't try to respond while SERIN is being loaded.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

Firestone1
01-27-2006, 04:42 PM
Ok, I think I understod the first part abaut flowcontrol on serout also.




' {$STAMP BS2px}
' {$PBASIC 2.5}
Rx CON 1
Tx CON 3
CTS CON 2
RTS CON 15
test VAR Byte
idx VAR Byte
start:
PAUSE 3000

HIGH CTS
PAUSE 50
LOW CTS

SEROUT Tx\RTS, 11505, ["AT+IPR=?", CR, LF ]

'PAUSE 200 ' wait a while shouldn't be an issue if CTS worked..
nytt:
SERIN Rx\CTS, 11505, 2000,GoOn, [SPSTR 60] ' capture 58 characters from modem
GoOn:
FOR idx = 0 TO 59 ' display capture
GET idx, test
DEBUG test
NEXT

DEBUG CR,LF
GOTO start




Tried both Low CTS and HIGH CTS and in combination both directions to se if the modem doesn't understand. Nothing worked. Also if I take the comment away for the pause after serout it never works. Shouldn't that work if CTS works as it should. I will take my ocilloscope at work and look whats really happens on the serial port. My guess is that something is broken. I still also have a feeling that it works better when the board have been switched of for a while. I really dont like that kind of symptoms.

I also dont like that the manual states that the modem pauses 100ms before returning response for almost every command.

As you can se I switched to 7E1 to se if that helped, I was told that parity would be more reliable. Yea, right..

Many, many thanks for the help so far. I really apprichiate the rapid response. Sorry for the sometimes bad english.

// Rickard

Firestone1
02-18-2006, 04:12 AM
Just wanted to update on this problem.

Problem solved.

As always its some kind of not understanding whats happening. In this case the modem had a "local echo" Doesn't all modems?

When I switched that of, it all started to work correctly. (ATE0)

So now you know.

Best regards
Rickard