I'm seeing the SPI driver on the zero is not configurable. In other words, it will not operate on any SPI settings I select. The same code works correctly on a Mega 2560. Can anyone offer suggestions on how to make it work?
Here's my code:
#define BIT_RATE 250000
If I change any SPISettings values, there is no change. I'm seeing the default 4MHz clock. LSB vs MSB always MSB first.
Thanks - JJS
I figured out the problem. Source code review tells me it's a bug. Here's how I know:
Look at SPI.cpp (relevant snippets below). Find the begin() method of SPIClass. Note the config() call at the end of the method. It overrides all of whatever SPI settings are passed when SPI.beginTransaction() is called. The workaround is to call SPI.setClockDivider() _after_ SPI.begin(). That's what worked for me.
I'm REALLY surprised this bug is not documented nor even findable on google.
const SPISettings DEFAULT_SPI_SETTINGS = SPISettings();
// PIO init
The Zero SPI driver is more buggy than I determined earlier.
The next bug I found is that calling transfer16() before calling transfer(uint8_t) will occasionally cut short the 8 bit SPI transactions. When I changed to all transfer(uint8_t) calls, the shortcut transaction went away.
Beware! The Zero SPI driver is crappy.
It's not a bug, simply your code... In your first line of code you're setting up the SPI connection with your desired settings but by calling SPI.begin() you're resetting everything back to the defaults. If you want to set your own SPI settings there's no need to use SPI.begin() at all.