EmbeddedRelated.com
Forums

controlling P2.9 on lpc2368

Started by ben_fnr October 24, 2007
I have a very wierd problem and wonder if anyone else here has
experienced anything similar.

I am trying to use P2.9 as an output port.

the datasheet has this pin as the following.

P2[9]/ USB_CONNECT/ RXD2/ EXTIN0
In my code I have the following
PINSEL4 &= ~(BIT32_19 | BIT32_18 ); /* P2.9 GPIO pin */
PINMODE4 &= ~(BIT32_19 | BIT32_18 ); /* use pull up resistor */

FIO2MASK = 0;
FIO2DIR |= BIT32_9;
FIO2SET = BIT32_9;

where BIT32_0 = 0x00000001
upto BIT32_31 = 0x80000000

The code is using FreeRTOS and has a 4 tasks. In one task I have the
following

portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();

for(;;)
{

vTaskDelayUntil( &xLastWakeTime, 20 );
FIO2SET = ( BIT32_9 );

vTaskDelayUntil( &xLastWakeTime, 20 );
FIO2CLR = ( BIT32_9 );
}

My problem is that when I run my software (power on reset) I get 2V on
P2.9 and the pin does not toggle.
If I cause a BOD reset while running, the pin operates correctly.

As far as I can see from the datasheet a power on reset and brownout
reset should both be the same.

I can find no explanation in the datasheet or errata, does anyone have
any ideas?

many thanks
Ben

An Engineer's Guide to the LPC2100 Series

Ben,

did you turn on fast I/O access? I don't know if this is neccessary
for the LPC2368 (e.g. for the LPC2148 it *is* neccessay). The earlier
LPCs run the slow GPIO by default, using the fast GPIO has to be
turned on first.

Regards
Herbert

At 11:05 24.10.2007 +0000, you wrote:

>I have a very wierd problem and wonder if anyone else here has
>experienced anything similar.
>
>I am trying to use P2.9 as an output port.
>
>the datasheet has this pin as the following.
>
>P2[9]/ USB_CONNECT/ RXD2/ EXTIN0
>
>In my code I have the following
>
>PINSEL4 &= ~(BIT32_19 | BIT32_18 );/* P2.9 GPIO pin */
>PINMODE4 &= ~(BIT32_19 | BIT32_18 ); /* use pull up resistor */
>
>FIO2MASK = 0;
>FIO2DIR |= BIT32_9;
>FIO2SET = BIT32_9;
>
>where BIT32_0 = 0x00000001
>upto BIT32_31 = 0x80000000
>
>The code is using FreeRTOS and has a 4 tasks. In one task I have the
>following
>
>portTickType xLastWakeTime;
>xLastWakeTime = xTaskGetTickCount();
>
>for(;;)
>{
>
>vTaskDelayUntil( &xLastWakeTime, 20 );
>FIO2SET = ( BIT32_9 );
>
>vTaskDelayUntil( &xLastWakeTime, 20 );
>FIO2CLR = ( BIT32_9 );
>}
>
>My problem is that when I run my software (power on reset) I get 2V on
>P2.9 and the pin does not toggle.
>If I cause a BOD reset while running, the pin operates correctly.
>
>As far as I can see from the datasheet a power on reset and brownout
>reset should both be the same.
>
>I can find no explanation in the datasheet or errata, does anyone have
>any ideas?
>
>many thanks
>Ben
Herbert,

Thanks for your reply. Yes I have enabled fast IO, but that is only
needed for ports 0 & 1.

However I have now fixed the problem. It seems that the ETM module was
enabled, and it configures P2.9 as an input (it uses P2.0 - P2.9).

