cancel
Showing results for 
Search instead for 
Did you mean: 

6MHz HSE from 8MHz creating many problems?

dawnofapril10
Associate II
Posted on October 15, 2015 at 11:52

Hi.I'm using 6MHz external crystal for STM32F0 instead of 8MHz.Following standard setup,i have successfully clocked the APB & AHB at 48MHz via PLL with the following modification on the code pasted below:

/* PLL configuration = HSE * 8 = 48 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL8);

Do i need to alter more in other part?I doubt this is causing UART framing error although i use this code:

int main(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
/* Configure USART1 pins: Rx and Tx ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
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);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1,ENABLE);
while(1)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, 'X');
}
}

What could be wrong again?
7 REPLIES 7
John F.
Senior
Posted on October 15, 2015 at 14:34

Do you have HSE_VALUE defined in your system? Does its value match the crystal?

dawnofapril10
Associate II
Posted on October 16, 2015 at 03:44

Hi John,

Yup.Found and altered the HSE constant in 32f0xx.h. Sorry.I'm a newbie in ARM.Do i need to alter this as well?

/* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;

Thanks.
Posted on October 16, 2015 at 04:04

No, it's a define usually passed in the compiler command line (see C compiler settings, or makefile), or in the stm32f0xx_conf.h file related to the project.

ie

-DHSE_VALUE=6000000

or

#define HSE_VALUE 6000000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dawnofapril10
Associate II
Posted on October 16, 2015 at 04:53

Hi Clive,

There's not such definition in mentioned file.Searched everywhere.

I'm using CooCoox.

Posted on October 16, 2015 at 06:01

http://www.google.com/search?q=CooCox+HSE_VALUE

http://www.coocox.org/forum/viewtopic.php?f=2&t=1886

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dawnofapril10
Associate II
Posted on October 16, 2015 at 06:56

Okay.It's in Configurations > Compile.

Thanks Clive.

dawnofapril10
Associate II
Posted on October 16, 2015 at 07:12

Okay.Now i got 36 MHz.What are the other alteration i should look at apart from RCC_CFGR_PLLMULL6?

Thanks.