4 years, 2 months ago.

Pin operations

The most basic task on a microcontroller - which I cannot get right - toggling port pins. I am using Nucleo Board F103-RB. My knowledge of C programming is reasonable .... my knowledge of C++ is roughly zero ....

at the start of main.cpp if I do this:

#define TESTPIN PB_7
DigitalInOut mypin(PinName TESTPIN);

... I assume that I am instantiating a DigitalInOut pin OBJECT which will have various methods available. I look in the API documentation to find them and then I expect to use these methods like this:

// set pin to have open drain output
mypin.mode(OpenDrain);

// set pin to output
mypin.output();

// set pin low
mypin.write(0);
wait_us(400);

// set pin high
mypin.write(1);
wait_us(100);

mypin.write(0);
wait_us(100);

// set pin as input 
mypin.input;
wait_us(100);

yet this will not compile - each 'method' reports error 153 .... "Error: Expression must have class type"

What am I doing wrong?

1 Answer

4 years, 2 months ago.

You should declare the pin as;

DigitalInOut mypin(TESTPIN);

The ''PinName'' in front is wrong.

Accepted Answer