I still don't know why it behaves differently after a brownout reset,
there is no mention of that in the ETM section of the user manual.
regards
Ben
>
> Ben,
>
> did you turn on fast I/O access? I don't know if this is neccessary
> for the LPC2368 (e.g. for the LPC2148 it *is* neccessay). The earlier
> LPCs run the slow GPIO by default, using the fast GPIO has to be
> turned on first.
>
> Regards
> Herbert
>
> At 11:05 24.10.2007 +0000, you wrote:
>
> >I have a very wierd problem and wonder if anyone else here has
> >experienced anything similar.
> >
> >I am trying to use P2.9 as an output port.
> >
> >the datasheet has this pin as the following.
> >
> >P2[9]/ USB_CONNECT/ RXD2/ EXTIN0
> >
> >In my code I have the following
> >
> >PINSEL4 &= ~(BIT32_19 | BIT32_18 );/* P2.9 GPIO pin */
> >PINMODE4 &= ~(BIT32_19 | BIT32_18 ); /* use pull up resistor */
> >
> >FIO2MASK = 0;
> >FIO2DIR |= BIT32_9;
> >FIO2SET = BIT32_9;
> >
> >where BIT32_0 = 0x00000001
> >upto BIT32_31 = 0x80000000
> >
> >The code is using FreeRTOS and has a 4 tasks. In one task I have the
> >following
> >
> >portTickType xLastWakeTime;
> >xLastWakeTime = xTaskGetTickCount();
> >
> >for(;;)
> >{
> >
> >vTaskDelayUntil( &xLastWakeTime, 20 );
> >FIO2SET = ( BIT32_9 );
> >
> >vTaskDelayUntil( &xLastWakeTime, 20 );
> >FIO2CLR = ( BIT32_9 );
> >}
> >
> >My problem is that when I run my software (power on reset) I get 2V on
> >P2.9 and the pin does not toggle.
> >If I cause a BOD reset while running, the pin operates correctly.
> >
> >As far as I can see from the datasheet a power on reset and brownout
> >reset should both be the same.
> >
> >I can find no explanation in the datasheet or errata, does anyone have
> >any ideas?
> >
> >many thanks
> >Ben
>
Ben,

after sending my mail I had a short look into the LPC2368 manual and
saw by myself, that fast IO is enabled all the time on P2. Sorry for
pointing into the wrong direction.

