GPIO manipulation

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

GPIO manipulation

1,382 Views
eman_koosha
Contributor II

HI 

i am a newbie to NXP micros 

i am using the LPC54xx

i want to output data on a set of pins. i will address each pin on its own becuase they are spread around

i am finding it very difficult to understand how GPIOs are manipulated.

i am setting them as output on the pin configuration tools and its being initialized by the generated code.

i want to start putting 1s and 0s on the pins

Are the below the correct functions to use:

1. GPIO_PortClear ( , , ) to put 0 on the port

for the pin i am using named enbale "E"

GPIO_PortClear (E_PIN_GPIO,E_PIN_PORT,1<< E_PIN_PIN);

2. GPIO_PortSet( , , ) to put 1 on the port

for the pin i am usinf named enbale "E"

GPIO_PortSet (E_PIN_GPIO,E_PIN_PORT,1<< E_PIN_PIN);

3. GPIO_PortMaskedSet( , , ) to write "0" or "1" 

GPIO_PortMaskedSet (E_PIN_GPIO,E_PIN_PORT,1<<(val&(1<<7))!=0);

please let me know if i am on the right track

Thanks

Eman

9 Replies

1,173 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Eman,

You have the right idea of how to write zeroes and ones to the pins. Though you have to consider some other factors as well.

Firstly make sure that you have initialized the clock of the port you will be using. 

You also should initialize the port and specific pin incase you use different pins as either inputs or outputs

Once this is done you may be able to write one or zero to that pin.

Can you confirm if you are using MCUXpresso and the complete part number of your LPC54. This way I can provide the correct examples you can try with your microcontroller.

Best Regards,

Sabina

1,173 Views
eman_koosha
Contributor II

Hi Sabina

 thanks for your reply

i am using  LPC54618J512BD208 and MCUXpresso 

I did go through the pin configurator and had the code generated through there. can i assume all the OK (initialized) or are there any further steps needed. i did see the init code that enables the clock in that generated code i also think i see the pin initialization 

examples would be great

thanks

0 Kudos

1,173 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Eman,

In order to check the examples for all peripheral that you can work with uing your LPC board. You need to download the SDK in our MCUXPresso SDK Website. If you are using the LPCXpresso54618 board then you can find it by clicking on "Select Development Board".

pastedImage_1.png

You will see the page come to this section, you can search for the microcontroller you are using or the development board you are using. In my case I have the LPCXpresso54618, so I search that.pastedImage_3.png

If you have a different board or a custom board you can search by the microcontroller name only.

Once you have selected your board you will see a button on the right hand side that says "Build MCUXpresso SDK". Next you will have your SDK builder, for the optional middleware I suggest to select all.pastedImage_7.png

Then press download.

Once downloaded you can drag this zip folder to the Installed SDKs window, as shown below:

pastedImage_9.png

Next to view the examples you can click on "Import SDK examples" in the Quickstart Panel.

Here you will find all the examples that have been created for different purposes. The one I recommend you take a look to see how GPIO works are the following under driver_examples > gpio:

pastedImage_17.png

This uses both led and switches. 

If you use the pin configuration tool then all the changes including initialization are done automatically.

For detailed information about the registers and pins for the GPIO. You can check chapter 13 of the user manual.

Once you try the example and the different configurations, let me know if you have any toher questions regarding the functionality of the GPIO pins.

Best Regards,

Sabina

0 Kudos

1,173 Views
eman_koosha
Contributor II

Hi Sabina

I am using this example actually.

i tried to follow in its footsteps but i am not successful yet

will do some reading and see how it goes

thanks

Eman 

0 Kudos

1,173 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hi Eman,

If you can share your project please attach it to this post and I can check it with detail.

Best Regards,

Sabina

0 Kudos

1,173 Views
eman_koosha
Contributor II

HI Sabina

attached is the code

thanks

Eman

0 Kudos

1,173 Views
Sabina_Bruce
NXP Employee
NXP Employee

Hello Eman,

I've been checking your code with detail to see how you are implementing the GPIO peripheral. I can see that the switch and led work fine as it is from the example in the SDK.

I can also see that you are using an LCD display to print some text. I have some observations that may help in successfully using GPIO for your LCD.

First I'd like to understand what it is your achieving with the following toggles. The reason I am asking is because prior to this I do not see if you are initializing this with a set value, like the led is in the SDK example. So if you apply a toggle to an unknown state pin you might not be seeing what you are expecting.

pastedImage_1.png

In general I can see you have an idea of what you need to do. It is just a matter of debugging to find where the root issue is that is preventing you from seeing the results.

If you can provide the LCD display that you are using (the part number). This way I can verify the sequence to write a character it will help me understand what you are trying to achieve. 

Please let me know as soon as you can so I can continue to support you.

Best Regards,

Sabina

0 Kudos

1,173 Views
gbarcan
Contributor II
0 Kudos

1,173 Views
Sabina_Bruce
NXP Employee
NXP Employee

Thank you for providing the info. We have received your internal case as well. We can continue the support there for other questions. 

Best Regards,

Sabina

0 Kudos