Scott Penrose


Scott is an expert software developer with over 30 years experience, specialising in education, automation and remote data.

Difference between revision 2 and current revision

No diff available.

Arduino SPI Mode

I have been using a lot of SPI devices lately. Specifically working with SD card and the ADS1247.

SPI Library Gotchas

  • used to say 0,1,2,3 - but it has now been fixed to say SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3 - thanks team.
  • Must set standard CS pin to output, even if not used (e.g. 10 or 53)

SPI Mode Issues

Working with the Ethernet chip, the SD Cards - they all use SPI Mode 0. This means you only need to use chip select to set the library.

Now start working with devices of different modes. Each may even use interrupts. You MUST set the mode (and any other settings, like Clock Speed etc) each time before chip select.

  • Chip select Low
    • Set Mode, Clock, MSB/LSB etc


  • Libraries using SPI, do not do this ! E.g. SD Card library does not set mode etc - they should
    • Only real solution is to update the libraries where they use chipselect to set the mode, timing, MSB, LSB etc.
  • Interrupts during this change could cause issues
    • You set Mode
    • Interrupt takes over, sets mode, returns
    • You set Chip select - but your mode is now wrong
    • Only real solution is to disable interrupts during this call. This makes more sense anyway and has solved other bugs.

I don't have resolution to these two issues yet. The first is just a matter of having custom versions. But that can be tricky - although I am going to try inheritance first. The second problem is more difficult.

VIM worth learning = Move paragraph = { } Find word marked = *

  • Arduino