2011-09-15 10:57 PM
just tryin to send PE.06 high but its not workin. is it my sourcecode? IT DOES compile without error or warnings.
#include ''stm32f10x_lib.h''
void Clk_Init (void)
{ // 1. Clocking the controller from internal HSI RC (8 MHz) RCC_HSICmd(ENABLE); // wait until the HSI is ready while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // 2. Enable ext. high frequency OSC RCC_HSEConfig(RCC_HSE_ON); // wait until the HSE is ready while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET); // 3. Init PLL RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9); // 72MHz RCC_PLLCmd(ENABLE); // wait until the PLL is ready while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // 4. Set system clock dividers RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); RCC_ADCCLKConfig(RCC_PCLK2_Div8); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); RCC_HCLKConfig(RCC_SYSCLK_Div1); #ifdef EMB_FLASH // 5. Init Embedded Flash // Zero wait state, if 0 < HCLK 24 MHz // One wait state, if 24 MHz < HCLK 56 MHz // Two wait states, if 56 MHz < HCLK 72 MHz // Flash wait state FLASH_SetLatency(FLASH_Latency_2); // Half cycle access FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable); // Prefetch buffer FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); #endif // EMB_FLASH // 5. Clock system from PLL RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); }////////////////////////////////
// // // //Start MAIN function // // // //////////////////////////////void main(void)
{ GPIO_InitTypeDef GPIO_InitStructure; #ifdef DEBUG debug(); #endif // Init clock system Clk_Init(); // GPIO Init // Enable GPIO clock and release reset RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOE, DISABLE); // Assign PE6 to LED GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_WriteBit(GPIOE,GPIO_Pin_6,Bit_SET); while(1) { } }#ifdef DEBUG
/******************************************************************************* * Function Name : assert_failed * Description : Reports the name of the source file and the source line number * where the assert_param error has occurred. * Input : - file: pointer to the source file name * - line: assert_param error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) *//* Infinite loop */
while (1) { } } #endif2011-09-17 05:28 AM
At the end of the clock init, add:
// Wait until PLL is used as system clock source while(RCC_GetSYSCLKSource() != 0x08 ) {} Cheers, Hal2011-09-17 06:20 AM
still nothing. but i think its the clock init function.
when clock init starts theres a push operation which goes to register 7. but at the end of the clock init function there is a pop which moves contents from register 0 to the PC which is 0xFFFFFFFE. why would it be doing this?2011-09-18 12:55 PM
I finanly got it working. Thanks for the help guys!
turns out it was the last function call of clock_init() // 5. Clock system from PLL RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); After the function call it pops 0xFFFFFFFE on to the stack. the question is why?2011-09-18 08:20 PM
So how did you finally get it working ? Inquiring minds want to know.
Cheers, Hal2011-09-18 11:51 PM
Chances are by not initializing the clocks, and using the standard reset conditions, or whatever startup was setting them too.
I'd probably ensure after both RCC_SYSCLKConfig() that it would spin waiting for the correct clock source to actually engage.