SPI Modes - why choose one over another?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Like most microcontroller peripherals, the AVR SPI is so flexible that it nigh impossible to set up without having to spend a lot of timing asking the datasheet, "˜Why on Earth would I want to do that?' And, as usual the datasheet just stares back at you, mute with a bit of drool dripping off its chin.

In this specific case, I'm provided with

Quote:
There are four combinations of SCK phase and polarity with respect to serial data,
And I can't see any reason to choose one over the other - except to match the other end of the SPI which might arbitrarily be set to one of the modes. Maybe a better way to ask this is if I am going to communicate via SPI between two AVRs, I'd set both to the same mode, but why would I prefer one over the other three modes?

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As far as I am aware, it's just a "choose the one which suits your slave" choice - I don't think there's a benefit to one over another. Note that different devices on the same bus can have different modes, requiring you to switch to the correct mode for each peripheral.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seem to be on an SPI kick at the moment. One nice thing about the "CPHA==0" modes is that a slave's MISO pin will immediately output the first-to-transmit bit (by default, the MSB) of SPDR the instant that SS gets asserted, without needing any clocks from the master.

That can be exploited to add "slave is ready" handshaking to arrangements where a master AVR communicates with slave AVRs via SPI.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Levenkay wrote:
Seem to be on an SPI kick at the moment.
Me? Well there is the 'taking over the world' subtext, but I am trying to get up to speed on SPI.

Your other post indicates that you know a bit about real world SPI.

My goal at the moment would be just to duplicate the SPI under ISP as used by AVRs and understand why each register bit is set as it is. The key is 'why' which I'm not sure I see in each case, like this one. I'm willing to accept 'because' for my own work, but since I might be writing about this topic, I should at least know what I'm saying. I need to get this correct and as simple as possible so I'm really trying to figure out what I can safely ignore and what I really need to know. SPI seems pretty darn simple until you get into the 'flavors' and I'm just not yet sure which flavor to pick.

Any advice is welcome.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Stick with the defaults, as that's the most common mode (ISP is LEAD RISING and SAMPLE LEADING according to my AVRISP-MKII clone code).

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!