Shop OBEX P1 Docs P2 Docs Learn Events
Serial input garbled with BS2 — Parallax Forums

Serial input garbled with BS2

WillWhiteWillWhite Posts: 15
edited 2006-02-09 15:12 in BASIC Stamp
Since my last question got answered so quickly I spent a bit more time trying to figure this one out in hopes that I'd stumble across an answer. Needless to say, I did not, so I figured I'd try to pick the brains of the folks on here again.

The following is the setup before my BS2 project:

PBX system outputs data on a 25 pin serial connection at 2400 7E1 to a dummy terminal which logs the data input.


I have put a 25 pin serial breakout box inline on the connection to give me access to the pins. I have the recieve data pin connected to a 22k resistor, and then into the BS2 pin #4.

Eventually I will be using this data, but just to make sure I am recieveing the correct information, I have set up a short program to display the data and compare it to the data on the terminal:

VAR number Byte
INPUT 4
DO
SERIN 4,8588,[noparse][[/noparse]number]
DEBUG number
LOOP WHILE 1 = 1



This code is intended to continuously loop the stamp to read the input from pin #4, output it to the debug window, and repeat forever, or untill I remove the power. I get the following as output in the debug window:

yi'>VI~v6yyyyyyyyyyyyyyyyyI"d'>vfyyyyyyyyyyyyy
yyyyyvy'V=yi'>VI~v'?yyy,|yyyyyyyyyyyyy)'II2yyyyyyyyyyyyyyyyyyvy'V=

When the output should look similar to this(this is not an exact sample, I can provide one if requested):

11100944 0002 J 3570 3833 00 1645

Any ideas on why this serial data is coming into the BS2 so garbled? Is it an error in my coding?

I am POSITIVE that the data is sent at 2400 7E1, I checked with both the dummy terminal and the PBX.

