---- Original Message ----
From: "rtstofer" <rstofer@...>
To: <lpc2000@yahoogroups.com>
Sent: Wednesday, May 31, 2006 3:24 PM
Subject: [lpc2000] Re: PINSEL Queries
> --- In lpc2000@yahoogroups.com, "suyash" <suyash_shembekar@...> wrote:
>>
>> I am using ARM LPC2106, I have following doubts about the
>> configuration of PINSEL0 and PINSEL1.
>>
>> 1)where exactly should I define it in the initialsation?
>> In common system initialisation or at the eac and every periphral
>> (ex. UART0 or SPI etc.) initialisation.
>
> It's your choice! I do most of the initialization in just one place
> in a function I call from main(). But, I don't think I like this
> approach. Next time I will set the USART pins in an initialization
> routine in the serial IO file. Same for SPI, I2C, etc.
Writing some big magical values to PIN->SEL0 and PIN->SEL1 in the beginning
of main() is possible but not very service friendly imho.
Instead I set both PIN->SELx to 0 in main() and let the various subsystems
modify "their" bits. I have a #define for each pin, and a macro for setting
PIN->SELx bits. The SET_PINSEL_P0() macro changes the pin function from 0
to 1, 2 or 3 by ORing the appropriate bits to the appropriate PIN->SELx
register.
#define P0_TXD0 (1u<<0)
#define P0_RXD0 (1u<<1)
#define P0_OUT4 (1u<<4)
#define P0_PWM (1u<<7)
...
#define SET_PINSEL_P0(p0bit,func) (((p0bit) <= 0x00008000) ? \
(PIN->SEL0 |= (p0bit)*(p0bit)*(func)) : \
(PIN->SEL1 |= ((p0bit)>>16) * ((p0bit)>>16) * (func)))
Then in each subsystem I can configure the pins like this:
void UartInit (void)
{
SET_PINSEL_P0 (P0_TXD0, 1); /* TxD0, not GPIO */
SET_PINSEL_P0 (P0_RXD0, 1); /* RxD0, not GPIO */
...
}
void PwmInit (void)
{
SET_PINSEL_P0 (P0_PWM, 2); /* PWM2, not GPIO */
...
}
void OutputInit (void)
{
IO->DIR0 |= P0_OUT4; /* GPIO out, not GPIO in */
IO->SET0 = P0_OUT4; /* Initially high, not low */
...
}
Karl OlsenMessage
Re: [lpc2000] Re: PINSEL Queries
2006-05-31 by Karl Olsen
Attachments
- No local attachments were found for this message.