6 years, 5 months ago.

Nucleo F411RE: LD2 flashes when I upload code and nothing else.

I'm working with a Nucleo F411RE board and just finished some test code but when I uploaded it to the board nothing happens except the onboard LD2 LED flashes.

The code is fairly simple. All it's supposed to do is read buttons and turn on LEDS. And I've successfully uploaded working code to this board for a couple weeks now. I can't figure out why it wont work anymore.

#include "mbed.h"

// BUTTONS/SWITCHES A, B, C, D, E
BusIn switches (PC_4, PC_5);                            // A, B
BusIn buttons (PC_6, PC_12, PC_3);                      // C, D, E
BusOut buttonC_RGB (PC_7, PC_10, PC_11);
BusOut buttonD_RGB (PC_13, PC_14, PC_15);
bool buttonState[3] = {0, 0, 0};
bool switchState[2] = {0, 0};

// ENCODERS A, B
BusIn encoderA (PB_4, PB_12, PB_13, PB_14);
BusIn encoderB (PB_15, PC_0, PC_1, PC_2);

// I2C
I2C i2c (PB_9, PB_8);



int buttonReader(int buttonID);
int switchReader(int switchID);
int TESTbuttonLED(int buttonID);
int TESTswitchLED(int switchID);

int main() {
    
    for(int i = 0; i < 3; i++) {
        buttonC_RGB[i] = 1;
        buttonD_RGB[i] = 1;
    }
    
    for(int i = 0; i < sizeof(buttons); i++) {
        buttons[i].mode(PullUp);
    }
    
    for(int i = 0; i < sizeof(switches); i++) {
        switches[i].mode(PullUp);
    }
    
    while(true) {
        
        for(int i = 0; i < sizeof(buttons); i++) {
            int buttonID = i;
            buttonReader(buttonID);
            TESTbuttonLED(buttonID);
        }
        
        for(int i = 0; i < sizeof(switches); i++) {
            int switchID = i;
            switchReader(switchID);
        }
    }
}



int buttonReader(int buttonID) {
    
    if(buttons[buttonID] == 1) {
        buttonState[buttonID] = !buttonState[buttonID];
        
        while(true) {
            wait(0.05);
            if(buttons[buttonID] == 0) {
                return 0;
            }
        }
    }
    
    return 0;
}



int switchReader(int switchID) {
    
    if(switches[switchID] != switchState[switchID]) {
        switchState[switchID] = !switchState[switchID];
        wait(0.2);
    }
    
    return 0;
}


int TESTbuttonLED(int buttonID) {
    
    if(buttonState[buttonID] == 1) {
        buttonC_RGB[buttonID] = 0;
        wait(0.5);
        buttonC_RGB[buttonID] = 1;
    }
    
    return 0;
}



int TESTswitchLED(int switchID) {
    
    buttonD_RGB[switchID] = switchState[switchID];
    
    return 0;
}
Be the first to answer this question.