cancel
Showing results for 
Search instead for 
Did you mean: 

simple input routine not working

tre2020067
Associate II
Posted on November 10, 2011 at 07:35

the ctrl registers remain at reset values but idr 0 an 1 goto low(0). is there something wrong with my source?

//

//

//

//STM32 BUTTON TEST

//by T. Herring tre2020067@gmail.com

//

////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////

//INCLUDE FILES

//these file should already be include in project space and do not need to be

//defined again.

//////////////////////////////////////////////////////////////

/*

#include stm32f10x_vector.c

#include stm32f10x_conf.h

#include stm32f10x_it.c

#include stm32f10x_lib.c

*/

#include ''stm32f10x_lib.h''

////////////////////////////////////////////////////////////

//FUNCTION PROTOTYPES

////////////////////////////////////////////////////////////

//void clockconfig();

void gpio_flash();

void Clk_Init (void)

{

        

        //RESET CLOCK CONFIG

        RCC_DeInit();

        

        

  // 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);

   

 

  // 2-1. Set system clock dividers

#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

    // Prefetch buffer

  FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    // Flash wait state

  FLASH_SetLatency(FLASH_Latency_2);

  // Half cycle access

  FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);

#endif // EMB_FLASH

 

 

 

 

 

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    RCC_PCLK2Config(RCC_HCLK_Div1);

    RCC_PCLK1Config(RCC_HCLK_Div2);

  RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);    

  RCC_ADCCLKConfig(RCC_PCLK2_Div8);

 

  // 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);

  // 5. Clock system from PLL

 //RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

 

 /*//WAIT FOR PLLCLK TO STABLILZE

while(RCC_GetSYSCLKSource() != 0x08)

{

}

 */

}

void main(void)

{

      GPIO_InitTypeDef GPIO_InitStructure;

      

      //SETUP DEBUG

      #ifdef DEBUG

   debug();

#endif

//CONFIGURE CLOCKS

Clk_Init();

  // GPIO Init

  // Enable GPIO clock and release reset

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOC, ENABLE);

  RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOC, DISABLE);

 //  GPIO_DeInit(GPIOC);

 

 

 

    // 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_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_5

    | GPIO_Pin_6;  

  GPIO_Init(GPIOE, &GPIO_InitStructure);

      

    

    // Enaable Swithches on PC0 and PC1

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;  

  GPIO_Init(GPIOC, &GPIO_InitStructure);

 

 

//APP MUST NEVER EXIT MAIN FUNCTION. STRANGENESS WILL OCCUR..

while(1)

{

  if(GPIOC->IDR != 0){

     GPIOE->BRR = 0x60;

  }

    GPIOE->BSRR = 0x60;

  }

}

void gpio_flash()

{

int i;

for(i=0;i<300000;i++){

 GPIOE->BSRR = 0x60;

}

for(i=0;i<30000;i++){

 GPIOE->BRR = 0x60;

}

//end gpio_flash

}

#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
3 REPLIES 3
tre2020067
Associate II
Posted on November 10, 2011 at 17:22

***UPDATE***

code works flawlessly when i run it on a different port (PORTA).

whats up with that?

Posted on November 10, 2011 at 19:54

code works flawlessly when i run it on a different port (PORTA). whats up with that?

Probably because you're not masking the bits you're examining, the probability of IDR being non-zero, for bits you're not interested in, are quite high.

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 November 11, 2011 at 18:53

that makes sense. thanx clive1 for your response!