Sharing IO Pins on the BS2px

xanatosxanatos Posts: 1,119
edited June 2013 in BASIC Stamp Vote Up0Vote Down
Hi,

I have the following setup:
' -----[ I/O Definitions ]-------------------------------------------------

SClock          PIN     0                ' shift clock (74HC595.11 and DS1302.7)
SDataIO         PIN     1                ' serial data (74HC595.14 and DS1302.6 via 1k resistor)
L595            PIN     2                ' output latch (74HC595.12)

CS              PIN     3                ' MCP3202.1 CS     MCP3204 CH0 = pin 2, CH1 = pin 3, Vss = pin 4, Vdd = pin 8
CLK             PIN     4                ' MCP3202.7 CK
AData           PIN     5                ' MCP3202.6 DO
ADCDin          PIN     6                ' MCP3202.5 DI

I'm sharing the data and clock lines for my DS1302 and my 74HC595s... but can I share the clock line of the MCP3202 and one (obviously) of the data lines with the others as well? Perhaps the ADCDin line, for example? DOes the MCP have the ability to ignore data passing by when the CS isn't active? From what I've read on teh data sheet I am thinking it should - but I just want to double check with you more experienced folks.

Thanks,

Dave
Like Xanatronics on FB: https://www.facebook.com/xanatronics

There are only 10 kinds of people in this world - those that know binary and those that don't.

