LPC1114 pin direction

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

LPC1114 pin direction

1,118 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Fri Jun 03 09:29:04 MST 2011
Hi All,

             I am using LPC1114 in my project. In my project, I am using PIO2_7 pin as an digital output and also as digital input. I need to periodically change the pin direction to input, read the value and then change it back to output.

/*
**    Make pin 2_7 an  input
*/ 
GIO_set_direction_for_pin_2_7(LOGIC_0);
delay_for_pin_dir();    // delay before reading

busy_status    = GIO_get_pin_2_7();    // [B]read the pin[/B]

/*
**    Make pin 2_7 an output as busy status has been checked.
*/ 
GIO_set_direction_for_pin_2_7(LOGIC_1);
delay_for_pin_dir(); 

Can anyone please let me know if the above method is correct or are there any other precautions that need to be taken when changing the [B]pin direction from output to input[/B] ?

[B]void
GIO_set_direction_for[/B]_[B]pin_2_7[/B][B](
    bool direction
) [/B]{
    if(direction) {
        LPC_IOCON->PIO2_7 = 0x00;
       
        /*
        **    Output
        */
        LPC_GPIO2->DIR    |= 1 << HDW_OP_LCD_DB7_BIT;
    }
    else {
       /*
        **    Input
        */
        LPC_GPIO2->DIR &= ~(1 << HDW_OP_LCD_DB7_BIT);

    }
}
0 Kudos
Reply
3 Replies

1,087 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jun 03 14:19:08 MST 2011
The answer is low and low (no pullups set and nothing connected)  :)

You can test this very fast if you start your debugger and change values for DIR / DATA in Peripherals view -> GPIO and scope / measure the pin meanwhile.
0 Kudos
Reply

1,087 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mohsin on Fri Jun 03 13:45:11 MST 2011
Thanks for yor reply. I was wondering what would happen in the following situations

1) If the pin direction is [B]output [/B]and is set to[B] High[/B]. Now if we change the direction to input ?

2) If the pin direction is [B]output [/B]and is set to [B]Low[/B]. Now if we change the direction to input ?

Does the pin get updated correctly and also do we require any delay ?

Regards,
Mohsin
0 Kudos
Reply

1,087 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jun 03 10:17:32 MST 2011
I would suggest to move

LPC_IOCON->PIO2_7 = 0x00;
somewhere in your init section. It's not necessary to select PIO2_7 function every time you change direction. Reset value is also 0x00, so this line should not be necessary.

Also I would suggest to use brackets in ([COLOR=Blue]blue is new[/COLOR])

LPC_GPIO2->DIR |=[COLOR=Blue] ([/COLOR]1 << HDW_OP_LCD_DB7_BIT[COLOR=Blue])[/COLOR];
Otherwise I can't see anything wrong in your code
0 Kudos
Reply