How to set SDHC clock to 50MHz?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set SDHC clock to 50MHz?

Jump to solution
1,053 Views
naftalir
Contributor III

Hi,

I've tested the SDCLK and noticed it works default in 20MHz clock, so i've managed to chage it to 40MHz but not to 50MHz.

My code looks like that:

        /* Set SDCLK to 40Mhz*/

        esdhc_ptr->SYSCTL &= 0xFFFFFFF7; //Disable the SD Clock

        esdhc_ptr->SYSCTL &= 0xFFFF00FF; //Setting the Prescaler to 0

        esdhc_ptr->SYSCTL |= 0x00000020; //Setting the Divisor to 3 

        esdhc_ptr->SYSCTL |= 0x00000008; //Enable the SD Clock

        esdhc_ptr->SYSCTL |= 0x00000004; //Remain the SDHC clock always enabled 

Tags (3)
0 Kudos
1 Solution
320 Views
c0170
Senior Contributor III

Hello,

SIM_SOPT2[SDHCSRC] register specifies Clock for SDHC peripheral. I note that you did not clarify your target MCU, therefore everything what I have written is for K40. Slight changes might be for different MCU.

Regards,

MartinK

View solution in original post

0 Kudos
10 Replies
321 Views
c0170
Senior Contributor III

Hello,

SIM_SOPT2[SDHCSRC] register specifies Clock for SDHC peripheral. I note that you did not clarify your target MCU, therefore everything what I have written is for K40. Slight changes might be for different MCU.

Regards,

MartinK

0 Kudos
320 Views
naftalir
Contributor III

Again, Thank you for your true help! :smileyhappy:

I forgot to mention my MCU: K60F120M, if there is any change to what you wrote i will be happy to know :smileyhappy:

Sincerely yours,

Naftali.

0 Kudos
320 Views
MarkP_
Contributor V

Hi,

I created a test project with CW 10.2 and selected PE-support.

The configuration is shown in picture below and register initialization is in attached C-file.

~Mark

.MK60_config.png

320 Views
naftalir
Contributor III

Hi Markku!

Thank you for your help.

I did managed to get 50MHz with the source of the OSC0ERCLK:

/* My Code for this is: */

SDHC_MemMapPtr esdhc_ptr = SDHC_BASE_PTR; 

SIM_MemMapPtr sim_ptr = (SIM_MemMapPtr)0x40047000; //Base address of the SIM

/* Set the SDHC clk source to OSC0 = 50MHz */

sim_ptr->SOPT2 |= 0x20000000; //Set ESDHCSRC clk to OSC0ERCLK

esdhc_ptr->SYSCTL &= 0xFFFF00FF; //Disable the Prescaler

esdhc_ptr->SYSCTL &= 0xFFFFFF0F; //Disable the Divisor 

Thank you all for your help: Kojto and Markku!!

:smileyhappy:

0 Kudos
320 Views
MarkP_
Contributor V

I think 50MHz cannot be generated from 120MHz CPU clock, need to be 100MHz.

0 Kudos
320 Views
naftalir
Contributor III

****I've accidently pressed "Send Button".

My question is: how to set the registers in order to provide clock of 50MHz, when the CPU Clock is 120MHz?

Thank you all.

0 Kudos
320 Views
c0170
Senior Contributor III

Hello naftalir,

I assume you are using Kinetis platform. There''s section in Reference Manual for your MCU where this equation is written:

Clock frequency = Base clock / (prescaler x divisor)

There's not much to do here to set desired 50 MHz with 120 MHz source clock. Closest you can get is 40 MHz. You can anyway change the bus clock.

Regards,

MartinK

0 Kudos
320 Views
naftalir
Contributor III

Thank you Kojto,

If i change the bus clock it will change the whole system performance..

Can i do it somehow without affected the system?

0 Kudos
320 Views
c0170
Senior Contributor III

Hello,

I forgot to mention, there's chapter in Reference manual dedicated to Clock distribution with the same name.

This is based on Kinetis 40:  There're 4 possible clock sources :

System clock

MCGPPLLCLK/MCGFLLCLK

OSCERCLK

SDHC0_CLKIN

You can select one of these clock sources for SDHC module and customize divider to have 50 MHz.

Regards,

MartinK

320 Views
naftalir
Contributor III

Again, Thank you Kojto but may i ask you for example on how to change the clock source?

i cant seem to find it..

Thank you.

0 Kudos