Do you have a pullup on RCK to disable the ETM? I just had a very
similar problem with the LPC2148: Sometimes port 2 worked after power
up, sometimes not. I had a connection to the corresponding pin (it's
TRACESYNC on this chip) pulling weakly low this pin causing the trace
port being active sometimes. It was rather difficult to find :-( I
now disable the trace port via software at startup in any case to be
on the save side.

Regards
Herbert

At 14:07 24.10.2007 +0000, you wrote:

>Herbert,
>
>Thanks for your reply. Yes I have enabled fast IO, but that is only
>needed for ports 0 & 1.
>
>However I have now fixed the problem. It seems that the ETM module was
>enabled, and it configures P2.9 as an input (it uses P2.0 - P2.9).
>
>I still don't know why it behaves differently after a brownout reset,
>there is no mention of that in the ETM section of the user manual.
>
>regards
>Ben
>
> >
> > Ben,
> >
> > did you turn on fast I/O access? I don't know if this is neccessary
> > for the LPC2368 (e.g. for the LPC2148 it *is* neccessay). The earlier
> > LPCs run the slow GPIO by default, using the fast GPIO has to be
> > turned on first.
> >
> > Regards
> > Herbert
> >
> > At 11:05 24.10.2007 +0000, you wrote:
> >
> > >I have a very wierd problem and wonder if anyone else here has
> > >experienced anything similar.
> > >
> > >I am trying to use P2.9 as an output port.
> > >
> > >the datasheet has this pin as the following.
> > >
> > >P2[9]/ USB_CONNECT/ RXD2/ EXTIN0
> > >
> > >In my code I have the following
> > >
> > >PINSEL4 &= ~(BIT32_19 | BIT32_18 );/* P2.9 GPIO pin */
> > >PINMODE4 &= ~(BIT32_19 | BIT32_18 ); /* use pull up resistor */
> > >
> > >FIO2MASK = 0;
> > >FIO2DIR |= BIT32_9;
> > >FIO2SET = BIT32_9;
> > >
> > >where BIT32_0 = 0x00000001
> > >upto BIT32_31 = 0x80000000
> > >
> > >The code is using FreeRTOS and has a 4 tasks. In one task I have the
> > >following
> > >
> > >portTickType xLastWakeTime;
> > >xLastWakeTime = xTaskGetTickCount();
> > >
> > >for(;;)
> > >{
> > >
> > >vTaskDelayUntil( &xLastWakeTime, 20 );
> > >FIO2SET = ( BIT32_9 );
> > >
> > >vTaskDelayUntil( &xLastWakeTime, 20 );
> > >FIO2CLR = ( BIT32_9 );
> > >}
> > >
> > >My problem is that when I run my software (power on reset) I get 2V on
> > >P2.9 and the pin does not toggle.
> > >If I cause a BOD reset while running, the pin operates correctly.
> > >
> > >As far as I can see from the datasheet a power on reset and brownout
> > >reset should both be the same.
> > >
> > >I can find no explanation in the datasheet or errata, does anyone have
> > >any ideas?
> > >
> > >many thanks
> > >Ben
> >
Herbert,

Actually RCK is pulled low on the board which of course causes the
problem. I didn't design the board, but I think the JTAG pin is one of
the ones that is supposed to be pulled low.

Still dont understand why the brownout reset disables it.

I am now disabling the ETM.

I probably would have caught it sooner, but the footnote in the PINSEL
register section was only in the column for the third function, so I
just assumed it wasn't relative as I wanted to use the pin as GPIO.

regards
Ben
>
> Ben,
>
> after sending my mail I had a short look into the LPC2368 manual and
> saw by myself, that fast IO is enabled all the time on P2. Sorry for
> pointing into the wrong direction.
>
> Do you have a pullup on RCK to disable the ETM? I just had a very
> similar problem with the LPC2148: Sometimes port 2 worked after power
> up, sometimes not. I had a connection to the corresponding pin (it's
> TRACESYNC on this chip) pulling weakly low this pin causing the trace
> port being active sometimes. It was rather difficult to find :-( I
> now disable the trace port via software at startup in any case to be
> on the save side.
>
> Regards
> Herbert
>
> At 14:07 24.10.2007 +0000, you wrote:
>
> >Herbert,
> >
> >Thanks for your reply. Yes I have enabled fast IO, but that is only
> >needed for ports 0 & 1.
> >
> >However I have now fixed the problem. It seems that the ETM module was
> >enabled, and it configures P2.9 as an input (it uses P2.0 - P2.9).
> >
> >I still don't know why it behaves differently after a brownout reset,
> >there is no mention of that in the ETM section of the user manual.
> >
> >regards
> >Ben
> >
> > >
> > > Ben,
> > >
> > > did you turn on fast I/O access? I don't know if this is neccessary
> > > for the LPC2368 (e.g. for the LPC2148 it *is* neccessay). The
earlier
> > > LPCs run the slow GPIO by default, using the fast GPIO has to be
> > > turned on first.
> > >
> > > Regards
> > > Herbert
> > >
> > > At 11:05 24.10.2007 +0000, you wrote:
> > >
> > > >I have a very wierd problem and wonder if anyone else here has
> > > >experienced anything similar.
> > > >
> > > >I am trying to use P2.9 as an output port.
> > > >
> > > >the datasheet has this pin as the following.
> > > >
> > > >P2[9]/ USB_CONNECT/ RXD2/ EXTIN0
> > > >
> > > >In my code I have the following
> > > >
> > > >PINSEL4 &= ~(BIT32_19 | BIT32_18 );/* P2.9 GPIO pin */
> > > >PINMODE4 &= ~(BIT32_19 | BIT32_18 ); /* use pull up resistor */
> > > >
> > > >FIO2MASK = 0;
> > > >FIO2DIR |= BIT32_9;
> > > >FIO2SET = BIT32_9;
> > > >
> > > >where BIT32_0 = 0x00000001
> > > >upto BIT32_31 = 0x80000000
> > > >
> > > >The code is using FreeRTOS and has a 4 tasks. In one task I
have the
> > > >following
> > > >
> > > >portTickType xLastWakeTime;
> > > >xLastWakeTime = xTaskGetTickCount();
> > > >
> > > >for(;;)
> > > >{
> > > >
> > > >vTaskDelayUntil( &xLastWakeTime, 20 );
> > > >FIO2SET = ( BIT32_9 );
> > > >
> > > >vTaskDelayUntil( &xLastWakeTime, 20 );
> > > >FIO2CLR = ( BIT32_9 );
> > > >}
> > > >
> > > >My problem is that when I run my software (power on reset) I
get 2V on
> > > >P2.9 and the pin does not toggle.
> > > >If I cause a BOD reset while running, the pin operates correctly.
> > > >
> > > >As far as I can see from the datasheet a power on reset and
brownout
> > > >reset should both be the same.
> > > >
> > > >I can find no explanation in the datasheet or errata, does
anyone have
> > > >any ideas?
> > > >
> > > >many thanks
> > > >Ben
> > >
> >
> >
>
>