cancel
Showing results for 
Search instead for 
Did you mean: 

HELP! SIMPLE APP WONT WORK

tre2020067
Associate II
Posted on September 16, 2011 at 07:57

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)

  {

  }

}

#endif
14 REPLIES 14
raptorhal2
Lead
Posted on September 16, 2011 at 16:40

I have never had to initialize the HSI if using the HSE. But PLLCLK is connected to HSE, so that is probably not your problem.

I have never had to release the APB2 peripheral reset. Try commenting that line out.

You don't identify the processor, so we have to assume PE6 is available. Single step through the code to make sure it executes as expected, and put a meter or scope on PE6 to make sure the problem is not a bad LED.

Cheers, Hal

Posted on September 16, 2011 at 19:47

If PE.6 doesn't work, try some other pins.

Stick a scope of the pin, and toggle it, lot more effective at identifying that we're talking about the right pin.

Perhaps the LED is active LOW?

The board should implicitly be running from the HSI to start with, if it's functional enough to be running code, you can set up the GPIO side of things with very little additional effort. For a peripheral reset to be helpful you need to ENABLE then DISABLE, so you actually get a reset pulse regardless of initial conditions, and it really needs a running synchronous clock first.

void main(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);

  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_SetBits(GPIOE,GPIO_Pin_6);

 

   while(1)

   {

   }

  

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tre2020067
Associate II
Posted on September 16, 2011 at 21:08

commented out the peripheral reset and still nothin.

i stripped most of the code from a working program. so im sure the led works.

my setup is a stm32f103vet6 with a segger jlink and IAR Workbench.

tre2020067
Associate II
Posted on September 16, 2011 at 21:21

Tried modifying the main function to reflect what u wrote but still nothing.

its confusing because the initial code that i got this from works fine.

i run the debugger. i stopped it and saw this.

http://i54.tinypic.com/35kj11k.png

Posted on September 16, 2011 at 21:27

HELP! SIMPLE APP WONT WORK

THE LED IS ACTIVE LOW - YOU NEED TO DRIVE IT WITH ZERO TO ILLUMINATE IT.

http://www.ebay.com/itm/ARM-Cortex-M3-STM32F103VET6-Mini-Development-Board-/190550067511?pt=LH_DefaultDomain_0&hash=item2c5dab4937

http://www.sendspace.com/file/6sh37k

http://fs02n2.sendspace.com/dl/ae0a2c0b6991b8fc1db6f1fa4a2ed554/4e73a1d56d97b874/6sh37k/STM32F103VET6.pdf

Note how the other end of the PE5/6 LED is connected to 3.3V VCC

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tre2020067
Associate II
Posted on September 16, 2011 at 22:38

clive1 forgive my ignorance, u mean somethin like 

GPIO_WriteBit(GPIOE,GPIO_Pin_6,Bit_RESET)?

i tried this but still nothin. 

raptorhal2
Lead
Posted on September 17, 2011 at 03:21

i run the debugger. i stopped it and saw this.

 

http://i54.tinypic.com/35kj11k.png

So what code line executed to trigger this fault? To answer that, you need to single step through the code.

Cheers, Hal

tre2020067
Associate II
Posted on September 17, 2011 at 04:30

tre2020067
Associate II
Posted on September 17, 2011 at 13:08

Okay well, i cant get the fault to occur again but i think i found where the problem is starting.

at the very last instruction of the clock init function, the program dead ends at a mov instruction that goes no where. what could be causing this?

http://i55.tinypic.com/2elfosk.png