Configuring port to input and output in LPC845

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

Configuring port to input and output in LPC845

2,589 Views
vidhya1
Contributor III

Hi all,

I need to configure port pins high and low for particular port pins,

please let me know the below procedure is correct:

#define DATA_BUS                                   LPC_GPIO_PORT->DIRSET0
#define CONTROL_BUS                          LPC_GPIO_PORT->DIRSET1

Below is the part of the code to toggle led for example P0_12 [PORT 0, 12th pin]

        if(count<800000)//
        {  
        LPC_GPIO_PORT->DIRSET0= 1<<(LED_RED);
        LPC_GPIO_PORT->CLR0 = 1<<(LED_RED);  
        }
        
        if(count>800000&&count<1600000)
        {
        LPC_GPIO_PORT->DIRSET0= 1<<(LED_RED);

        LPC_GPIO_PORT->CLR0= 1<<(LED_RED);
        }
        if(count>1600000&&count<2000000)
        {
        LPC_GPIO_PORT->DIRSET0= 1<<(LED_RED);

        LPC_GPIO_PORT->SET0= 1<<(LED_RED);
        }

I need to know is there any other way to set the port pin to input and output[high/low] using other

peripheral gpio pins?

The problem is I need to 2 ports which I should configure to input and output, and direct those pins to

data pins[D4-D7], and control pins[RS, RW, EN] to interface the LCD.

Please suggest.

Labels (1)
Tags (1)
0 Kudos
12 Replies

2,168 Views
ianbenton
Senior Contributor I

Most of the LCDs have a pseudo-bidirectional bus, an N-channel FET to drive it low and a constant current source at the top. You can therefore save a lot of code by setting the BUS pins to open-drain. Then you don't have to bother with the DIR register, just write 1s to the pins when they are inputs. 

The later OLEDs have a proper push-pull driver, but you can achieve the same thing by adding pull-up resistors (about 3.3k seems to work). Unfortunately, the built-in pullups are too high a value making the interface too slow.

Also, note that the new OLEDs won't work from the 3.3V output of the LPC845- you need to level shift to 5V to achieve a HI input (but the open-drain and pull-up technique deals with this). You will still have to buffer RW, R and E to get a 5V signal, but it's output only, so a simple 74HCT04 does the job.

0 Kudos

2,168 Views
vidhya1
Contributor III

Thank you for the response.

Presently now I'm using LCD display, and configured the gpio pins in the

following way:

#define DATA_BUS LPC_GPIO_PORT->DIRSET0

#define CONTROL_BUS LPC_GPIO_PORT->DIRSET0

#define CONTROL_SET LPC_GPIO_PORT->SET0

#define CONTROL_CLEAR LPC_GPIO_PORT->CLR0

#define DATA_SET LPC_GPIO_PORT->SET0

#define DATA_CLEAR LPC_GPIO_PORT->CLR0

Will apply and work on the points you suggested.

Thank you

0 Kudos

2,168 Views
ianbenton
Senior Contributor I

Just a further thought. If it turns out you need a level-shifting buffer (74LVC245) to get D0-D7 from 3.3V to 5V, then how about this solution. . .

Use a 74HCT595 instead, and connect it to an SPI port. You need a lot fewer connections to the processor, and they don't have to run in order.

I'll supply further details if you want.

0 Kudos

2,168 Views
vidhya1
Contributor III

Since the display I'm using won't support SPI or I2C interface, I'm

doing parallel interfacing of 8x2 lcd, if you come across supporting

driver files[lcd.c &lcd.h] files for LPC845M301JBD64 or any equivalent

MCU for lpc845, kindly provide.

Thank you

0 Kudos

2,168 Views
ianbenton
Senior Contributor I

The 74HCT595 converts serial to parallel, so you can connect a parallel display to the SPI port.

0 Kudos

2,168 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

You need initialize SYSAHBCLKCTRL to enable GPIO clock.

You need also config SWM to make sure the fixed pin is disabled and the pin is used as GPIO.

after above initialization, you can set pin direction and value as you did.


Have a great day,
Jun Zhang

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,168 Views
vidhya1
Contributor III

Thank you for the response.

Yes initialized SYSAHBCLKCTRL register, but not sure how to configure

SWM to make the pin as GPIO, referred user manual of LPC845, in that

page 131, Table.179, since they have given movable functions,

Is there any tool for switch matrix? Since i'm using keil ide 5.26

Or only need to configure the pin like SYSAHBCLKCTRL register?

Kindly advice

Thank you

0 Kudos

2,168 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi ,

SYSAHBCLKCTRL is to enable/disable model clock.

For LPC845, By default,the GPIO function is selected except on pins PIO0_2, PIO0_3, and PIO0_5. See datasheet 7.2 Pin description. So most of the pins are GPIO feature by default.

For Pin config tool, please see below url:

MCUXpresso Config Tools|Software Development for NXP Microcontrollers (MCUs) | NXP 


Have a great day,
Jun Zhang

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,168 Views
vidhya1
Contributor III

Good Day Sir!!

As I'm using keil u vision IDE for LCP845 MCU, is there any link

to check for pin config tool, since MCUXpresso IDE is very new

for me and takes much time to understand.

And is there any sample code for movable function ,

so that will try to understand how to configure movable pins first,

and I have attached the sample codes for keil which i'm referring for

DAC, timers and other peripherals, so is this sample codes correct for

referring.

Thank you

0 Kudos

2,168 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

As I answered in my previous email, Pin Config tool can be download from this url:

MCUXpresso Config Tools|Software Development for NXP Microcontrollers (MCUs) | NXP 

Here is the document

https://www.nxp.com/docs/en/user-guide/GSMCUXCTUG.pdf 

See Chapter 3, Pin Tool.

If you have more question about Config Tool, as this is another topic, please create a new question here

MCUXpresso Config Tools 

Your other question about DAC project, as this is another topic, please create a new thread for this.

Let's keep one thread for one topic. Thanks for your understanding.


Have a great day,
Jun Zhang

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,168 Views
vidhya1
Contributor III

Ok sir, thank you so much, will go through the document,

and will create a separate thread for the peripherals

as you suggested.

Thank you

0 Kudos

2,168 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Fine. I also appreciate your understanding.


Have a great day,
Jun Zhang

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos