Skip to main content
idris
Associate II
October 2, 2015
Question

Measuring input from a reed switch with STM32L100RB

  • October 2, 2015
  • 8 replies
  • 1593 views
Posted on October 02, 2015 at 17:08

I want to count pulses generated from a reed switch. The switch has three outputs connected to WKUP1, WKUP2 and PCO of the STM32L100RB. I need an example or suggestions on how to achieve this. Kindly assist.

    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    October 2, 2015
    Posted on October 02, 2015 at 19:36

    Take a look at the EXTI examples where the pins could generate interrupts. Might need to consider debouncing

    STM32L1xx_StdPeriph_Lib_V1.2.0\Project\STM32L1xx_StdPeriph_Examples\EXTI\EXTI_Example\main.c

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    idris
    idrisAuthor
    Associate II
    October 5, 2015
    Posted on October 05, 2015 at 09:46

    Thanks Clive1.

    idris
    idrisAuthor
    Associate II
    October 5, 2015
    Posted on October 05, 2015 at 09:56

    Hi Clive1,

    Kindly send me the link to the V1.2.0 Library. I can only find the latest version i.e. V1.3.1.

    Tesla DeLorean
    Guru
    October 5, 2015
    Posted on October 05, 2015 at 18:29

    Pretty sure the newer version has the same examples, I just went through the most recent library I had unpacked.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    idris
    idrisAuthor
    Associate II
    January 21, 2016
    Posted on January 21, 2016 at 13:59

    Hello Clive1,

    Please see the attachment for my implementation. I set up two interrupts for the signal lines. One on GPIO PA0 connected to EXTI_Line0. The second on GPIO PC13 connected to EXTI_Line However, the first interrupt is working fine, but the second isn't. I want to be able to get input from both signal lines. how can I achieve this?

    ________________

    Attachments :

    Switch_Interrupt_Implementation.docx : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Tm&d=%2Fa%2F0X0000000biD%2F60tvLLytkJ8zmjsOqI5cYTAJbucx465frvnpUExwYOc&asPdf=false
    Tesla DeLorean
    Guru
    January 21, 2016
    Posted on January 21, 2016 at 18:29

    Probably want a more complete/consistent use of defines, or create a pin structure holding all the details,

    void EXTI15_10_IRQHandler(void) {
    if (EXTI_GetITStatus(EXTI_Line13) != RESET) {
    if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_9)) // <<< SURELY THIS SHOULD BE PC.13 ???
    {
    GPIO_ResetBits(GPIOA, GPIO_Pin_9);
    delay (500);
    GPIO_SetBits(GPIOA, GPIO_Pin_9);
    delay (500);
    }
    EXTI_ClearITPendingBit(EXTI_Line13);
    } 
    }

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    idris
    idrisAuthor
    Associate II
    January 23, 2016
    Posted on January 23, 2016 at 17:01

    Thanks Clive1. I did make the adjustment but still no response. Do I need to include EXTI_GenerateSWInterrupt(EXTI_Line13) in the main?

    Tesla DeLorean
    Guru
    January 23, 2016
    Posted on January 23, 2016 at 18:21

    And have we confirmed that the GPIOs transition as expected if you just loop polling the pins, and outputting via LEDs?

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..