basic stamp with RS-232 link
Robban
Posts: 124
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
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
Comments
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."
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
SEROUT 15,84,[noparse][[/noparse]"0100",13]
Jeff T.
·· 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
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 Savage
Parallax Tech Support
no,i do not have the capasitors connected...
i have the pins from the max directly connected to the pins on the stamp.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
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)
·
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 -->
When i hook upp the elm againt a terminal program i use 9600 and this works very good.
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
i am using the elm327
2. A "terminal Program" is something like Hyperterm, SmartTerm, PuTTY, etc. Which one are you using?
but if you look at link 2 in the first message, shouldn´t those be enough or do i have to put addational 4?
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.
' {$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..
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.
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
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....
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
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..
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.
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?
·
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.
i did tied it as you said....
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.
so hardware communication is working...
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