Go Down

Topic: Hardware SPI questions (Read 15 times) previous topic - next topic

scswift

Hey guys,

I'm studying how to do hardware SPI because I don't think doing it in software is going to be fast enough to write to a DAC at the sampling rates I need.

I've already discovered that to do hardware SPI I need to connect my DAC to specific pins.  SPI may use any or all of the following:

D10 - CS aka Chip Select aka SS aka Slave Select
D11 - SDI aka ??? aka MOSI aka Master Out Slave In aka Output
D12 - ??? aka ??? aka MISO aka Master In Slave Out aka Input
D13 - CLK aka SLK aka Serial Clock

What I need to know is this:

1) Do I need to connect pin 10 to the DAC, if it is the only thing I am communicating with?  Could I stick a pullup/pulldown resistor on the DAC's CS pin instead to keep it eneabled?

2) If I can get away without connecting pin 10 to the DAC, can I put it to other use without issue, or will the hardware SPI mess with the pin?

3) Question 2 applies to pin 12 as well.  The DAC has no way to send data back to the atmega, so that pin will be connected to nothing.  Can I use it for something else without screwing up my communications, and without the communications messing with whatever's on the pin?

scswift

#1
Oct 11, 2010, 12:08 pm Last Edit: Oct 11, 2010, 12:14 pm by scswift Reason: 1
I found the page for the SPI library:
http://arduino.cc/en/Reference/SPI

It says the following:

Quote
On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK). On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). Note that even if you're not using the SS pin, it must remain set as an output; otherwise, the SPI interface can be put into slave mode, rendering the library inoperative.


When they say "even if you're not using the SS pin, it must remain set as an output" do they mean you can't do anything with the pin, or is it just a warning that if you do do anything with the pin, like blink an LED, it's gotta be used as an ouput pin?


Also:
http://arduino.cc/en/Reference/SPITransfer

This transfer function sends and recieves a byte at the same time.  What happens if after I set up my SPI communications I set pin 12 to output and use it for other things and then call this function?  Will I just get garbage back?  Will it toggle pin 12 back to an input?

Grumpy_Mike

Quote
The DAC has no way to send data back to the atmega, so that pin will be connected to nothing.  Can I use it for something else without screwing up my communications,


Yes

scswift

So how about pin 10?  As long as I leave that set to output, can I do other things with that?  Or will the SPI lib pull it low every time I try to send a byte to the DAC?

Ran Talbott

Quote
So how about pin 10?


It's absolutely essential to "real" SPI (occasionally, you'll see a manufacturer call some other shift-register-based interface "SPI" when it's not the same as the original Motorola design.  You need to watch out for that when picking parts):  it tells the slave "This data  is for you" and "This is where the byte starts and ends".  So you can't just tie it low if you have only one slave.

Go Up