Reading GPIO stops program execution?

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

Reading GPIO stops program execution?

563 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fpg on Mon Mar 07 11:56:02 MST 2011
First of all I'm sorry if the solution to my problem is already mentioned somewhere, but I have no idea where to search for it...

I use LPCXpresso LPC1769 with the Embedded Artists LPCXPresso Baseboard. There is a project handed with the baseboard called disp7seg-rotary. It runs perfectly.

But when I try to use the functions of the rotary encoder, program execution stops after a few times of executing rotary_read function. By placing a breakpoint I found the very line, where it stops working:

uint8_t state = ROTARY_READ_STATE();

On the right there is a macro, it's just reading in the values of GPIO Port 0:
#define ROTARY_READ_STATE() ((GPIO_ReadValue(0) >> 24) & 0x03)

If this is coming next and I try to step over, debugging icons become inactive except stop and pause. If I just let it run, it reads the values for a while after that it simply stops running.

Anyone got any idea, what am I missing... ? :eek: :confused:
0 Kudos
Reply
2 Replies

535 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Mar 08 02:10:52 MST 2011
Try "stepping in" rather than "stepping over". I've not looked at this specific example, but I imagine that program execution is stuck in a loop inside the [FONT=Courier New][SIZE=1]GPIO_ReadValue(0)[/SIZE][/FONT]function that the macro invokes.

Regards,
CodeRedSupport
0 Kudos
Reply

535 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by william.vh on Mon Mar 07 13:42:55 MST 2011

Quote: fpg

On the right there is a macro, it's just reading in the values of GPIO Port 0:
#define ROTARY_READ_STATE() ((GPIO_ReadValue(0) >> 24) & 0x03)

Anyone got any idea, what am I missing... ? :eek: :confused:



I've not looked at the code carefully, but GPIO_ReadValue(0) is also a macro, and I suspect that in that macro there is a line something like while(!data_ready){} that holds execution until the ADC sets a flag saying the data is ready.

If you find your self at that line and ADC isn't running, you'll get stuck.

I ran into a problem on the LPC2148 ADC where the ADC would have that bit cleared (or not properly set) and I would get stuck. I got around it by clearing the ADC by doing a dummy read (calling for conversion but not check in the data_ready bit). Fixed my problem, even though I never really understood why that bit would get cleared prior to reading.

These days I use a counter in the while(!data_ready){} loop and if too much time has passed, I restart the ADC process to get me back in business.
0 Kudos
Reply