Shop OBEX P1 Docs P2 Docs Learn Events
BS2px to BS2px Serial Comm problem — Parallax Forums

BS2px to BS2px Serial Comm problem

FalconFalcon Posts: 191
edited 2012-01-21 17:28 in BASIC Stamp
Hello all,

For a while I have had a BS2px and a BS2 communicating flawlessly using the following Serial code:


BS2px (Base Unit)
T9600           CON     396
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     T9600 + Inverted

SERIN SI\FC, baud, 100, notalk,[WAIT ("Report"), current1, current2, a2dResult0, a2dResult1, a2dResult2, a2dResult3]         ' Serial In from Remote BS2

BS2 (Remote Unit)
T9600               CON     84
Inverted            CON     $4000
Open                CON     $8000
Baud                CON     T9600 + Inverted

SEROUT SO\FC, Baud, 2, Main, ["Report", current1, current2, a2dResult0, a2dResult1, a2dResult2, a2dResult3]  ' send the data

To gain some code space for additional functions, I replaced the BS2 (Remote Unit) with another BS2px. I then replaced the baud code with the same as used for the Base Unit BS2px code. Those were the only hardware and software changes made at that time. Now I cannot get the two px's to communicate.

Since both Stamps are the same flavor, shouldn't the baud code be the same as well?

Would the best solution be to add the following from the BSS&RM:
#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T1200 CON 813
T2400 CON 396
T9600 CON 84
T19K2 CON 32
T38K4 CON 6
#CASE BS2SX, BS2P
T1200 CON 2063
T2400 CON 1021
T9600 CON 240
T19K2 CON 110
T38K4 CON 45
#CASE BS2PX
T1200 CON 3313
T2400 CON 1646
T9600 CON 396
T19K2 CON 188
T38K4 CON 84
#ENDSELECT
Inverted CON $4000
Open CON $8000
Baud CON T38K4 + Inverted

