Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

PINSEL Queries

PINSEL Queries

2006-05-31 by suyash

Hi all,

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.

2) suppose I want to use a single pin as multipurpose functioning, so 
how do I have to take care of PINSELn.
will it be always overwritten everytime or else we need to mask it 
and then modify it(for retaining its previous status).

Re: [lpc2000] PINSEL Queries

2006-05-31 by Xtian Xultz

Em Qua 31 Mai 2006 09:43, suyash escreveu:
> Hi all,
>
> 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.

You can reconfigure anytime. For example, I first define all the pins as 
GPIOs, then next I define the GPIO that will be outputs. Then, in the routine 
that configures the UARTs, I change the pins from GPIOs to UART. But you can 
do it all in one time...

> 2) suppose I want to use a single pin as multipurpose functioning, so
> how do I have to take care of PINSELn.
> will it be always overwritten everytime or else we need to mask it
> and then modify it(for retaining its previous status).

All time you write a 32 bits word in the PINSELs, they will change, so you 
have to mask them.

Re: PINSEL Queries

2006-05-31 by rtstofer

--- In lpc2000@yahoogroups.com, "suyash" <suyash_shembekar@...> wrote:
>
> Hi all,
> 
> 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.

> 
> 2) suppose I want to use a single pin as multipurpose functioning, so 
> how do I have to take care of PINSELn.
> will it be always overwritten everytime or else we need to mask it 
> and then modify it(for retaining its previous status).

Again, it's a choice!  You can modify a pin and leave it changed
assuming any other function using the pin will change it as required.
 Or, you can change it back to the way you found it.  There are
certainly arguments for both.  Either approach gets hairy if the pin
is changed inside interrupt handlers...

I don't have any code where this occurs - at least on ARM.  I just
wrote some code for the AVR where I spent a lot of time tri-stating a
bidirectional data bus and in this case, every function left the bus
floating.  That was required because the external DRAM that was
connected to the bus was also the frame buffer for the LCD display.

So, I don't think there are rules.  Put all the initialization in one
place versus initialize in the same file where the device is used. 
Either way...  Just get it done before you use the pin.

Unless, of course, there is something connected to the pin that needs
to be in a particular state quickly.  In this case, you can put the
code in crt.s and that's about as fast as you can get.

Richard

Re: [lpc2000] PINSEL Queries

2006-05-31 by Tom Walsh

suyash wrote:

>Hi all,
>
>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.
>
>2) suppose I want to use a single pin as multipurpose functioning, so 
>how do I have to take care of PINSELn.
>will it be always overwritten everytime or else we need to mask it 
>and then modify it(for retaining its previous status).
>
>  
>
As the others have said, your choice.

I am driving a buzzer with the PWM5, and the buzzer circuit requires 
that PWM5 to be low (0 volts) when not in use.  So, I initially program 
PWM5 as an output pin with IODIR, set it with IOCLR.  Next, I program 
the PWM0 for my frequency, and I toggle the P0.21 function bit in the 
PINSEL1 between GPIO and PWM5.

TomW


-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------

Re: [lpc2000] Re: PINSEL Queries

2006-05-31 by Karl Olsen

---- Original Message ----
Show quoted textHide quoted text
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 Olsen

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.