View Full Version : Why this code does not work???
I am trying to display output from a serial device - which sends out 2 bytes of data.The device works well and when the out put is captured using BS2sx works ok.
When I use the propeller - "PropRPM" the attached code only displays "Display O2 sat data in ASCII" text only.
NO serial data is displayed at all.
Please can someone show me why?
04-30-2008, 02:48 AM
code looks ok as far as I can tell (but I don't really use BS2 functions)....
You might try changing:
RxData1 := BS2.SERIN_DEC(RX_Pin,Baud,1, 8)
RxData1 := BS2.SERIN_DEC(RX_Pin,Baud,0, 8)
just in case you signal is inverted somewhere...
also, for troubleshooting, maybe try
RxData1 := 5
and be sure it shows "5" on the monitor.
You might consider using "fullduplexserial" instead of BS2 functions if you still have problems. It's also pretty easy to use.
·I tried using "·RxData1 =5" ,"Rxdata2=10" and I can display the numbers on the screen.
I also used "FullDuPlexSerial",:ExtDuplexSerial","Simple Serial" - objects. with all of them do·NOT seem to receive any serial data.
I am using the"PropRPM" with the built in serial interface using the "MX2232" chip.
The Basic Stamp set-up I am using the serial data is sent directly from the serial device to the BS2px ·pin using "SERIN command".
Does this have antthing to do with this problem.
Can I use a 10K resistor and directly feed the serial out put from the serial device to the "Prop Pin-31" as I only require the serial out-put from the serial device.
Thanks for the quick reply.
P.S - serial device still works well with BS2 set-up.
04-30-2008, 04:07 AM
You should describe your connections in much more detail (like with a schematic). If you connected the MAX3232 chip to a BS2px pin without a series resistor as described in the BASIC Stamp Manual, you may have destroyed the I/O pin. Theoretically, you could connect the serial output through a 10K resistor to a Propeller I/O pin and the resistor should protect the I/O pin, but it may not work well depending on the speed, voltage range, etc. I don't recommend it. Use the transistor circuit shown in the Propeller manual or a 3.3v logic to RS232 converter chip like the MAX3232.
04-30-2008, 04:27 AM
Ok, I think I see your problem... The MAX3232 is there to convert PC level RS232 signals (+/- 10V) down to TTL levels. But, is sounds like your serial device is already at TTL levels. So, you want to connect this directly to a prop pin. But, maybe you should use a 1k or so series resistor just for safety. I think your proprpm thing has plenty of spare pins, so you might want to use a different one, besides 31,30.
I am connecting the DB9 connection from the serial device to the DB9 in the "PropRPM".
I have nothing else connected.
Rayman - I will try your solution.Is there a way to·check the out-put with a Digital voltmeter to
see whether it is TTL or not.
04-30-2008, 07:04 AM
Measure the voltage at the output. If the resting or idle voltage is +5V, it's probably TTL.
04-30-2008, 07:23 AM
Also, I think if you had it going straight to a BS2 pin before, it must be TTL...
Thank you very,very much for such prompt replies.You all are agreat help for week-end amature electronic hackers like me who has no formal training.
I will try what both of suggested and will post back with the results.
The voltage between pin-2(Rx) and pin-5(gnd) of the DB-9 is 8.7V. coming from the serial device.
I measured again - the measurements are very confusing anyway here they are :
····· 1.DB-9 pin2(Tx)· and pin 5-Gnd --->8.7V ----> This is Tx coming out of BS2 pin
····· 2DB-9 pin3 (Rx) and pin5(Gng) --->0.001V ---> this is the Rx going to the BS2 pin
I measured them after removing the BS2px chip - measured at the DIP socket
I am very confused now.
04-30-2008, 11:24 AM
Oops, I see now that the BS2px has a built-in level shifter for serial data. So, it sounds like you do need the MAX3232. Connecting your serial data line directly to a Prop pin would not be a good idea!
So, I guess I don't know why your original code didn't work...
Post Edited (Rayman) : 4/30/2008 3:39:34 AM GMT
I connected the serial out-put straight to the computer and then tried to capture the data via the Hyperterminal and I get all garbage and NO decimal out-put.The connection parameters are correct - "9600,8,N,1 " as stated in the instructions with the serial device.
When I fired up the software that came with it - I get decimal out-put as it is supposed to - which I also get from my BS2px st-up.
Then I used RS232 port analyzer software - which also worked well and diaplayed the decimal out-put correctly.
As far as I can see the hardware is connected OK.Only the·?" PropRPM" and ? Hyperterminal has issues.
I hope one of you can solve this.
05-01-2008, 01:57 AM
I think you're going to have to post some more information about the device/protocol.· Maybe you can post some of the BS2sx code that is working...
It may be that the decimal output you're looking for would look like junk on the Hyperterminal screen.· But, at least you get some output from your device with Hyperterminal.· You should get something with your setup too...
Maybe there's something strange about the PropRPM platform...· I'm not too familiar with that...
·Thanks for helping me.
Please find the attached specs for the serial device.
05-01-2008, 03:27 AM
Ok, that describes TTL-like serial siganl coming out of a pin. How is this connected to the DB9 connector? Is it a direct connection? Or, is there an IC chip there to boost to PC-RS232 levels?
It is attaced to the DB9 via - chpi # LTC1382CSW.
I have attached the data sheet for you.
Thanks for all this.
05-01-2008, 09:37 AM
Everything looks OK then. So, you have me stumped as to why it's not working... This is the point where I'd break out an oscilloscope to track down the issue...
I just received the "Parallax USB Scope" and was just reading the intro., so you can see I am very,very
fresh at this.
If you can just point me what I should do with the scope I will be glad to follow your instructions.This will not only solve the problem but will also be a very good lesson in oscilloscope usage.
05-01-2008, 11:39 PM
Well, I would just look at pins 2 & 3 of the DB9 connector you are connecting to the PropRPM.· One of them should show serial data coming in...· Should look something like this:
-------+ +-+ +-+ +---------
| | | | | |
| | | | | |
| | | | | |
+---+ +-+ +---+
I guess you should get 3 bytes like this every second...
I think the high level should be 10V and the low level might be 0 or -10V...
Then, hook it up to your PropRPM and look at pin31.· You should see the same type of signal with a high voltage of about 3.3V and a low voltage of 0V...
05-01-2008, 11:50 PM
One thing I'd look for is the serial data coming in on the wrong pin...
It needs to be on pin3 of the DB9 connector, but maybe it's on pin2 for some reason... If so, need a null-modem like adapter to swap pins 2&3...
Measring the out-put from the serial device furhte confused me - may be I was doing it incorrect - with the scope.I seem to get a better signal on P2 rather than P3 - of the DB9 coming out of the serial device.
Then I double checked the connections to BS2 set-up.I have P3 connected and not P2 from the DB9.
Thank you very very much for all the help you have given me.
I will get bak with you when I acquire little experience with the scope so I know what I am doing with it.
If you would like I willget back with you sometime.
I am planing to connect the serial output directly to the propeller to see if it si gong to work - sine it works with the BS2.
To do so what would be the best way - I know I might damage the prop - that is a chance I am willing to take.
I found this circuit in the forum -" Serial to Propeller Connection Schematic" - may be I will try connecting the serial device as per this doc.
05-02-2008, 08:47 AM
That circuit should work. You just need the transistor on the left. Note that the circuit inverts the polarity of the signal, but I think the BS2 functions and fullduplexserial expect this, or at least have a option to correct for it.
You might try connecting directly with a 10k resistor. But again, you may have to account for the polarity of the signal.
05-02-2008, 10:16 AM
If you already have been able to talk to the device thru rs232 using the provided software and also to the BS2 thru your program it seems just a matter of getting the level conversion correct and making sure the max232 clone(LTC1382) is working correctly. The LTC1382 has a pin(pin 18) that must be pulled high for it to not be tri-stated.
A simple test that can be done with rs232 is the loopback hookup. Say you want to have hyperterminal receive characters that you type on the keyboard as input .This can be done by connecting the TX to the RX pin which just loops the data back into hyperterminal.
So let's say you want to test your max232 clone circuit . There are two rs232 circuits so you can form a type of loopback test. One rs232 circuit(maybe pins 8and 9) goes to your computer running the software that works and the other rs232 circuit(pins 14 and 15) goes to your device(blood monitor) that your are trying to interface to.
The logic side of the max232clone would have pins 10 and 12 hooked together and pins 11 and 13 would be tied together to form a loopback circuit . This is from the datasheet that you provided.
If the max232 clone is working correctly then you should see the data , if not then your hookup of the chip should be examined closely.
············ I am still unable to capture the serial out-put from the device to the propeller.I tries the transistor circuit using only the the left transistor.I still have to try connecting directly via 10K resistor.In the mean time I have been playing with the scope.
Attached is a picture of the scope wave form and readings.
Thw wave form does not look like the ones in the book· or the one you depicted.
The out put from the device is at 9600,8N1
I can see the out-put at 1.0Htz - frquency.What does all this add upto.
Hoprfully this will give you more info to resolve this issue.
05-05-2008, 01:34 AM
you're just looking at 60hz noise there... Maybe you didn't hook up the ground connection to the scope input correctly... Also set your trigger threshold (I'm assuming that thing has a trigger) so that you don't trigger off noise, but only the signal you're looking for.
Since your questions are about all Parallax sold products, you might try calling or emailing their support line... Might get there faster that way...
The serial devise I have is fairly expensive and opening it will void my warrenty and peeping from the openings - the components
seem to be SMD's so I really would not wan't to monkey with it.
Rayman - I will call parallax to-morrow to seek some advise.
Thanks for both of you to taking time to help
05-05-2008, 11:51 AM
I thought you had made your own interface using the max 232 clone chip and not a manufactured one. Having looked at the Proprpm it already has the max 2323e chip used for·programming the prop. If you can download programs to the Proprpm then you already have your rs232 comm's working.All you really need is to work out your protocol with your device. To test out the rs232 there are several objects that allow you to send from the prop to the PC and vice versa ·thru the rs232. I like Brays terminal as· program which is a free download.
I can send data from the PC to the PropRPM - I can download the spin code from the PC to the PropRPM.
I can also also see the data out-put from the serial device when connected to the PC - using either using the software that came with the Serial device and also when using a serial port analyser software but not with the Hyperterminal and ·when I connect the derial device to the PropRPM via the serial port - the prop does not see the data.
The spin program seem to working well otherwise except is unable to recive the data - all I can see is "000" and displays other " text" without any problems.NO decimal serial data that show up in the PC when connected directly to the serial device.
I will download the program you suggested and see what happens.
05-06-2008, 02:50 AM
I looked at it some more and I think I see your problem!
You shouldn't be using the SERIN_DEC function from BS2_functions because that expects ASCII text ending in a <CR> character...
But, your device is just sending 3 bytes of raw data (I think).
So, just replace SERIN_DEC with SERIN_CHAR.
The TV.dec function you already have with then display this byte as a number...
I got help from Parallax touse the scope and I think I got the answer you were seeking.
Ihave attached the scope picture of the serial out-put from the serial device.I scoped all the 9 pins coming out of the serial device - what is attached is the out-put from Pin 2.Your hunch was afterall right- I still wonder why when the pin 3 is connected to BS2 and it works.
As you can see the output Voltages are high and my guess is I will require the transistor circuit - like you advised with only the left transistor to feed the input to the PropRpm.I am planning to use different pin as I have some to spare and keep the built -in serial connection to connect to the PC.
Please advise if my descion is -OK if not direct me in the right direction.
Thanks once again for all the help.
05-06-2008, 05:42 AM
Read my last post! I think your real problem is with your code...
I will change the code as you suggested and will get back.
05-06-2008, 08:50 AM
If the PC(DTE) can talk to your device(DCE) and the PC(DTE) can talk to the PropRPM(DCE)· but the PropRPM(DCE) cannot talk to the device(DCE) then I would think you need what is called a null modem cable. Sounds like you have a 'straight trough' cable (pin 2 to pin 2 and pin 3 to pin 3) . A null modem cable would have pin2 going to pin3 and vice versa.
·You are absolutely right - I made a new cable switching the pins ·2 & 3 and now I am receiving data - but the new problem is they are not same decimal numbers they are suppose to be.
I tried inverting the signal - still I get data but they are not right.
What is this new problem - ? code.
05-07-2008, 02:02 AM
If you can receive the data correctly with the software provided for the device and by the rs232 analyzing software but NOT by hyperterminal correctly then I would guess that the way the data is presented to hyperterminal is the way your program is trying to read it also. Have a look at what is actually being received by the analyzing software.
After I switched the P2&P3· and changed the code of the BS2 calls to "serin_char" as you suggested.
Now it shows incorrect decimal values.
I was using a trial version - "serial port analyser"- and the function I need is blocked.So when I get a
fully working software version,I will get back to you.
Thanks for the help.
05-07-2008, 07:55 AM
Here is a link to that terminal program that I mentioned.It works very well at seeing what is happening on your rs232.
05-08-2008, 08:01 AM
One other thing to look at is if the signal is inverted or not. You could just try both inverted and non-inverted modes in the SERIN_CHAR function's mode parameters. You can also tell this by using your scope on PIN31 to see what the signal looks like.
Also, once you get the signal on Pin31 of the Prop (like you showed above), you can actually read the data right off the scope screen...
I tried inverting the signal - still not correct data,tried different parity - not successful.
The data coming out of the serial device· when connected toa serial devise analyser is: 96000 8N1 - the out put is "Decimal" - with the correect data.
I will try to read the Data off the scope ? this p.m and will get back to you.
Thanks for taking all this time to help me.
I have finally able to display the correct data on the screen.
The final solution was swapping the pins 2&3, inverting the signal and routing the signal via the DB9 - port in the PropRPM.
Although I can get the signal via the transisitor circuit to the PropRPM but was not able to get the correct data display.
Now that I have accomplished what I was after now I can proceed to the next step in my project.
I am very thankful to both of you for your extrodinary ability to stick with me to and to guide me along to resolve the issue.
I learned a lot about serial communication and as an additional bonus learned fast lesson on how to use a scope to read a serial signal.