I may have to break down and buy that Serial Port Complete book by Jan Axelson (it's been in my Amazon cart for a month now), but I'm hoping there is a simpler solution in the mean time.

falcon

Comments

  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-14 16:37
    Falcon,

    Let me chew on your code a little, i'll get back to you soon.

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-14 16:57
    Falcon,

    I know it is the same set-up but double check this anyway:

    Make sure your ground between the two stamps is in good shape. I like to twist the Serial Data Line with a Ground (about 2 twists per inch) so the AC (edges) of the signal has a good return path (AC takes the path of least inductance).

    Try this: see it you can hack up some code to do serial in and out between some pins on the same stamp. In the mean time, I am still looking at your code.

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-14 17:26
    Falcon,

    By all means, you code should always have the conditional compile code for the baud modes - they are constants and pre-processor (#) commands so they don't take up any space in your target EEPROM.

    You only sent a code fragment... so I coded using IO PINs 1 and 2. Are you using IO 16 (the dedicated Serial pin) for Tpin, Rpin or both?

    I am trying to watch the football game and my wife keeps asking me if I see Sallie (one of the Patriots Cheerleaders is our friend). I will see if I can try your code on on BS2px after the game.

    So far what you are doing seems to be routine. Are you getting garbled data, or no data timeout? Try putting in a label for the Parity error, I always use them.

    Paul
  • FalconFalcon Posts: 191
    edited 2012-01-14 17:59
    Paul,
    I'm using pins 7 & 8.

    I just re-installed the BS2 (with the previous code) and the BS2px communicates with it just fine.

    I can't think of a reason that the px to px communication wouldn't work with both units using the same baudrate codes.

    I'll make anothe attempt with the conditional compile code inserted in the Base and Remote units.

    I appreciate your assistance,

    falcon
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-15 07:18
    Falcon,

    I agree, this should work. Let me see if I can find an old BS2px (I think I have one somewhere that works but I blew out a couple of IO on it) Tip: Never get rid of a PStamp, you can always fix them for a fraction of the price or reuse them if only a few IO are blown.

    Patriots won last night, we didn't see Sallie.

    I'll get back to you later.

    Paul

    Also, on your new BS2px, try using different IO and if that makes any difference.
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-15 07:44
    Falcon,

    Try using a larger timeout in your SERIN command. This may sound counter-intuitive, but until you get this working use longer timeouts.

    As you know the, remote unit's code will run faster (and a lot of its timing constants are different) now that you are using a BS2px.

    I only found 1 BS2px. I had mentioned to loop back the IO on the PS2px but I forgot to mention you need to externally delay the signal (SERIN and SEROUT cant run at the same time in a BS2 series device). I have an FPGA development board that used when I did this years ago (I made a 200ms digital delay from it which worked in my application)... so don't even try that experiment - you have two BS2px's anyway and that is eaisier with which to experiment.

    Keep going, I'm still looking at it on my end.

    Paul
  • FalconFalcon Posts: 191
    edited 2012-01-15 08:42
    Paul,
    I pared the code down to just the essentials to see if I could get just 2 bytes to send/receive between the 2 BS2px's. Coincidentally, I did increase that SERIN timeout to 200. See following code:

    Base unit code
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    SI              PIN     7                                            'Serial Input
    FC              PIN     8                                            'Serial In flow control pin
    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T1200 CON 813
        T2400 CON 396
        T9600 CON 84
        T19K2 CON 32
      #CASE BS2SX, BS2P
        T1200 CON 2063
        T2400 CON 1021
        T9600 CON 240
        T19K2 CON 110
        T38K4 CON 45
      #CASE BS2PX
        T1200 CON 3313
        T2400 CON 1646
        T9600 CON 396
        T19K2 CON 188
        T38K4 CON 84
    #ENDSELECT
    
    Inverted         CON  $4000
    Open             CON  $8000
    Baud             CON  T9600 + Inverted
    
    current1        VAR     Byte
    current2        VAR     Byte
    
    main:
    SERIN SI\FC, baud, 200, notalk,[WAIT ("Report"), current1, current2]         ' Serial In from Remote BS2
    
    DEBUG BIN8 current1, BIN8 current2, CR
    PAUSE 100
    GOTO main
    
    notalk:
    DEBUG CLS, "Data not received", CR
    GOTO main
    


    I reinstalled the BS2px in the Remote unit and installed the following pared-down code:
    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    
    Clock1              PIN     0                    '74HC165 Shift clock  Pin 2
    SerData1            PIN     1                    '74HC165 Serial data  Pin 7
    Load1               PIN     2                    '74HC165 Input load   Pin 1
    SO                  PIN     7                    ' serial output
    FC                  PIN     8                    ' flow control pin
    
    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T1200 CON 813
        T2400 CON 396
        T9600 CON 84
        T19K2 CON 32
      #CASE BS2SX, BS2P
        T1200 CON 2063
        T2400 CON 1021
        T9600 CON 240
        T19K2 CON 110
        T38K4 CON 45
      #CASE BS2PX
        T1200 CON 3313
        T2400 CON 1646
        T9600 CON 396
        T19K2 CON 188
        T38K4 CON 84
    #ENDSELECT
    
    Inverted    CON   $4000
    Open        CON     $8000
    Baud        CON     T9600 + Inverted
    
    current1            VAR     Byte
    Current2            VAR     Byte
    
    Main:
    
    GOSUB Read_Sensors                           'Read 16 Sensors from 74LC165
    DEBUG BIN8 current1, "    ", BIN8 current2, CR
    SEROUT SO\FC, Baud, 50, Main, ["Report", current1, current2]  ' send the data
    
    'PAUSE 50                                     'wait
    GOTO MAIN                                    'repeat forever
    
    '-------------------------SUBROUTINES------------------------------------------------
    Read_Sensors:
    HIGH load1
    PULSOUT Load1, 5                              'Reads Input from 74HC165
    SHIFTIN SerData1, Clock1, MSBPRE, [Current1, Current2]      ' Reads Input from 74HC165
    PAUSE 5
    RETURN
    

    Still no luck reading those 2 Bytes on the Base Unit. The DEBUG code on the Remote Unit does display the 2 Bytes in 8-bit binary so that leads me to believe that the BS2px I'm using in the Remote Unit is working. However it doesn't confirm the two I/O pins I'm using on that 'px are good. I suppose that's my next step.

    The Base and Remote Units are in my house and garage, but it's a pain to walk back and forth to check to see if its working. I have extra BOE's so I may have to mock it all up on one table to speed up the troubleshooting process.

    Also, I do have a BS2pe so I guess I could try that in the Remote Unit.

    I look forward to any suggestions you or anyone else has.

    falcon
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-15 10:46
    Falcon,

    Yes, trying different I/O pins would be the next logical step. I think I mentioned that before, but anayway....

    I was thinking the same thing as your code shows. Attached is the code that I tried on my BS2px. I looked at the signals on a scope and the Remote BS2px was putting out the proper data. I only have the one BS2px so I had to use a Arbitrary Wafeform Generator to take the place of the Remote BS2px. I emulated the data stream and pumped it back into my BS2px (now programmed as the Base) and it received it all pefrectly.

    Things to try (just for experiments):

    Slower Baud rates
    Dont use Flow Control
    A different Pair of Pins on the Remote unit
    A good ground between the two PStamps
    Twisted Pair Signal/Gound for the Serial Data line
    Another BS2px

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-15 10:52
    Falcon,

    Can you send me a photo of your setup? Use a private message if you like.

    Also, how long is your serial line between the stamps?

    Paul
  • FalconFalcon Posts: 191
    edited 2012-01-15 13:12
    Some Progress.

    I re-confirmed that the data transfers fine with a BS2 in the Remote location. BS2 to BS2px works good.

    I then installed the BS2px from the Remote Unit into the Base Unit while leaving the BS2 in the Remote Unit. No data transfer. I suspect the BS2px I had been using in the Remote Unit has a problem.

    I installed a BS2pe in the Remote Unit and installed the original BS2px into the Base Unit. Success. The 'pe will transfer the data to the 'px.

    I will plug the suspected bad 'px into my PDB and check each I/O.

    I am using every pin at the Remote Unit so switching I/O pins around to avoid a bad pin is not an option. In fact, if I had a good solution for using a BS2p40 at that location I'd have one there by now. Where do you get a carrier-type board that will accomodate the 'p40?

    Thanks for all of your assistance. Sometimes you just have to work through a problem with someone else to provide some other troubleshooting angles and an entirely different set of experiences.

    falcon
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-15 19:06
    Falcon,

    Fantastic! Yes, when I was a young pup Engineering Assistant, the engineers would always ask me if they could explain their designs to me. As they described what they were doing, they often found little bugs here and there - all I had to do is listen and ask a few questions... everybody learns in these situations. That is what this Forum is like somtimes - a peer review.

    I will check Digikey and see what they have. I think Parallax may have some boards too. I will get back to you with some links.

    Hey, by the way... is this project some kind of battery charger or block heater monitor for your cars?

    Paul
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-15 20:04
    Falcon,

    1)
    This is a low cost solderless breadboard that I have used before and it is inexpensive (about $8).

    http://search.digikey.com/us/en/products/TW-E40-510/438-1109-ND/2618532

    If you have a Parallax BOE or Homework Board you can carefully remove the small proto board that comes with it (it is held on with double stick tape). Then you can stick this one in its place. It will hang over the Board, but it will work.

    2)
    The Super Carrier Board is good but the prototype area is 2 rows too shy for the BS2p40! ($20)
    Parallax did that to get you to shell out $160 for the Professional Board. But, you may be able to cut some traces to get a BS2p40 to work on it.

    http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/122/Default.aspx

    I was thinking about getting a Super Carrier Board and then installing a Zero Insertion Force (ZIP) connector. ($15)
    This way I could swap in and out BS1's, BS2's, BS2p40's as needed - with a flip of a lever (no more bent pins pulling out a PStamp!).

    http://search.digikey.com/us/en/products/40-6554-10/A306-ND/27600

    3)
    Parallax has their Professional Development Board (if you want to shell out $160)
    I has a lot of nice features but I have access to all of them in the lab so I never purchased one.

    http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/123/Default.aspx

    Paul
  • FalconFalcon Posts: 191
    edited 2012-01-16 06:14
    Falcon,

    Fantastic! Yes, when I was a young pup Engineering Assistant, the engineers would always ask me if they could explain their designs to me. As they described what they were doing, they often found little bugs here and there - all I had to do is listen and ask a few questions... everybody learns in these situations. That is what this Forum is like somtimes - a peer review.

    I will check Digikey and see what they have. I think Parallax may have some boards too. I will get back to you with some links.

    Hey, by the way... is this project some kind of battery charger or block heater monitor for your cars?

    Paul
    Hey Paul,

    The project is a home monitoring system, and is still in development. About 60% complete now. I'm monitoring door locks, garage door positions, window positions, weather alerts, driveway sensors, CO and Smoke, washing machine and water heater leaks, cold and hot water temps, various inside and outside air temps. I can monitor it all on my mobile phone too. I am expanding to include an RFID reader and electric door bolt and a datalogger to keep a history of all events. I'm also trying to incorporate as many provisions for future functions as possible before I have my PCBs made.

    It's all really for fun and a learning experience. None of it is absolutely necessary since I've lived 47 years without any of it.

    falcon
  • FalconFalcon Posts: 191
    edited 2012-01-16 06:29
    Falcon,

    1)
    This is a low cost solderless breadboard that I have used before and it is inexpensive (about $8).

    http://search.digikey.com/us/en/products/TW-E40-510/438-1109-ND/2618532

    If you have a Parallax BOE or Homework Board you can carefully remove the small proto board that comes with it (it is held on with double stick tape). Then you can stick this one in its place. It will hang over the Board, but it will work.

    2)
    The Super Carrier Board is good but the prototype area is 2 rows too shy for the BS2p40! ($20)
    Parallax did that to get you to shell out $160 for the Professional Board. But, you may be able to cut some traces to get a BS2p40 to work on it.

    http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/122/Default.aspx

    I was thinking about getting a Super Carrier Board and then installing a Zero Insertion Force (ZIP) connector. ($15)
    This way I could swap in and out BS1's, BS2's, BS2p40's as needed - with a flip of a lever (no more bent pins pulling out a PStamp!).

    http://search.digikey.com/us/en/products/40-6554-10/A306-ND/27600

    3)
    Parallax has their Professional Development Board (if you want to shell out $160)
    I has a lot of nice features but I have access to all of them in the lab so I never purchased one.

    http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/123/Default.aspx

    Paul

    Paul,
    Thanks for the links and all the time and effort helping me out.

    #1 is a good idea. I already have several of those BBs so that is a real possibility. My Home Monitor project will be based on two BOEs with additional circuitry placed on a second PCB connected with header cables.

    #2 That ZIF is a good idea but I can see where $10 would be a lot to add to production costs. I have a BS2 with pins that look like a squashed cockroach.

    #3 I have a PDB but it is overkill to install in a project. I have/will install a BOE, but that's a lot less. I did happen to bid on and win a little board at the last Parallax EBay dump that allows me to install a BS2p40 and then plug it into a 28-pin socket. It has an extra hsingle header row that allows connections to the AUX I/O's.

    I was too late to get one of the BOE's that accomodated the 'p40.

    falcon
  • Paul RomskyPaul Romsky Posts: 66
    edited 2012-01-16 10:49
    Falcon,

    Hey kid, I am going to be 49 in June, take it from an old man [laugh] it is never too late to get a security system (unless you were robbed)!

    We had some intrusion on our property just before the holidays (they didn't get in but they tried). I told my wife that I could make our own custom alarm system using PStamps.
    She didn't want to wait so we went with FrontPoint. Its not like ADT, Brinks and the others... My house is in CONSTANT communication with the monitoring center. It handles doors ,windows, motion, fire, heat, smoke, water, freezing, carbon monoxide, gas detection, cameras, driveway sensors, lighting, and more. The sensor are all wireless and uses a phone line and built in cellular data phone. Even if someone trys to jam the system or cut the phone line, it knows because it lost comms instantly! Rather than spending all that money for a whole bunch of window sensors, I wired the windows to the nearest door sensor using tiny reed switches and magnets! That saved me a lot of money.

    I can even control it all from my smart phone.

    It sounds like your system has the same capabilities except for the monitoring. Look in the PBasic help for DTMFOUT, there is a nice circuit there that you can use to have your system call you and then send tones to let you know what is going on. You can even use a EEPROM and a DAC to send a recorded voice.

    I built this when I was thinking about making my own system. Once triggered it would take over the phone line, dail a number, and start playing the digital message. Worked like a charm, but that is all moot now.

    Anyway....
    For a permanent project, go to Digikey and

    Search for breadboards. Then find a cheap 40 pin socket. The whole thing should be about $20

    If you are bold, goto ExpressPCB and download their free software. You can make your circuit board for about $100. Actually I think you get two that that price.

    Good Luck,
    Paul
  • bsnutbsnut Posts: 521
    edited 2012-01-18 00:38
    Falcon,
    If you are bold, goto ExpressPCB and download their free software. You can make your circuit board for about $100. Actually I think you get two that that price.
    I have ExpressPCB software on my laptop for doing my drawings and PCB design and been using it for years now. I suggest you have PCB made for a more permanent future than using breadboards do to the fact that the wires can get loose over time. I had a board made for the Spinneret contest that I entered last year for web based remote monitoring system. Take a look at the drawings that I did for the contest and it should give some more ideas for your project that you are working on.
  • FalconFalcon Posts: 191
    edited 2012-01-18 04:34
    bsnut wrote: »
    Falcon,

    I have ExpressPCB software on my laptop for doing my drawings and PCB design and been using it for years now. I suggest you have PCB made for a more permanent future than using breadboards do to the fact that the wires can get loose over time. I had a board made for the Spinneret contest that I entered last year for web based remote monitoring system. Take a look at the drawings that I did for the contest and it should give some more ideas for your project that you are working on.

    I installed that ExpressPCB software over the Christmas break and I like it. I'm not familiar with the mor capable ($$) products but I think that will do what I need to do.
    I'll take a look at your project.

    falcon
  • KievlaninKievlanin Posts: 55
    edited 2012-01-21 17:28
    I have no idea if this would help to anyone.
    I am a beginner.
    IMG_5149.jpg
    IMG_5150.jpg
    IMG_5151.jpg


    I have made a serial connection b-n BS1 & BS2
    Below is some code.
    I had problems sending letters, but 3 digit numbers coming thru no problem.
    Maybe the code below will be helpfull to someone.

    This code is for BS1:
    ' SERIN.BS1
    ' Learning program.
    ' For connection see: Figure 5.40: SEROUT Open-Drain
    'Circuit. This circuit is FOR use with
    'the Open, Non-inverted baudmode.
    'Page 426 • BASIC Stamp Syntax AND Reference Manual 2.2 • [URL="http://www.parallax.com"]www.parallax.com[/URL]
    'Made to transfr three digits from BS2 to BS1
    
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    SYMBOL serData = W2
    SYMBOL counter =B1
    Main:
    PAUSE 500
      SERIN 1, T2400, serData
      DEBUG serData, CR, #serData, CR, %serData, CR, @serData
    PAUSE 10000
    DEBUG "serData equal-", W2
    PAUSE 3000
    DEBUG CLS
    GOTO Main
    

    This code is for BS2:
    ' SEROUT.BS2
    ' Learning program.
    ' For connection see: Figure 5.40: SEROUT Open-Drain
    'Circuit. This circuit is FOR use with
    'the Open, Non-inverted baudmode.
    'Page 426 • BASIC Stamp Syntax and Reference Manual 2.2 • [URL="http://www.parallax.com"]www.parallax.com[/URL]
    'Made to transfr three digits from BS2 to BS1
    
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    value CON 65
    Main:
    PAUSE 1000
    SEROUT 0, 396, [value]                         ' baudmode set for BS1
    GOTO Main
    
    
    1024 x 768 - 83K
    1024 x 768 - 79K
    1024 x 768 - 107K
Sign In or Register to comment.