Shop OBEX P1 Docs P2 Docs Learn Events
basic stamp with RS-232 link — Parallax Forums

basic stamp with RS-232 link

RobbanRobban Posts: 124
edited 2007-03-07 20:27 in BASIC Stamp
hi!
trying to connect· a elm327 (see link 1) to my basic stamp 2 and found out that i would need a max323 rs-link (see link 2) so i bought myself a MAX323 and hooked it up like...

Max in--->Pin 14
Max Out-->Pin15
Max 5v--->vdd
Max gnd-->Vss

and wrote this program

rpm var word
·start:
· SEROUT 15,84,[noparse][[/noparse]"01O0"]
· SERIN 14,84,[noparse][[/noparse]rpm]
··debug·hex rpm
··pause 200
GOTO start

when i hook up the computer· directly to the elm327 and send the "0100" i get back
41 BE 1F B8 10

just as i should...
but when i tried it with my BS2 nothing happends..


link 1
http://www.elmelectronics.com/DSheets/ELM327DS.pdf

link 2
http://www.embedinc.com/products/ser/index.htm

Any ideas?

Regards
Robert
«1

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2007-02-07 18:31
    The MAX323 is the wrong IC to use.
    It's the MAX232 you should use.

    I still have to install the PBasic program on this laptop (just got it replaced).
    OK, just installed it.
    The "84" in your serin/serout lines refers to the serial data going out in TRUE format. Meaning a logic 1 is a +5V level....basically TTL levels.
    RS232 doesn't work that way. A Logic 1 in RS232 is actually a negative voltage (~-5/-8/-12volts depending). and alogic 0 would be the positive of those values.
    The stamps don't produce a negative voltage, but instead just drop the level to 0volts at the output which is usually good enough for most devices.

    So, if you are connecting your BS2 to the MAX232 RS232 in pin, you have to set your serout baudmodes to 16468 -- inverted mode.(this is all in the pbasic helpfile).

    To be honest, you should be able to get away without using a MAX232 as you can set the BS2 to use the inverted mode and connect it straight to your ELM. NOTE though, that you need a series current limiting resistor on your serin line to avoid damaging that pin (this too is in the help file).

    Hope that straightens some things out.

    cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve

    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • RobbanRobban Posts: 124
    edited 2007-02-07 18:39
    i have tried this with 16468 but with no luck....is my program correct?
    can i use that 16468 in any pin on the stamp?

    tried also to hook up a display to my pin 0 and replaced the debug line with "serout 0,84,[noparse][[/noparse]hex rpm]" but also this was of no luck
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-02-07 19:38
    Hi Robban, scanning the datasheet real quick I see that the elm327 expects a carriage return at the end of sent data, it may not be the cause of your communication problem but you might try it and see if the response differs. Even without the <CR> it should return "?" after a 20 sec timeout

    SEROUT 15,84,[noparse][[/noparse]"0100",13]

    Jeff T.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-07 21:04
    steve_b said...(trimmed)
    The "84" in your serin/serout lines refers to the serial data going out in TRUE format. Meaning a logic 1 is a +5V level....basically TTL levels.
    RS232 doesn't work that way. A Logic 1 in RS232 is actually a negative voltage (~-5/-8/-12volts depending). and alogic 0 would be the positive of those values.
    The stamps don't produce a negative voltage, but instead just drop the level to 0volts at the output which is usually good enough for most devices.
    So, if you are connecting your BS2 to the MAX232 RS232 in pin, you have to set your serout baudmodes to 16468 -- inverted mode.(this is all in the pbasic helpfile).
    To be honest, you should be able to get away without using a MAX232 as you can set the BS2 to use the inverted mode and connect it straight to your ELM. NOTE though, that you need a series current limiting resistor on your serin line to avoid damaging that pin (this too is in the help file).
    Steve,

    ·· Actually if you're using a MAX232 you'd want to use TRUE baud mode since the driver itself inverts the signal for you (it is basically an inverter).· So the 84 would be correct in this case.· Also, as for the direct connection...For some devices this does in fact work and we mention it in our manual.· It usually works when connecting to a PC.· Some devices/peripherals on the other hand expect RS-232 signals and do not work well without them.· In these cases you pretty much need a line driver.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • RobbanRobban Posts: 124
    edited 2007-02-07 21:17
    Chris!

    from what i have been wiriting...what are your conclutions? what do i do wrong?
    i cant get the display to show anything....therefore i am not sure if the stamp gets the input from the elm327
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-07 21:34
    That is hard to say without more information. As Steve said, it sounds like you have the wrong chip unless that was a typo above. Assuming you do have the right chip do you have the 4 required .1uF capacitors connected?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • RobbanRobban Posts: 124
    edited 2007-02-07 21:41
    i wrote the wrong max......i have the max232...the fingers slipped smile.gif

    no,i do not have the capasitors connected...
    i have the pins from the max directly connected to the pins on the stamp.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-07 22:13
    Well the MAX232 requires the capacitors for the charge pumps. Without them it won’t work. Please see the datasheet for more information.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • RobbanRobban Posts: 124
    edited 2007-02-08 07:22
    the strange thing is that when i hook up the max and stamp against my pc and connect the cable to the max and write a program that get the input (serin) from my pc and then serout the to lcd i can write on the keyboard and directly i see it on the display...

    like

    serout 0,84,[noparse][[/noparse]"Hello world"]·· 'send hello world to the terminalprogram (pbasics)
    start:
    serin 1,84,[noparse][[/noparse]keys]·············· ' get the inputs from the keyboard
    serout 15,84,[noparse][[/noparse]keys]·········· ' send the inputs to the display
    goto start


    but when i replace "hello world" with 0100 and connect it to the elm the display is blank...

    isn´t the caapasitors included on the Rs-232 link (see link in 1:st message)
    ·
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-08 07:44
    Robban -

    What is the proper BAUD RATE for the "ELM Unit", according to their specifications?

    Is more than one BAUD RATE available, and if so, do you have the "ELM Unit" strapped or jumpered to provide the BAUD RATE you are expecting?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • RobbanRobban Posts: 124
    edited 2007-02-08 08:42
    Read the sheet and from what i understand i should use the 9600 baudrate...but according to the sheet it can be set to 38400 also.

    When i hook upp the elm againt a terminal program i use 9600 and this works very good.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-08 09:04
    Robban -

    Could you qualify "terminal program" a bit as there are many, many of them out there?

    Additionally, which ELM Unit are you using?

    Bruce

    Post Edited (Bruce Bates) : 2/8/2007 9:08:59 AM GMT
  • RobbanRobban Posts: 124
    edited 2007-02-08 10:11
    What do you mean with qulaify?

    i am using the elm327
  • RobbanRobban Posts: 124
    edited 2007-02-08 12:50
    i am using hyperterminal or the Pbasic 2.5 debug window
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-08 13:53
    1. The Max232 needs 4 capacitors to do its "Level Shifting" work (from TTL to RS-232 +- 10 volts). If you haven't put them in, then the MAX232 isn't going to work.

    2. A "terminal Program" is something like Hyperterm, SmartTerm, PuTTY, etc. Which one are you using?
  • RobbanRobban Posts: 124
    edited 2007-02-08 14:53
    i am using hyperterm or the pbasic:s terminalwindow...
    but if you look at link 2 in the first message, shouldn´t those be enough or do i have to put addational 4?
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-08 15:12
    Ok, good, that board should work fine. And it DOES have 4 capacitors already installed, so that's OK.

    Now, the other big difference between the PC and the BOE is that for a PC to talk to a BOE it uses pin 2 to 2, 3 to 3, pin 5 as ground. What they call a "straight through" cable.

    BUT, when you connect the BOE directly to the ELM327 you need to connect pin 2 to 3, pin 3 to 2, and pin 5 straight through -- what they call a "null modem" cable.

    It sounds like that is your problem.
  • RobbanRobban Posts: 124
    edited 2007-02-08 18:01
    allan, i used my nullmodem cable between the elm and my stamp and wrote this

    ' {$STAMP BS2}
    key VAR Byte
    'SEROUT 16,84,[noparse][[/noparse]"0100",13]
    SERIN 16,84,[noparse][[/noparse]key]
    SEROUT 2,84,[noparse][[/noparse]HEX4 key] ---display the incoming hex on my display

    but still i cant make it work...
    i should be recieving something like
    41 00 BE 1F B8 10

    but all i get was a bpunch of zeros and one or two ff och 3f..
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2007-02-08 18:38
    It seems you are getting a response now at least, maybe you could get a little more information if you adjusted your formatting a little. You could try and gather a little more from the elm by accepting a string of bytes,

    key var byte(8)
    SERIN 16,84,[noparse][[/noparse]STR key\8\10]
    DEBUG STR key

    and maybe adjusting the out string to see what effect that has

    SEROUT 16,84,[noparse][[/noparse]"01",13,"00"]

    Jeff T.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-08 18:38
    For your 'baudmode' (that 84 up there) try 16468. That's the "inverted" baud mode -- the logic of when to 'invert' or not is very unclear, I usually just try stuff until it works.

    Note the SERIN "HEX" modifier takes IN a string that SHOULD be a 'hex' number, and converts it to a SINGLE 'word' value (32 bits). It looks like your SERIN recieves a single byte, then tries to print it as a 4-byte hex string.

    To debug what's going on, you probably want something like:

    KeyStr VAR BYTE(6)

    SERIN 16, 84, [noparse][[/noparse]STR KeyStr\4] ' Get 4 bytes
    SEROUT 2, 84, [noparse][[/noparse]STR KeyStr\4] ' Send 4 bytes.

    Note on "port 16", everything recieved is echo'ed back out to the sending device -- this might confuse the Elm327. I assumed you were using your MAX232 to talk to the 'Elm'.

    Anyway, send and recieve as STR, then you can put in the hex modifiers as so:

    KeyVal VAR WORD
    SERIN 16, 84, [noparse][[/noparse]HEX KeyVal] ' Recieve hexadecimal string, and put into KeyVal word
    SEROUT 2, 84, [noparse][[/noparse]HEX KeyVal, 13] ' Convert KeyVal back into hexadecimal string
  • RobbanRobban Posts: 124
    edited 2007-02-08 18:44
    tried the replace the 84 with 16468 but no change....no i did not use my max232...i connected the stamp directly with a nullmodem cable to the elm...

    cause when i connect it with my max232 nothing happend with the leds on the elminterface...

    but when i connect it to the dsub on the BOE and start the program there are 2 leds that start light up a while....
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-08 18:52
    Gosh, where to begin...

    The first thing you must do is "debug your interfaces". Currently, you don't know (because nothing is working) if your wiring to the Elm is correct, or your baudmode setting to the Elm is correct. The "STR" versions of code above are to help you find out what is wrong and correct it.

    Second -- you MUST NOT use the built-in DB-9 of the BOE to talk with the Elm. That connector assumes there's a "real" RS-232 device (like your PC) on the other end. And everything that port recieves is echoed, by the hardware, back to that device. For SURE this is going to confuse the Elm.

    So, were I you, I would use the PC as a debug terminal, hang the Elm off the other port (port 2) with or without the MAX232 does not matter. If your PC talks directly to the Elm, then probably you MUST use the Max232 to get it to work, but you can find that out by trying it.

    The key to successful software is to validate the low level interfaces (perhaps with a VERY simple program). Then build on stuff you KNOW works to get the next level of functionality.

    Otherwise, there's WAY too many things that can be going wrong to be able to make any progress.

    Oh, and only the pseudo "port 16" can be used for both input and output.· To talk to the Elm, you'll need a TX pin, and an RX pin.· Currently pin 2 looks like an 'output' pin.

    Also, the Elm probably wants a CR character to know when a transmission is finished.· The PC gives it that automatically.· So, for the BS2:

    SEROUT 14, 84, [noparse][[/noparse]"0100", 13]· ' Assuming the Elm is recieving from the BS2's pin 14.

    And note you MUST run Vss to the Ground pin of the DB-9 connector (Ground) to the Elm for the Elm to properly get the data.


    Post Edited (allanlane5) : 2/8/2007 6:59:16 PM GMT
  • RobbanRobban Posts: 124
    edited 2007-02-08 18:59
    i have connected my max232 to the pin0 and pin 1 and tried to write a very small program (like above) so now i come to another question...is the pins0-15 indepenetly in and out?

    i have hooked up the elm directly to my elm via the com1 and it works just as i should with hyperterminal....
    when i wrote 0100 then i got the hexa numbers i menshend earlier..
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-08 19:04
    The direction (input vs. output) is set by the DIR register (look in the PBasic Manual for a discussion) which is a 16 bit register. A one in a bit position sets the corresponding pin to input mode. A zero in that bit position sets the pin to output mode. Many of the statements that include a pin number will implicitly set the I/O direction and the INPUT and OUTPUT statements will set the direction for the single pin specified. If you display the value in DIR using DEBUG and execute INPUT and OUTPUT statements, you will see how DIR changes.
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-02-08 19:05
    I don't know what "i have hooked up THE elm directly to MY elm via the com1" means. I assume it means you've connected the Elm directly to your PC's COM1 serial port. And apparently that works. This is good, this means that the Elm RX/TX and ground are working properly. You've validated the Elm chip.

    Yes, pins 0..15 are independently in and out. Meaning, if you tie pin0 to the Elm RX, and pin 1 to the Elm TX, and Vss to the Elm Ground, then you should be able to send:

    HexStr VAR BYTE(5)
    I VAR BYTE

    MAIN:
    SEROUT 0, 84 [noparse][[/noparse]"0100",13]
    SERIN 1, 84, [noparse][[/noparse]STR HexStr\4]
    FOR I = 0 to 3
    SEROUT 16, 16864, [noparse][[/noparse]HEX HexStr(I)] ' Assumes PC is connected
    NEXT
    SEROUT 16, 16864, [noparse][[/noparse]13]

    PAUSE 1000 ' Wait 1 second so we don't get 'flooded'
    GOTO MAIN

    And the above should work.
  • RobbanRobban Posts: 124
    edited 2007-03-02 17:42
    hi Allan!

    Tried to hook up the BS2 and the Elm as you wrote o wrote the program.
    But nothing happends..

    I made a 9 pin dsub with pin 2 on the dsub to the pin 0 on the BS2
    and pin 3 to the pin 0 on the bs2
    and pin 5 to vss

    can´t understand what is wrong..

    I also tried to use my max232 on the same pins but still nothing.


    One more thing.
    When i connect the elm directley to the laptop and use a terminalprogram (Hyperterminal / pbasic:s terminal window and write 0100 the leds on the elm starts to light up for every key i press...
    like

    0 - flash
    1 - flash
    0 - flash
    0 - flash

    and i get the answer i should....

    any clues/ideas?




    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-03-02 18:42
    If you've tied DB-9 pin 2 to pin 0 on the BS2, AND tied DB-9 pin 3 to pin 0 on the BS2, then you've shorted TX to RX, and I'm not surprised it doesn't work.

    Tie DB-9 pin 2 to P0 on the BS2, and DB-9 pin 3 to P1 on the BS2. On the good side, that DB-9 pin 5 to Vss is correct.
  • RobbanRobban Posts: 124
    edited 2007-03-02 18:45
    oh...sorry if i got it wrong when i wrote....

    i did tied it as you said....
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-03-02 18:52
    If it works in Hyperterminal then you probably need a properly installed Max232 chip.

    You've got the stuff in front of you. If you can't figure it out, there's limits on what I can do to help you. I think I've reached those limits.
  • RobbanRobban Posts: 124
    edited 2007-03-03 15:56
    allright....now i got the hexa decimal as i should on the display...it was the "84" that should be replaced by 16468 instead.
    so hardware communication is working...smile.gif

    nw to another gueastion
    my answer from the elm is 41 0C 1A F8
    and from what i have inderstood it is only the 1AF8 that is the data...

    Question is...is there a command in Pbasic to "mask" out the 1AF8 or do i have to make a small program for this?
    if so....anyone has any examples?

    regards
    Robban
Sign In or Register to comment.