gpioGetValue

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

gpioGetValue

1,683 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Mon Apr 05 19:55:57 MST 2010
Is there a routine like
gpioGetValue  to get a ports value?

Please and thank you.
0 Kudos
Reply
13 Replies

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Apr 07 01:05:34 MST 2010
Hi,

Glad to hear that you are now up and running with the GPIOReadValue() function, and have found where to disable the warning messages.

With regards to the names of your files after copying/renaming your project, you need to change the "Build Artifact" setting for each build configuration of your "new" project. To do this:

[LIST=1]
[*]Go to[FONT=Times New Roman] Project Properties -> C/C++ Build ->  Settings[/FONT]
[*][FONT=Times New Roman]Select the Build Artifact tab[/FONT]
[*][FONT=Times New Roman]Change the Artifact name to match your new project name[/FONT]
[*][FONT=Times New Roman]Repeat this for your other build configurations (typically Debug and Release).[/FONT]
[/LIST]
[FONT=Times New Roman]Once you are happy everything is working, you can delete the files with filenames based on the old artifact name.

Regards
CodeRedSupport
[/FONT]
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 16:57:07 MST 2010
It seems to be ok now. I found where to undo the warnings checkbox in the project properties. It still had the original error so I cut and pasted my main file into the blinky project and it ran ok this time.

Thanks for your help.

David
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 14:57:59 MST 2010
that Wall might work but I am not an expert. All I have is a Build button to push. How do I work the options into that please?
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 13:36:29 MST 2010
Thanks. I will check that. I just noticed that under the debug folder in my project, is a bunch of files that still have the name blinky in them. Probably because I originally started with the blinky project. Is there some way to regenerate these or are they ok as they are?
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Apr 06 11:24:24 MST 2010
[FONT=Times New Roman]By default, LPCXpresso projects build with the -Wall option, which enables most of the compiler's warning messages. The message you are seeing here is a result of this. For more information on -Wall, please see:

http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

In particular, read the part on the the [/FONT][FONT=Times New Roman]-Wchar-subscripts option.

You can turn off the use of -Wall using

Project Properties -> C/C++ Build -> Settings -> MCU C Compiler -> Warnings

I would imagine that the reason you did not see this with the Rowley tools is because they do not enable -Wall by default.

I doubt that this has anything to do with why you cannot get GPIOReadValue() to compile, but if you remove these warnings it is possible that you will spot another warning/error which will point you to the cause.

Regards,
CodeRedSupport
[/FONT]
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 10:14:42 MST 2010
The only other difference I see so far is the faulty program also has another warning
in this function. The 2 lines that starts with the "if" produce an "warning: array subscript has a type 'char'. "

This ran ok under Rowley compiler.  The array is declared as:

char send_toggle[8][4];
char receive_toggle[8][4];

void save_receive_toggles(char addrs,char endpoint)
{
char b;
  b = Hrreg(rHRSL);  
  if (b & bmRCVTOGRD)   receive_toggle[addrs][endpoint] = bmRCVTOG1;
          else receive_toggle[addrs][endpoint] = bmRCVTOG0;
}

Getting this warning is actually producing 50 warnings because it is used in 50 places.
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Apr 06 09:33:52 MST 2010
So you have proved that the example GPIOReadValue function does work for you in one test program. As it doesn't work in the your other test program, then I suggest you start off comparing the two source files containing the call to GPIOReadValue() and try to spot the difference.

You really need to post a compilable source file that shows up the error message for us to provide additional assistance.

Regards,
CodeRedSupport.
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 09:16:33 MST 2010
I just took the same code snippets from my program and cut and pasted to the blinky program and they work ok in that program and not in mine.  I originally added my code to the blinky program and then renamed it as a way of starting a new project. Later I imported the blinky program to restore it .  Any suggestions are welcome.
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 08:57:03 MST 2010
uint32_t a ;

a = GPIOReadValue (3,0);

the routine I added to gpio.h was cut and pasted from the forum.

the compiler build id is 2010-01-22(v3.2.2)
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Apr 06 08:14:01 MST 2010
Getting the error "error: expected expression before 'return'" is rather strange. It sounds like the compiler is for some reason rejecting the line before the return statement. Are you using the code exactly as in my previous post?

And how are you calling GPIOReadValue? In my test code (based on the standard blinky example), I effectively do the following....

uint32_t state;

state = GPIOReadValue(LED_PORT, LED_BIT);


Regards
CodeRedSupport
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mayotte1 on Tue Apr 06 07:48:52 MST 2010
I tried these and they both return the same "error: expected expression before 'return'"

this happens even if I replace the middle line with val = 1;.

I am operating without much sleep these days so maybe I don't see some simple error?
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wrighflyer on Tue Apr 06 03:21:44 MST 2010
Isn't the (val >> BitPosi), shifting a uint32_t, in that a bit "expensive" if it may be done every time an input is read? I guess one would need to look at the generated code in each case but would:
 
return (val ? 1 : 0);

possibly be better?

(admittedly I don't know this CPU core that well - maybe it has a barellel shifter and an arbitrary shift can be acomplished in a single cycle?)
0 Kudos
Reply

1,578 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Apr 06 02:36:49 MST 2010
The GPIO examples provided for LPCXpresso only provide a GPIOSetValue() function [as an inlineable function in gpio.h), not a GPIOReadValue() function.

The following is a simple implementation of GPIOReadValue(), based on GPIOSetValue(), which will read the state of a single gpio pin. It will return 1 if the pin is high, else 0.

static __INLINE uint32_t GPIOReadValue( uint32_t portNum, uint32_t bitPosi)
{
    uint32_t val;
    val = LPC_GPIO[portNum]->MASKED_ACCESS[(1<<bitPosi)];
    return (val >> bitPosi);
}


Place this into gpio.h, and then include this header in your source files.

Note that the LPC11/13 GPIO pins can act as interrupt sources - you might want to consider using them in this ways, rather than directly reading them.

Regards,
CodeRedSupport
0 Kudos
Reply