Set / Clear IO bit in LPCOpen (very-very beginner)

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

Set / Clear IO bit in LPCOpen (very-very beginner)

414 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Bela on Wed Nov 05 08:02:50 MST 2014
Gentlemen,

I'm new to Cortex M3, also to LPCXpresso, and to LPCOpen and even to C language. But I do have a motivation to learn it all :-)

I use LPCXpresso 7.3.0 on Ubuntu 14.04.
An LPCXpresso 1768 board is connected.
I can open an existing example-project, in my case it is a blinky example, it compiles and can be downloaded to the board. Since it just blinks, there's nothing to do with.
It took me a while, while I could recognize that CMSIS, mbed and LPCOpen are different things and shouldn't be mixed up :-) I decided to try to use LPCOpen.

My next step is to write my own code for something similar.
There's an LED on P0.22, I want to control it's brightness up and down slowly, employing PWM principle.
To do this, I could use Timer0 and one (or two) of the match registers. They could procuce an internal PWM and I could control the P0.22 in software, because this pin cannot be controlled directly by the built-in PWM hardware. The PWM rate would be changed by SysTick IT, one step in every 10 msec by incrementing / decrementing the value in Timer0/match0 register. Match0 could provide the duty cycle, Match1 the PWM period and it also resets Timer0. That's my idea.

Here are the problems coming in.

1.:   There's only one IT vector for Timer0. How can my code detect if this IT is due to one of the match registers? Both should have it's IT enabled.

2.:   I couldn't find out how could I write a value into Timer0/Match0 and Match1 register?
       LPCXpresso gives proposals to some registers, for example like this: LPC_SYSCTL->PCONP Here PCONP comes up automatically as I enter LPC_SYSCTL-> .
       But if I try LPC_TIMER0-> here just MR is valid. In the user manual I see 4 match registers for each of the timers, not only one. I don't understand, how could I access one out of the 4.

3.:  How could I set and/or clear the P0.22 bit? When I try LPC_GPIO_T-> no proposal comes, and whatever I try to finish this instruction, it doesn't compile, saying:
../src/Proba03.c:101:12: error: expected identifier or '(' before '->' token
  LPC_GPIO_T->CLR0 = (1<<22);    // LED1 output low (On)
                           ^
Similarly, I couldn't acces the IO control bits, because LPC_IOCON_T->  doesn't compile and doesn't give proposals.

4.:  Is there a verbosely written documentation of LPCOpen? I do have this HTML docu: http://www.lpcware.com/system/files/lpcopen_2_10_docs_17xx_40xx.zip but it is not written for beginners.

It is so inconvenient sitting in the darkness, could someone help me, please?
Labels (1)
0 Kudos
3 Replies

342 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ano on Wed Nov 19 04:45:35 MST 2014
In LPC Open there should be some functions for this cases.
Setting a Pin: Chip_GPIO_SetPinSate(LPC_GPIO; Portnumber; Portpin, state);
or state being true or false. There is also a fuction to toggle the pin.
Before you can use this command, you need to set the GPIO to output:
It is called Chip_GPIO_SetDirection or something like that.

For the Matchtimer use: Chip_Timer_SetMatch(X,X,X); There you can enter
your desired matchvalue. Write it like that: "Chip_GetSystemClock / Y" with Y
being the frequency you want to aquire.
(to understand the match values needed, read this: Thread)
0 Kudos

342 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Fri Nov 07 01:42:26 MST 2014

Quote: Bela
1.:   There's only one IT vector for Timer0. How can my code detect if this IT is due to one of the match registers?

Look at the bits in T0IR.


Quote: Bela
2.:   I couldn't find out how could I write a value into Timer0/Match0 and Match1 register? [...] But if I try LPC_TIMER0-> here just MR is valid. In the user manual I see 4 match registers for each of the timers, not only one. I don't understand, how could I access one out of the 4.

Typically this would be an array, i.e. use LPC_TIMER0->MR[0] (I havent't checked, though).


Quote: Bela
3.:  How could I set and/or clear the P0.22 bit?


In general, read the .h file defining these things, and figure out how it relates to the register description in the user manual.
0 Kudos

342 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Bela on Thu Nov 06 10:42:48 MST 2014
Maybe I have to include more header files?
How to do that and how can I find out what headers are available and which one I need?
0 Kudos