SPI clarification

Just making sure I understand this correctly:

SPI uses the CLOCK, MISO, MOSI for all devices and 1 CS(OI pin) for each device? Can I use both Digital and Analog pins?

From the micro controller:
Four wires for one device, +1 for each additional device. And check the datasheet to ensure it will work via SPI before purchasing.

Hi,
Sounds right..

There MIGHT be some SPI Slave-Only device but I don't recall one...

Arduino Analog inputs are also useable as Digital I/O.

The "Default" SPI Pins on UNO are 11-12-13 for MOSI MISO CLK. You can use any other pins for individual Slave Select. However Pin 10 Slave Select must always be set as OUTPUT.

SEE: SPI - Arduino Reference which has ALL the info...

Can I use both Digital and Analog pins?

Only for bit banging the SPI protocol, that is creating the SPI signals in software. The chip has built in hardware that handles the SPI protocol and the pins it uses are fixed and can not be changed. Using the built in hardware is about 20 times faster ( at a guess ) than bit banging.

Analog and Digital pins can be used for the Slave Select to the various devices, with the SS pin (D10 on '328Ps) set to output, even if it is not used as one of the slave selects.
SPI clock can be as high as 8 MHz for the fastest transfers to/from the 328P (with a 16 MHz system clock).

I might be getting ahead of myself, but, do all microprocessors have clocks?
Crystals onboard used for timing, right? Assuming they do, but just to be sure.

Not sure what you mean:

CrossRoads:
SPI clock can be as high as 8 MHz for the fastest transfers to/from the 328P (with a 16 MHz system clock).

Just like wireless networks; you're only as fast as the router, even if the provider is pushing out ##mbps? Is that the same analogy? Going to look for the datesheet for the temp/humidity sensor I've been looking at. BRB

Never mind. I think I got it. You may have to slow down the clock for some devices in order for them to communicate correctly... Check the data sheet! ? Will SPI devices (data sheet) tell you what rate to set the clock?

I might be getting ahead of myself, but, do all microprocessors have clocks?

Yes, but it's just an oscillator or a pulse (like a musician's metronome).

When we say "the processor's clock", we're not talking about a time-of-day clock.* (Of course once you have an oscillator at a known speed, you can make a time-of-day clock in software.)

Microprocessors are sequential devices, the do one thing at a time in a particular sequence. Each "step" takes some amount of time and "philosophically" you need some kind of clock or counter if you are going to do things in sequence.

Machine-code instructions typically take more than one clock cycle, and that information is available in the Atmega datasheet. But, since we are writing C++, which the compiler converts to machine code, we usually don't know (and we usually don't need to know) how machine code or how may clocks it takes, etc.

Just like wireless networks; you're only as fast as the router, even if the provider is pushing out ##mbps? Is that the same analogy?

It's somewhat similar, in that you can't transmit faster than you can receive (or vice-versa). But, there is a difference... The network protocol is smart-enough to slow-down if necessary. SPI isn't that smart so it's up to you (the programmer) to make sure the speed is OK.

  • A time-of-day clock is usually called a "Real Time Clock". You can get RTC modules that have a built-in battery and their own oscillator. They are more accurate than the Arduino's clock/oscillator and they don't loose track of time when your Arduino looses power.

Yes, all microprocessors Need a clock. I don't know that all microprocessors necessarily Have a clock.
The Atmel 328P, 1284P, 2560, all have an internal 8 MHz RC oscillator that can be used, as well as connecting a faster 16 MHz external clock. Some will support faster (20 MHz) with an appropriate core change.

Most Arduino boards use an external resonator, or an external crystal, for the clock source. I think some of the smaller Lilypad boards may only use the internal 8MHz source.

I guess that analogous to the router; or perhaps, you're only as fast as the weakest link.

Allrighty then, Now I need a class on reading datasheets.

I just pulled up the datasheet for a temp/humidity sensor, i've been looking at:
Bosch BME380
Starting at page 32 paragraph 6.3

The address for this device is 0xF7 to read data from it?

6.4.3 SPI timing ? 10mhz max?

CrossRoads:
Most Arduino boards use an external resonator, or an external crystal, for the clock source.

On my Uno; Tiny oblong metal thingy with 1600...(too tiny for me to count the number of zeros on it)=16Mhz?

do all microprocessors have clocks?

All but one sort and that is the Amulet which is an aysynchronous design by Steve Furber who was big at Acorn and Arm and then moved to Manchester ( University ). I have the privilege of interviewing him once for a magazine article.

marine_hm:
On my Uno; Tiny oblong metal thingy with 1600...(too tiny for me to count the number of zeros on it)=16Mhz?

Yes it is a crystal oscillator running at 16MHz

Bump for #7. Question regarding reading data sheet.

Yes 10MHz is the fastest you can read from it. Given you only have a 16MHz processor that can only generate an 8MHz clock what is the problem?

The address for this device is 0xF7 to read data from it?

There are lots of registers in this device if you rad what has gone before and reading data requires you to read register 0x7F. The device has three bytes written to it as previously described, one byte specifies the register.

Mike; you answered my question. Data read max, given the uno crystal, I can read from that temp sensor chip @ 8MHz.

Thank you guys sooo much for the lesson!

If you consider data as one bit then yes you can read it at 8MHz. From the data sheet you need three bytes to get one byte of data so the data read rate is somewhat lower.

I see it as one control byte and one register byte as a minimum, but more data bytes can be transferred.
Code can be written to do it at just over 1uS (17 clocks) per byte of data.

:confused: Does that mean I would divide 8MHz by 2 or 3? Or some other factor I have yet realized?

CrossRoads:
I see it as one control byte and one register byte as a minimum, but more data bytes can be transferred.
Code can be written to do it at just over 1uS (17 clocks) per byte of data.

Do you recommend just using I2C for this device? Should be fairly easy since there will be no other device connected.

CrossRoads:
I see it as one control byte and one register byte as a minimum, but more data bytes can be transferred.
Code can be written to do it at just over 1uS (17 clocks) per byte of data.

Yes but once you have written those two you must write something else to clock in the data byte you want so that makes a minimum of three bytes for the first byte of data back. Subsequent bytes only need one or two bytes depending on the auto increment.

marine_hm:
:confused: Does that mean I would divide 8MHz by 2 or 3? Or some other factor I have yet realized?

First divide it by 8 so you talk about bytes not bits and then divide it by three.

marine_hm:
Do you recommend just using I2C for this device? Should be fairly easy since there will be no other device connected.

Makes no difference to what you have to write and as I2C is normally a 100KHz standard it is going to be a lot slower to access.