How to set SD card clock frequency between 100 kHz – 400 kHz

clockfrequencysd

I am interfacing a 32 GB microSD card with PIC32MX795F512L. I am following the examples provided in Lucio de Jasio's book.

As the author has described that to set a 250 kHz, they are driving their peripheral clock frequency by 144. Which means 36 MHz when divided by 144 gives 250 kHz. But then why are they setting the SPI1BRG = 71;? (SPI1BRG = SPI baudrate register.)

I am using 44 MHz as a peripheral clock frequency. What value should I use?

I am really confused in setting the clock frequency for the SD card.

Best Answer

They probably set it to 71 as the relationship between the register value and the divider value is probably divider = (BRG register value + 1)*2. In this case, (71+1)*2=144. You just need to calculate the divider value, divide by two, and subtract 1.