System clock of Photon vs Core affecting SPI

Hello folks,

Give that the Photon’s system clock (120 MHz) is almost twice as fast as the Core’s clock (72 MHz), do we need to adjust the SPI_CLOCK_DIV on the libraries that we port from the Core to the Photon?

The issue that I’m having is that after migrating from the Core to the Photon, the SD card reader of the [Adafruit TFT LCD shield] (https://learn.adafruit.com/adafruit-3-5-color-320x480-tft-touchscreen-breakout/bitmaps-spi-mode) that I’m using stops working. SD.Begin() returns False, and I get Error: CMD0 in the serial.

My suspicion is that the new SPI speed might be too fast for the SD SPI. The LCD does work though.

Any thoughts?

The libraries I’m using are:


STs documents are pretty clear on the clock structure. I don’t have the data sheets in front of me but if you look at both it should be clear if they need to be divided down differently.

There’s part of me that wants an API in the SPI class that allows you to specify the desired clock frequency rather than the clock divider. This will make it more portable between devices.

e.g.

SPI.setClockFrequency(24*MHz);

The API would choose the clock divider that results in the highest frequency not higher than the frequency specified.

2 Likes

Thanks guys. So the answer to my question is, yes - you need to replace the DIV4 for a DIV8 to have a similar clock frequency. Right?

@mdma, you would definitely have my vote on the frequency specific API. This is going to be even more useful when the Electron (and future processors) is/are launch.

1 Like

Hello Folks,

I’m having failures on SD.begin() at “random”. I’m using the SD library from @BDub.

This issue started happening when I switch from using a Core to using a Photon.

I changed some pointers on Sd2Card.cpp. Besides that, co I need to adjust something else on the SD library to get it working for the Photon?

I try changing the SPI_CLOCK_DIV from 4 to 8 in case the clock speed was the issue, but that didn’t work. Any other ideas?

Thanks!

After further investigation, it seems that this might be a hardware issue. I posted the question here: