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.


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.

  • \$\begingroup\$ what is the importance of 144.? I didn't get it properly. Please point me to any document or explain more. \$\endgroup\$ – user007 Dec 22 '15 at 10:01
  • \$\begingroup\$ You said it yourself in your question...? \$\endgroup\$ – alex.forencich Dec 22 '15 at 10:04
  • \$\begingroup\$ Thanks I got. I am using 44MHZ that means dividing it by 176 will give 250KHZ. So the value I have to put in register is 87 (87+1)*2=176 Is this correct.? \$\endgroup\$ – user007 Dec 22 '15 at 10:08
  • \$\begingroup\$ Looks right to me. It also passes the basic sanity check that since you're using a faster clock, the divider value should also be larger. \$\endgroup\$ – alex.forencich Dec 22 '15 at 10:11
  • \$\begingroup\$ Where did you find this equation divider = (BRG register value + 1)*2 \$\endgroup\$ – user007 Dec 22 '15 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.