Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Load shift-registers via SPI?

Status
Not open for further replies.

Mike - K8LH

Well-Known Member
Has anyone used the PIC MSSP module "SPI" mode to load 8 bit shift registers like the 74HC595?

I've always bit banged this process but if I'm reading the data sheet correctly it seems I could eliminate some software 'overhead' by simply stuffing my 8 bits of data into SSPBUF. Is that correct?
 
Of course it can be done :D I have always had to latch the strobe manually though. The SPI module just saves time, as it can run full whack. Its handy especially for large LED displays and I/O cards. - Or for getting more out of a 12f675.

I believe the 595 has a 'clock enable' (could be wrong here) which can be used with the CS line. On falling, it enables the SR to clock in data, and when rising, strobe it into its output buffer. SPI was meant for it. One caveat may be you must read the SPI buffer before sending, as it is a data exchange protocol, and expects to load in data as it sends data out, whether it means anything or not.

Blueteeth
 
Hmm I wanted to set the clock and data in on the 595 to be constantly running (since it won't affect the outputs till a latch enable strobe)
The PICs SPI shouldn't care if it doesn't see data on the DI input. Just throw it away in theory.
Hooking it up something like this.
**broken link removed**
 
So how many pins are tied up if I use the SPI? Is it four pins? If so, that may be why I decided to bit-bang it (a few years ago)...
 
It's only 3 pins and has no need of the serial input on the SPI hardware port so I just bit-banged it. Same goes for a Microchip digital pot I use - it too is output-only SPI.

Besides, I needed the async serial port and that shares pins with the SPI port. Which is why one could really grow to love the 24 series and their progamable pin assignment :)

P.
 
Well, don't want to over complicate things but you could use the USART on a PIC in 'sync mode' with a shift register, may require the clock to be inverted as I dont think it has a polarity setting...so thats in hardware. The shiftregister, as Bill pointed out, has a buffer register, so you can send it what you like..it will only move data from the shiftregister to the output buffer on a low-high strobe transistion.

I have done the above to use those two pins for UART and SPI (with an extra I/O to strobe, and another to select between the two).

As I said, overly complicated in hardware, but it can be done with simple logic/transistors. You just can't use both SPI and USART at the same time obviously...but with the speed of the SPI you won't need to.

Blueteeth
 
Blueteeth said:
Of course it can be done :D I have always had to latch the strobe manually though. The SPI module just saves time, as it can run full whack. Its handy especially for large LED displays and I/O cards. - Or for getting more out of a 12f675.

the 12f675 has a hardware spi module? i've been looking for an 8 or 14 pin pic with a slave i2c module, so far, I don't think one exists.
 
Just DIY,

Apologies, it looked like I was saying the 12F675 has a HW SPI module..it doesn't (if only it did!). I mentioned it as an example of a shiftregister used for I/O expansion (595 as output, and 165 as input). I know there are some 'newish' PIC's, 14 pin, run down to 2v, internal oscs..that have great peripherals, but I have to see some with an SSP. Looks like you'll have to have a software I2C slave (mikroC has a recently updated and debugged library for it). Software SPI on the other hand is much easier.

Bill, it does work. Although..many just use the clock and data lines, with the strobe/latch being 'manual'. But with multiple SPI devies, one would use mutiple I/O's for seperate CS lines anyway.

Blueteeth.

ps. Didn't want to sound like a know it all, its just personal experience. I've got a couple of LCD's with 595's attached so I can control them serially (SPI), fewer I/O's and the code is very similar...just move to SSPBUFF, instead of PORTB.
 
Blueteeth said:
Just DIY,

Apologies, it looked like I was saying the 12F675 has a HW SPI module..it doesn't (if only it did!). I mentioned it as an example of a shiftregister used for I/O expansion (595 as output, and 165 as input).

gotcha.

I love the 595 as an output expander myself ... inexpensive, easy to use and the engineers even considered ease of pc board layout when they put almost all the outputs on one side of the chip, instead of scattered all around like the 8 bit ports on a mid sized pic
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top