Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.

Nucleo F401RE and rotary encoders

01 Jul 2016

Hi,

I have posted this as a question, let my try it also in the discussion area.

I am trying to use a rotary encoder on the Nucleo F401RE, with no luck so far. I am trying to use the mRotaryEncoder library, but it does not seem to work on this plattform.

Here is my program:

Nucleo F401RE program

#include "mbed.h"
#include "mRotaryEncoder.h"

DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
mRotaryEncoder RE(PA_0, PA_1, PA_4, PullUp, 500);

int main()
{
    pc.baud(115200);
    pc.format(8,Serial::None,1);
    pc.printf("\nmBed ready.");

    while(1)
    {
        myled = 1;
        wait_ms(80);
        pc.printf("\n%d", RE.Get());
        myled = 0;
        wait_ms(200);
        
    }
}

I was also trying an almost identical code with one of my older mBed plattforms, the LPC1768, and it worked first shot!

Here is the code for that:

LPC1768 program

#include "mbed.h"
#include "mRotaryEncoder.h"

DigitalOut myled(LED1);
Serial pc(USBTX, USBRX);
mRotaryEncoder RE(p29, p30, p28, PullUp, 500);

int main()
{
    pc.baud(115200);
    pc.format(8,Serial::None,1);
    pc.printf("\nmBed ready.");

    while(1)
    {
        myled = 1;
        wait_ms(80);
        pc.printf("\n%d", RE.Get());
        myled = 0;
        wait_ms(200);
        
    }
}

I ran a search on the mBed homepage to investigate why this is not working on my Nucleo board, but did not find a solution yet.

I have the feeling that this has something to do with the interrupt handling of the Nucleo board or the PinDetect function of the mBed+Nucleo "combo".

I also tried phisical (I mean external) pull-up resistors of the relevant lines, but in the case of the Nucleo board, it did not help.

I have also read it in the discussions somewhere that the Nucleo boards can have interrupts on virtually any pin with the restriction that if for example one has an interrupt on PA_0, one can not have an interrupt on PB_0 or PC0, etc. The same is valid for the other numbered pins.

Could someone point me into the right direction on solving this?

Thank you and Best Regards: Balazs

Please log in to post a reply.