STM32 Saat Frekansı Kontrolü

Projemizde saat frekans ayarlamalarımızı istediğimiz gibi oluşturduk, fakat acaba saat frekansımız gerçekten de istediğimiz gibi çalışıyor mu? Bir osiloskop yardımı ile gerçek saat frekansımızı ölçmemiz mümkün. Aşağıda STM32F401RE mikrokontrolörünün Reference Manual’inden yaptığım alıntıda görüldüğü gibi bu işlem için iki pin ayrılmış durumda. Yazılımda bu pinlerin ayarlamalarını yapmamız gerekiyor.

Clock-out capability
Two microcontroller clock output (MCO) pins are available:
• MCO1
You can output four different clock sources onto the MCO1 pin (PA8) using the
configurable prescaler (from 1 to 5):
–HSI clock
– LSE clock
– HSE clock
– PLL clock
The desired clock source is selected using the MCO1PRE[2:0] and MCO1[1:0] bits in
the RCC clock configuration register (RCC_CFGR).
• MCO2
You can output four different clock sources onto the MCO2 pin (PC9) using the
configurable prescaler (from 1 to 5):
– HSE clock
– PLL clock
– System clock (SYSCLK)
– PLLI2S clock
The desired clock source is selected using the MCO2PRE[2:0] and MCO2 bits in the
RCC clock configuration register (RCC_CFGR).
For the different MCO pins, the corresponding GPIO port has to be programmed in alternate
function mode.
The selected clock to output onto MCO must not exceed 100 MHz (the maximum I/O
speed).

Pinleri Alternate Function moduna ve 100MHz’e ayarlıyoruz. MCO1 çıkışını dahili osilatör çıkışına, MCO2 çıkışını sistem clock’a bağlıyoruz. Frekanslar 4 e bölünecek şekilde ayarlıyoruz.

Hepsi bu kadar. Artık çıkış pinlerinden saat frekansımızın gerçek değerini ölçebiliriz.

GPIO_InitTypeDef GPIO_InitStructure;

RCC_ClockSecuritySystemCmd(ENABLE);

/* Enable GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO);

/* Configure MCO (PA8) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);

RCC_MCO1Config(RCC_MCO1Source_HSI, RCC_MCO1Div_4);

/* Enable GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_MCO);

/* Configure MCO (PC9) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);

RCC_MCO2Config(RCC_MCO2Source_SYSCLK, RCC_MCO2Div_4);
Etiket(ler): , , , .Yer işareti koy Kalıcı Bağlantı.

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir