Noob help - Basics (input and output)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Noob help - Basics (input and output)

365 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LukeHill2015 on Fri Jan 16 16:40:20 MST 2015
Hello everyone

Ive been given a LPCExpresso 1769 board along with an experiment board.

So far i can do light sequences with little knowledge how it is actually working. Ive been looking for help and documentation/tutorials for a while not but cant find anything usefull.

Here is my code to turn on only 1 LED.

LPC_PINCON->PINSEL0 &= (~(3 << 12));

LPC_GPIO0->FIODIR |= (1 << 6);

LPC_GPIO0->FIOSET = (1 << 6); //turn on
LPC_GPIO0->FIOCLR = (1 << 6); // turn off

The confusion i have is that if i take out the FIOSET and FIOCLR line to just have

LPC_PINCON->PINSEL0 &= (~(3 << 12));

LPC_GPIO0->FIODIR |= (1 << 6);

The LED is on, i do not understand why this is as i thought FIODIR just configures the pin.
What if i wanted to configure the LED for output until a button is pressed?

Any help would be much appreciated,
Thank you
0 Kudos
3 Replies

343 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Jan 17 05:06:10 MST 2015

Quote: LukeHill2015
That is what i have at the moment, FIOSET is actually turning the LED off. Which is just confusing, and FIOCLR will turn it on.



Then you are obviously switching the cathode of your LED  :D

So pin low is LED ON and pin high is LED OFF...

Schematic of your board should help you to riddle this behaviour  :)


0 Kudos

343 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LukeHill2015 on Sat Jan 17 04:40:30 MST 2015
Thanks for the help but that didn't do anything for me :/

    LPC_PINCON->PINMODE0 |= (1 << 12); //pulldown

    LPC_PINCON->PINSEL0 &= (~(3 << 12));

    LPC_GPIO0->FIODIR |= (1 << 6);


    volatile static uint32_t i;
    while (1) {

    LPC_GPIO0->FIOSET = (1 << 6); // Turn LED1 on
  }

That is what i have at the moment, FIOSET is actually turning the LED off. Which is just confusing, and FIOCLR will turn it on.
0 Kudos

343 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sat Jan 17 02:00:43 MST 2015

Quote: LukeHill2015
The LED is on, i do not understand why this is as i thought FIODIR just configures the pin.



User manual 10360 is describing this registers:

http://www.nxp.com/documents/user_manual/UM10360.pdf

DIR is just changing the direction, not the level of the pin  :((

Default pin setup (after Reset) is input and pull-up (see PINMODE registers) 

So your input is pulled high and you switch this pin to output -> out / high ->  LED is on.

If you set PINMODE of this pin to pull-down before you change it to output you'll get out / low -> LED is off.

LPC_PINCON->PINMODE0 |= (3 << 12); //pulldown


Note: Peripheral view of debugger is helpful to change this settings and watch the result 

0 Kudos