Comments

  • 20 Comments sorted by Date Added Votes
  • Mike GreenMike Green Posts: 22,581
    edited June 2013 Vote Up0Vote Down
    The problem is that the 74HC595 doesn't have a CS line. The DS1302 has a CE line which is the opposite of CS in that it's active when high and disables the device when low. You can share the DS1302 clock and data lines with the MCP3202 CK and DO lines. In fact, you can connect the MCP3202 DO and DI lines together as well although you're probably better off if you put a 1K resistor between the DO line and the rest (DS1302 data, MCP3202 DI and BS2px I/O pin). The 74HC595 needs to be separate though with its own clock lines. The 74HC595 can share the data line with the other chips. You might use a 1K series resistor for the DS1302's data line. The 74HC595 doesn't need one because it's input data only.

    Make sure that the DS1302's CE line has a pulldown and the MCP3202's CS line has a pullup so both chips are disabled until the BS2px enables them. Similarly, you might want pulldown on the 74HC595's shift clock and latch clock lines.
  • xanatosxanatos Posts: 1,119
    edited June 2013 Vote Up0Vote Down
    I didn't know I could share DI & DO (via a 1k) on the MCP3202 - thanks for that! And I do have a 1k on the '1302's data line. Also - the 74HC595 sharing D & C with the DS1302 - I got that from a Savage Circuits project (I believe it was a binary clock). Please correct me if I'm wrong here, but my understanding is that, yes, the '595s will shift around in response to the data and clock signals directed at the other chips on the lines, but that those bits won't appear on the outputs until the Latch is enabled - am I correct?

    The reason I ask is because the system is working (or at least seems to be!) with the lines being shared with the 1302 and the '595s. Just that the last thing that goes on the lines before the '595s get their latch signal is the count that gets loaded to them immediately prior to the latch. These 595s are part of the circuitry that scans my 100+ inputs - and the sequencing is working perfectly with those lines shared. The 1302 is polled immediately prior to each scan sequence and it's reporting properly as well

    So long as the latching and data loading sequences between the '595s and the other items on the buss are well controlled - is there any other issue I'm potentially missing by sharing D & C with the '595s?

    Thanks - as usual - very much for your help.

    Dave
    Like Xanatronics on FB: https://www.facebook.com/xanatronics

    There are only 10 kinds of people in this world - those that know binary and those that don't.
  • Mike GreenMike Green Posts: 22,581
    edited June 2013 Vote Up0Vote Down
    Yes, you could share the serial clock line on the 74HC595 with the other shift clocks as long as you remember that the 74HC595's shift register will have to be reloaded if other devices are accessed. You're right. The 74HC595's outputs won't change until the latch clock is toggled. The shift register contents may be stirred up with the extra serial clock pulses, but that won't change the outputs.
  • xanatosxanatos Posts: 1,119
    edited June 2013 Vote Up0Vote Down
    Thanks for that - I knew it was working, but when I saw your post I got worried that there might have been something I just didn't know on that point. The way I've got it set up is that each devices' data gets loaded only with its own CS, or in the case of the '595s, immediately before the latch. Everything happens in nice linear, sequential blocks - which is probably why I like working with the Stamps so much :-)

    And to find that I can share the DI & DO as long as I use that 1k between them is an added benefit. I've got a LOT of stuff hanging off of my Stamp in this project, and now adding a pair of MAX7219s to drive a visual annunciator panel with 128 LEDs, I'm just wanting to conserve as many pins as possible (although I know I can share the D & C lines of the MAX7219 with the others as well - just adding it's own dedicated CS or Latch).

    Thanks again for your guidance,

    Dave
    Like Xanatronics on FB: https://www.facebook.com/xanatronics

    There are only 10 kinds of people in this world - those that know binary and those that don't.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited June 2013 Vote Up0Vote Down
    Here is an example of a project that shares the Clock and Data lines with a MAX7219, DS1302, DS1620 and three 74HC595s. You can share the lines on all these devices because they ignore the data when their chip select pins are not active. In the case of the 75HC595, data flows through the register no matter what, but if you don't latch it, it never appears on the outputs. And on a BASIC Stamp system you would typically shiftout the new data prior to latching, so it will never be an issue. Please look at my schematic toward the bottom of the page.

    http://www.savagecircuits.com/binarydigitalclock
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • xanatosxanatos Posts: 1,119
    edited June 2013 Vote Up0Vote Down
    Hi Chris, this is great because that was the project I saw that I realized I could share the 595 and 1302's D & C lines in the first place! Thanks for that. I love effiiciency in my projects, and running a list of chips all from the same pins makes me happy! :-) That binary digital clock actually showed me a few tricks I liked.

    Thanks again for your efforts and willingness to share & teach.

    Dave
    Like Xanatronics on FB: https://www.facebook.com/xanatronics

    There are only 10 kinds of people in this world - those that know binary and those that don't.
  • xanatosxanatos Posts: 1,119
    edited June 2013 Vote Up0Vote Down
    Just a quick set of shots of the input section I keep talking about. 8 cards that scan 16 inputs each. They're a little wobbly because the top mount isn't installed yet... This is the largest single project I've ever done going by chip count. And etching and drilling!

    picture087.jpg

    picture086.jpg

    picture082.jpg

    picture088.jpg
    1024 x 576 - 73K
    1024 x 576 - 87K
    1024 x 576 - 93K
    1024 x 576 - 97K
    Like Xanatronics on FB: https://www.facebook.com/xanatronics

    There are only 10 kinds of people in this world - those that know binary and those that don't.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited June 2013 Vote Up0Vote Down
    xanatos wrote: »
    Hi Chris, this is great because that was the project I saw that I realized I could share the 595 and 1302's D & C lines in the first place! Thanks for that. I love effiiciency in my projects, and running a list of chips all from the same pins makes me happy! :-) That binary digital clock actually showed me a few tricks I liked. Thanks again for your efforts and willingness to share & teach. Dave

    You're welcome. I wasn't sure if the code would be any use to you, but I figured the schematic would help you out. That schematic was also meant to show one other thing. There are always considerations when mixing SPI parts like that. As you can see on the DS1302 and the DS1620, the data lines have a series resistor to protect against contention in the event the BASIC Stamp is driving the lines at the same time as the DS1302 or DS1620. By using the same constants for the pins the code was also cleaner since there is a one-to-one correspondence bewteen the pin definition and the actual I/O pin. More devices could have shared these lines, however there was no need in this project.
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited June 2013 Vote Up0Vote Down
    Apologies for the broken link...I will get that fixed later tonight. The project is there, but the permalink forward isn't enabled on that project. Ooops!
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • xanatosxanatos Posts: 1,119
    edited June 2013 Vote Up0Vote Down
    FYI, I am now sharing the C & D lines with the 74HC595s, the DS1302, the MCP3202 and the MAX7219s (with appropriate 1k resistors on lines of possible contention). Flawless. Next is my I2C Comms with the items on the Spinneret board, which I hope will work as easily!

    Thanks again guys!

    Dave
    Like Xanatronics on FB: https://www.facebook.com/xanatronics

    There are only 10 kinds of people in this world - those that know binary and those that don't.
  • SapphireSapphire Posts: 474
    edited June 2013 Vote Up0Vote Down
    xanatos wrote: »
    Just a quick set of shots of the input section I keep talking about. 8 cards that scan 16 inputs each. They're a little wobbly because the top mount isn't installed yet... This is the largest single project I've ever done going by chip count. And etching and drilling!

    Dave, Just what are you going to do with all those 128 inputs?!?
    Sapphire
  • xanatosxanatos Posts: 1,119
    edited June 2013 Vote Up0Vote Down
    Hi Sapphire, I pick up level data via (up to) 128 4-20mA sensors in an industrial environment. Right now there will be around 90 active, but they're putting another 18 in.
    Like Xanatronics on FB: https://www.facebook.com/xanatronics

    There are only 10 kinds of people in this world - those that know binary and those that don't.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited June 2013 Vote Up0Vote Down
    The Permalink I posted for the Binary / Digital Clock is working again. I just had to get out my aggressive mouse pointer. :innocent:
    Chris Savage | Engineering Tech | Main Office: (916) 624-8333 | Direct to Tech Support: (888) 997-8267 | Website | Twitter | Google+
  • I know this post is old, but I have one more question on shared I/O pins. I'm running a Basic Stamp 2SX with a DS1302 Clock Module, a MAX7219 display chip and two 74HC165 shift registers to read switches (See the rough sketch below). I am sharing the CLK pin with all four devices. The MAX7219 has its own separate DATA pin (D2), but the DS1302 and the two shift registers all share the same DATA pin (D1), also each device has a dedicated CS pin (CS1-CS4).

    If you look at my sketch, you'll see I've place a 1k resistor in front of each of the three devices sharing the same DATA pin. Before I added the resistors, the clock was working fine, but I could not get the shift registers to feed in the switch values. Now that I have added the three resistors, nothing seems to work except the MAX Display. I know I have not posted my code (which would probably help), but for now I just need a sanity check that the resistors are indeed necessary. If I can work without them, or I only need one in front of the DS1302, then I'll make any hardware changes required. I just don't want to alter my code to death if I have a hardware issue. Thanks for your help.
  • No reason I can see that it should not work. The DS1302 and the BS2 are the only chips with I/O pins. The '165 and MAX7219 are input only so you only need a current limiting resistor on the MAX or the BS2, not both.
    In science there is no authority. There is only experiment.
    Life is unpredictable. Eat dessert first.
  • Kwinn,

    If I understand you correctly, I can eliminate the two 1k resistors at both shift register data lines and just have the one 1k on the shared data line between the BS2 and the DS1302?
  • Tracy AllenTracy Allen Posts: 6,113
    edited December 5 Vote Up0Vote Down
    There is no reason it shouldn't work with those resistors in place, so I do suspect there is a problem in the firmware. Most likely a chip left in the selected state when it shouldn't be. Remember that the DS1302 has a CE high enable, not low select.
  • truetech, here's a project using the same parts you listed, all sharing clock/data lines. A schematic is included, as well as source code for the BASIC Stamp 2.

    http://www.savagecircuits.com/binary-digital-clock/
    Chris Savage - Savage///Circuits
  • Chris,

    It looks like you only have the one 1k on the shared data line (DS1620, DS1320 & 74HC595's) just before the DS1302 and you have a dedicated data line for the MAX7219 (Just like I'm doing). I used part of the clock code from your site already and that seems to work good. My circuit is an Odometer, Trip odometer and Clock all on a triple stack mezzanine set-up (3"x4") that fits into a standard 1988 Pontiac GTA dash bezel. I'm using the battery backed RAM on the DS1302 to store the Miles & Trip values every mile and then save just the miles value to the EEPROM every 100 miles so it does not wear it out. The odometer pulses (2000/mile) are feed into an 8 bit counter (74590) that I use as an accumulator while the stamp is running through it's main loop. When it's time to read the accumulator (0-255), I just shift in the 8-Bit values and reset the counter. The math is pretty simple and the 2SX has more than enough speed to keep up with the accumulator at normal highway speeds.

    I'll tweak a few things based on your suggestions and post a picture of the completed unit. Thanks for your help guys.
  • AntediluvianAntediluvian Posts: 45
    edited December 5 Vote Up0Vote Down
    Those resistors aren't technically necessary, but are there to protect in the event of a programming error that causes an output on the line at the wrong time. They're just to limit current to prevent pin damage, so they don't need to be any larger. I once completely rebuilt the dash in a 1980 Pontiac Grand Prix to be all digital. While that system used a Z80 at the heart, I too had a functioning Odometer, Trip Odometer and Clock all running on the 2x16 LCD that was used for that section. Of course, that was all parallel interface, but in the case of the project I linked I was attempting to show how to share / consolidate I/O lines. While I prefer SPI to I2C, you see the disadvantages to SPI when you start losing pins. I've also integrated 74HC595 and 74HC165 using 4 pins.

    By the way, I did receive your email and will reply later today. I've been a little busy lately.
    Chris Savage - Savage///Circuits
Sign In or Register to comment.