Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 1 month ago.
DigitalIn (NC) not working
I want my code to be able to 'know' if a pin has been defined
#include "mbed.h" //#define BAUDRATE 57600 #define BAUDRATE 115200 //#define BAUDRATE 19200 //#define BAUDRATE 921600 //#define BAUDRATE 19200 //#define BAUDRATE 9600 DigitalOut myled(LED1); DigitalOut Pin_A (p6); DigitalOut Pin_B (p7); DigitalOut Pin_C (NC); DigitalOut Pin_D (p9); Serial pc (USBTX,USBRX); int main() { pc.baud(BAUDRATE); if (Pin_A != NC) pc.printf ("Pin_A is defined .. \r\n"); else pc.printf ("Pin A NOT defined !\r\n"); if (Pin_B != NC) pc.printf ("Pin_B is defined .. \r\n"); else pc.printf ("Pin B NOT defined !\r\n"); if (Pin_C != NC) pc.printf ("Pin_C is defined .. \r\n"); else pc.printf ("Pin C NOT defined !\r\n"); if (Pin_D != NC) pc.printf ("Pin_D is defined .. \r\n"); else pc.printf ("Pin D NOT defined !\r\n"); while(1) { myled = 1; wait(0.2); myled = 0; wait(0.2); } }
results in ..
Pin_A is defined .. Pin_B is defined .. Pin_C is defined .. Pin_D is defined ..
I am designing building some hardware, and want to be able to selectively enable / disable selected pins.
Very weird, because I am sure this used to work.
After all this is how i would define, for example an SPI with no MISO ..
SPI MySPI_TX_Only (p8, NC, P10, p23); // MOSI, MISO, CLOCK, CS
Thanks in advance
Ceri
1 Answer
12 years, 1 month ago.
Problem is if you do a DigitalIn == ..., it will read the DigitalIn and return 1 or 0. So that has never worked like this. If you have for example a class that uses a pin, it will have a PinName in the constructor, and you can check if that is equal to NC.