zirunhong I wonder if I have done in the wrong way of setting the SPI frequency?
The frequency is a function of both the nRF9160 and the SD card you’re using. What’s the rated max speed of the card?
Seems like you’re setting the frequency correctly in your overlay
zirunhong I wonder if it is correct to say SPI only run at a maximum speed of 8MHz on nrf9160?
From a brief glance, the test code you have looks like it should work.
Have you read back the data to see what was the result? I’d be curious if the data you’re writing is corrupt or not.
Have you also, for sanity, probed the GPIO pins you’re using for SPI? (Also which pins are you using?) It’s always good to double check hardware fundamentals even if the problem doesn’t seem to manifest that way. It also doesn’t hurt to have a probe on the SPI CLK line to see if you can, indeed, modify the speed.
zirunhong I wonder if it is correct to say SPI only run at a maximum speed of 8MHz on nrf9160?
I’m running the onboard flash (supposedly) at 40MHz. I did see the 8bps though. I’ve yet to probe these signals as they run on inner layers. Now I’m curious to see if it truly is 40MHz! I know that 8bps doesn’t translate to 8MHz as there’s overhead, delays, finite buffers for transferring, etc.
One thing that you may want to turn on if you’re using logs as measurements is the CONFIG_LOG_IMMEDIATE
option. Otherwise the log thread will display the messages when the system is not busy processing higher priority tasks.
Similarly, back to the probing part, you could probe the CLK line to check for the start and end of transfer and make sure you’re hardware measurements agree with the software output.
Hope that helps!