cancel
Showing results for 
Search instead for 
Did you mean: 

can't set reset a Bit (STM32F091 64pins)

raphael
Associate II
Posted on May 04, 2015 at 11:49

Hello everyone.

My target is STM32F091C I want to send something using SPI and after that make an impulse with a bit of my microcontroller. On my scope I see that I send well the data but the impulse is not generate.

Here is the code of the gpio init + the function that should generate the impulse :

void init_system_gpio (void)

{

    GPIO_InitTypeDef GPIOA_Init;

    GPIO_InitTypeDef GPIOB_Init;

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB,ENABLE); /*PORT B and PORT A are used*/

    /*PORT B Configuration*/

    GPIOB_Init.GPIO_Pin =GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_13 | GPIO_Pin_15;

  GPIOB_Init.GPIO_Speed = GPIO_Speed_50MHz;

  GPIOB_Init.GPIO_Mode = GPIO_Mode_AF;

  GPIOB_Init.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIOB_Init.GPIO_OType = GPIO_OType_PP;

  GPIO_Init(GPIOB, &GPIOB_Init);

    

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_Mode_OUT); //Freq_UPD

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_Mode_OUT); //LED Debug 1

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_Mode_OUT); //LED Debug 2

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_Mode_IN);  //BP1

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_Mode_IN);  //BP2

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_0);    //SPI2 CLK

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_0);    //SPI2 MOSI

    

    /*PORT A Configuration*/

    GPIOA_Init.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_4 | GPIO_Pin_9| GPIO_Pin_10 | GPIO_Pin_15;

  GPIOA_Init.GPIO_Speed = GPIO_Speed_50MHz;

  GPIOA_Init.GPIO_Mode = GPIO_Mode_AF;

  GPIOA_Init.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIOA_Init.GPIO_OType = GPIO_OType_PP;

  GPIO_Init(GPIOA, &GPIOA_Init);

 

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_Mode_AN); //ADC_IN0

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_Mode_AN); //DAC_OUT1

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_0);        //UART1 TX

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0);        //UART1_RX

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_Mode_OUT);//RST DDS

}

void freq_ud_dds(void){

    GPIOB->ODR=(GPIOB->ODR)|0x04;

//    int i =0;

//    GPIO_WriteBit(GPIOB, GPIO_Pin_3, Bit_SET);

//    while(i<200) i++;

//    GPIO_WriteBit(GPIOB, GPIO_Pin_3, Bit_RESET);

//    GPIO_SetBits(GPIOB, GPIO_Pin_3);

//    GPIO_ResetBits(GPIOB, GPIO_Pin_3);    

};

As you can see in this last function I tried many ways to set/reset my bit...

If you can help me to generate this pulse, it would be great !

Thank you
2 REPLIES 2
Posted on May 04, 2015 at 13:04

You're use of GPIO_PinAFConfig is all wrong, you need to pick a peripheral there, not a GPIO Mode. Do the GPIO_Init() for the pins using the correct mode, ie IN/OUT/AIN/AF

Also try not to cross post to other forums here.

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

thank you clive !

Sorry to answer late, i didn't see notification in my mail box