Thanks for any help,
Will

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2005-11-10 15:12
    Will,

    Check your baud parameter. I just looked at Jon Williams template and came up with 8588 + $4000. ( the $4000 puts you into inverted mode)

    Assuming the data coming in is 'real' RS-232, you need to use the Inverted form at the Stamp pin. Also, untill the data starts looking OK, capture the incoming data as a STRing instead of a number. I think you'll be seeing the ASCII number of each character in its present form.

    Tom
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-10 15:15
    Hello,

    ·· If your Baud parameters are correct (That is a possibility), then my guess is you're trying to print raw binary data to the screen.· Are you sending ASCII digits, or binary values?· If they're binary values, you will need the DEC formatter to display them properly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Tom WalkerTom Walker Posts: 509
    edited 2005-11-10 15:17
    And that old favorite....common ground?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-10 15:33
    Good point Tom...Funny too, I just mentioned that in another thread.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • WillWhiteWillWhite Posts: 15
    edited 2005-11-10 18:30
    Thanks for the responses.

    I've unfortuneatlely been caught up in another project today and won't have time to work on this before tomorrow, when I'm guessing alot of you won't be around (Happy Veterans Day), so I'll prob. have to bump this up on Monday.

    ---Common Ground: Pin 7 of the 25 pin serial cable is connected to VSS as per the SERIN instructions. This was something I forgot at first, but did remember before posting. Is this the correct way to do it?

    ---Input String instead of Individual Char: I was having trouble with this at first, hence why I switched over to inputing a single char at a time. This was BEFORE I fixed the common ground problem though, so I'll switch back to inputing a string and see if it helps.

    ---DEC in front of "number" in the debug command: I did try this, and I got numbers...however they were not the correct ones.

    ---8588 +$4000: I have tried using the inverted form, and after reading up more on it I realized that I should DEFINATELY be using this, so I'm not going to bother experimenting with 8588 anymore. Thank you.


    So what I think I should do is give it a couple more trys using some of the information presented here. For example, make sure I'm using the inverted form, try it with DEC and without DEC to make sure. Also I'll try inputing strings to see if that works for me.

    When I get a chance to give this all a try and I'll post my results here, hopefully to say "woohoo it works"....but possibly to sponge a little more knowledge. I didn't notice, but the string of Data I had posted wasn't formatted correctly. I've attached an example log file from the terminal as a text file.

    Thanks for the help again, and I hope you'll all be around tomorrow or next week when I have a chance to play with this some more.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-10 22:31
    Will,

    ·· Parallax Technical Support will be here tomorrow as usual.· Now, a few things to note...It sounds like you've made your own Serial cable.· If this is true you really should double check your connections.· 8 out of 10 people who are having trouble and have made their own cable find the problem in the cable.

    ·· Also, when you say, "Input String", how are you doing this?· You haven't posted any code so we can see what's going on.· Speaking of which, if your baud parameter is the 8588 +$4000 then this could be your problem, since this doesn't correspond to any standard baud rate parameters I have listed.· What baud rate are you trying to use?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-11-11 04:58
    Chris -

    Double check your tables under the 7-bit heading. The 24972 appears in the Help File baudmode tables. Admittedly the Help File shows it only under no parity, but that a matter for another day.

    Regards,

    Bruce Bates
  • WillWhiteWillWhite Posts: 15
    edited 2005-11-11 17:48
    Chris - I was writing the 8588 + $4000 as a response to stamptrol, I didn't want to change around the numbers to confuse things. $4000 = 16384 DEC, so 396 +8192 +16384 =24972 per the help file (and Bruce above). Sorry for any confusion there....Figures I wrote it that way to AVOID the confusion. smile.gif

    I did not make my own serial cable. I'm using a standard cable from the PBX manufacturer which outputs on a 25 pin connection. I then use a gender changer and connect it to the breakout box, which is admitedly old but works like a charm. The breakout box has connection points similar to a breadboard which grip the wire. I am wiring from the RX point and the Ground point (Pin 3 and 7, i don't have it right in front of me, but I'm positive the RX pin is correct, the breakout box shows me activity on the line when data is transmitted. I will eventually be making my own cable, and will be sure to keep the cable in mind as a top reason for a possible fault at that time.

    Here is a copy of the code I am having this error with. This is by no means my final code, not even close, this is simply written so I can make sure I can capture the data correctly. The errored characters I was referring to in my original message came from this code:


    VAR number Byte
    INPUT 4
    DO
    SERIN 4,8588,[noparse][[/noparse]number]
    DEBUG number
    LOOP WHILE 1 = 1

    It is very simple, but I figured simple was better to start with so I didn't have to worry about coding errors. The Input String I was speaking of was in response to Stamptrol's suggestion that I attempt to use a STR type of data into an array instead of doing a single character at a time. I wasn't going to post my current "planned" code for the next step (after I get the stamp accepting the serial data the way I want) but this is the way I plan to implement it. Please note, it may be incomplete and is NOT the code I'm currently using to get the error. I haven't had a chance to try anything since my original posting due to other pressing duties at work, but here's the plan -- Please note, the following code is NOT complete and is not even in testing yet, I'm simply providing it to give you a roadmap of where I'm going: (EDIT - Please see attachment for better formatting)

    test VAR Byte 'DEBUG Counter Variable
    array VAR Byte(9) 'Array to hold incoming and outgoing numbers

    Is_Ring:

    'THIS SUB WILL BE USED TO START Phone_Number WHEN THE DAA SIGNALS A RING TO THE BS2
    'GOSUB Phone_Number 'ACTIVE WHEN DAA IS ONLINE


    Phone_Number:
    SERIN 4,24972,[noparse][[/noparse]SKIP 53] 'Skip the first 53 characters of the input
    SERIN 4,24972,[noparse][[/noparse]STR array \9] 'Store the next 9 character in the array
    ' FOR test = 0 TO 8 'TESTING PURPOSES ONLY - TO SHOW NUMBER THAT WAS READ
    ' DEBUG array(test)
    NEXT

    'THE FOLLOWING IS TEMP UNTILL THE DAA IS CONNECTED TO SIGNAL A RING
    '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    IF array(0) = 51 THEN
    IF array(1) = 52 THEN
    IF array(2) = 52 THEN
    IF array(3) = 48 THEN

    'SITE OF FUTURE CODE TO INSTRUCT QUADRAVOX TO READ BACK NUMBER - WILL NOT BE TEMP -+-+

    ENDIF
    ENDIF
    ENDIF
    ENDIF

    '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


    New_Num: 'WAITS FOR LINE FEED WHICH SIGNALS THE END OF THIS RECORD

    DO
    SERIN 4,24972,[noparse][[/noparse]test]
    'DEBUG test
    LOOP WHILE $test <> 0A
    'GOSUB Is_Ring 'ACTIVE ONCE DAA IS ONLINE
    GOSUB Phone_Number 'REMOVED WHEN DAA IS ONLINE

    END





    The code is also attached to this as a text file if you want to see it with a little better formatting.

    Post Edited (WillWhite) : 11/11/2005 5:52:19 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-11 19:17
    Bruce Bates said...(trimmed)
    Double check your tables under the 7-bit heading. The 24972 appears in the Help File baudmode tables. Admittedly the Help File shows it only under no parity, but that a matter for another day.
    Bruce,

    ·· I have the table...But the more standard/common parameters are for 8-bit.· I guess I should've worded it differently, as that is a common mistake to make.· Many people know the baud rate, but don't understand the other parameters, such as start/stop bits, parity, even/odd, etc.··So whenever someone uses 7-bit or anything unusual I always throw that out there as a possibility.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-11 19:46
    Will,

    ·· I understand, and wasn't referring to mixed number bases.· I just wasn't sure if you were sure of the baud parameters.· As for the cable, well it may be a standard cable, but if you're using a breakout box on the other end, then connections can be miswired just the same.· Again, it was a possibility I was throwing out there to consider.· If you're sure of these things then we'll move on.··In the small section of code you posted, you used 8588 for the baud rate, yet in the larger sections below, you are using 24972.· Which one is correct, and what are the baud parameters of the device sending this data to the BASIC Stamp?· In fact, what is the data coming from, and is it TTL level or RS-232 level data?


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 11/11/2005 8:11:31 PM GMT
  • WillWhiteWillWhite Posts: 15
    edited 2005-11-11 22:04
    Chris - I'm positive of the baud parameters, I checked the internal settings on the PBX, and visually verified on the terminal (I actually changed the terminal to 8N1 and got garbage on the screen, so I switched it back to 7E1 and it was golden again).

    The breakout box has a key to pin functions located inside the cover. I'm positive of the RX pin as this is the activity light which flashes when data is sent to the terminal (there is no reverse data sent, the PBX can not accept data over this connection). I checked the ground on the box and it indicates that it is pin #7, however I will investigate with a digital multimeter next week.

    The 8588 is the settings I used in the sample output I put in my original message. I did try using 24972 and had similar results, however have since come to learn that 24972 is the correct setting for a standard RS-232 cable so I believe I will find this to be the correct setting, thus the reason my future code was changed. I kept the 8588 in the code snippit I put up because I didn't want to make it seem like that output came from 24972. I haven't had time to work on it again since yesterday morning, I'm hoping to dedicate Monday afternoon to working on the BS2.

    The data is TTL (I will verify this, I am only 90% positive). It is coming out of an Erricsson MD110 PBX working on BC9.

    The specifics of this project are:

    The BS2 is listening in on the incoming call log in order to see when a specific phone number is called, this phone number will be answered by the DAA which will EVENTUALLY be connected to the BS2. On Ring, the BS2 will instruct the DAA to answer, then it will pause for 1 second, then instruct the DAA to hang up the line. At this point it will begin listening on the call log serial port for the information the PBX sends across about the call. This information will contain the phone number which called the BS2. The BS2 will then use this information to return the phone call, and using the QV306 will read back the phone number. I want to implement this for two reasons, one is for my technicians so they can identify the phone numbers in different dorm rooms, as well as verify their location in the various IDF and MDF's throughout our campus. The second is so that students will be able to call in and obtain their own phone number as we are NOT allowed to give out this information, however an automated dial-back system is ok.

    But, this project is currently on the shelf (If all goes well on Monday morning, then it will be back on my desk on Monday afternoon), I'm just fishing for ideas to help me figure out what could be going wrong. Hopefully I'll be able to try out some of your ideas on Monday....I'll let you know what happens. smile.gif
  • WillWhiteWillWhite Posts: 15
    edited 2006-02-09 15:12
    Hey, I'm back after a long time of not being able to work on this since more pressing issues came up.

    Anyhow, the time off did some good for me, I was able to finish up the project in a day.

    What I found was that for some reason the stamp refused to read the input from the serial out on one of the call logging outputs (the one I speak of in the above posts). So I redesiged the software portion of the project, and hooked it to the serial input on the voicemail system. This transfers at a faster rate (9600 instead of 2400) so it's a little tougher to make sure I scan all the data with the stamp.

    Anyhow, I now do the following:
    1) Call goes to a specific number(#A)
    2) #A is forwarded to voicemail.
    3) Voicemail recieves the call and the data about the call (Calling number, called number, input port) is passed over an RS232 link. The stamp listens in on this link and looks to see when #A is called.
    3a) Voicemail forwards the call automatically to another number (#B) that the stamp is connected to.
    AND at the same time:
    3b) The stamp project goes into a finite loop (in case of error or hangup) waiting for the phone to ring.
    4) When the phone rings, the stamp answers and reads back the information from the serial port....so the phone number that placed the call to #A is read back, and then hung up on.

    So....Pros and Cons of this method:

    Pros:
    1) Off-campus calls can not access the stamp as only internal information is passed over the serial link. Without the "trigger" condition required to tell the stamp to listen to the Ring Indicator on the DAA outside calls won't get connected.
    2) Information can be read back during the call....my other method would have required a call-back from the stamp since the log isn't entered untill the call is ended.
    3) Since the VM system gets to look at the call before it goes to the stamp, I can eventually use this number to route calls to different locations using a menu.
    4) Scalability - I can expand on this project, make it look for more numbers, add temperature and humidity sensors for the switch room, and make an automated menu by adding a DTMF module.

    Cons:
    1) Time. The amount of time it takes for the call to connect thru the VM system, be transferred back out, ring (the VM system must detect a ring or it won't release the call..I have to allow 1 ring), answer, and read back the numbers (the Quadravox module is a little slower then I'd like) is a bit more then the technicians would like to wait. This, of course, is only about 10 seconds, but they're impatient. smile.gif
    2) Non-portable. Since each voicemail system accepts data in a different way, I may have to reprogram the stamp when we upgrade the VM system or the PBX....the software in the PBX will be upgraded in June, so I'll get a sample of it then.
    3)Not all calls are caught - Occasionally, if alot of data is being passed over the serial link, the stamp misses a call to the Number ID line. I can't change the baud rate the PBX communicates to the VM system, however I could upgrade the stamp so that it could run more instructions per second. Definately not a game breaker.


    So anyhow, if anyone would like to see a schematic of the circuit (I'm not engineer, so it's simply a cad drawing I could print as a PDF) or the code I'm using, let me know and I'll post it here.

    Thanks for all the help guys, now I just have to sodder everything together on a carrier board or other thru-hole board so that I can convince them to buy me more parts and I'll have a professional development board to play with. smile.gif
Sign In or Register to comment.