EmbeddedRelated.com
Forums

Interference problems on Port 1 of LPC2148

Started by capiman26061973 November 24, 2007
Hello,

i currently tring to understand a problem, which almost drives me
crazy. I hunt for it for a few hours now, just a simple code. I try
to implement a soft uart, 9600 baud, 8N1, only sending via a timer
routine.

Processor is LPC2148 (i have a 'A' revision and a not 'A' revision,
same results). 12 MHz oscillator. MAMTIM = 0x3; MAMCR = 0x2; SCS = 3;
USB in use. gcc was 3.x, now 4.1.1
PLLCFG = 0x24; so i get 60 MHz. Embedded Artists Board and also on
self developed board. No resistor to P1.26 and P1.20, just open, to
get debug ports disabled.

Some additional info, what i am using:

static void Interruptroutine_Timer1(void) __attribute__ ((interrupt
("IRQ")));
static void Interruptroutine_Timer1(void)
{
...removed, see later...

T1IR = 1; /* Clear interrupt flag */
VICVectAddr = 0; /* Acknowledge Interrupt */
}

VICIntSelect &= ~(1<<5); // select IRQ for
Timer1
VICIntEnable |= (1<<5);
T1MR0 = (60000000 / 9600); // Timer 9600 Hz
T1MCR = 3; // Interrupt and
Reset on MR0
T1TCR = 1; // Enable Timer
VICVectAddr1 = (unsigned long)Interruptroutine_Timer1;
VICVectCntl1 = 0x20 | 5;

enableIRQ();
I have a timer routine (Timer 1, 9600 Hz) and a endless while loop in
main. The timer routines access some pins (on port 0 and port 1 of
LPC2148 (no JTAG or other debugging tool connected !)). I am
currently using

FIOCLR1 = (1 << TESTPUNKT_P1_18);
FIOCLR1 = (1 << TESTPUNKT_P1_21);
FIOCLR0 = (1 << TESTPUNKT_P0_5);

or alternatively

FIOSET1 = (1 << TESTPUNKT_P1_18);
FIOSET1 = (1 << TESTPUNKT_P1_21);
FIOSET0 = (1 << TESTPUNKT_P0_5);

so each of the three Pins are toggling the same way. This is the soft
uart where i want to send out some bytes (for debugging purposes, the
other 2 uarts are already occupied).

In the main loop i have a endless while loop, which contains the
following code:

#if 1
{
static unsigned char toggle = 0;

if(toggle == 0)
{
FIOCLR1 = (1 << TESTPUNKT_P1_16);
toggle = 1;
}
else
{
FIOSET1 = (1 << TESTPUNKT_P1_16);
toggle = 0;
}
}
#endif // 0

#if 1
{
static unsigned char toggle = 0;

if(toggle == 0)
{
FIOCLR0 = (1 << TESTPUNKT_P0_4);
toggle = 1;
}
else
{
FIOSET0 = (1 << TESTPUNKT_P0_4);
toggle = 0;
}
}
#endif // 0

Now the problem:
The pin toggling (on P1.16) in main loop, disturbs the pins on port 1
(p1.18 and p1.21) which i control from timer interrupt routine.
I see something / someone setting the pin to high, around 720 ns
after i set the pin to low. I can see this in logic analyzer.

See http://www.engelschall.com/~martin/foto/port1_problem.jpg

(On top is correct case, on bottom you can see the problem)

This happens on various positions (beginning of pattern or also
inside the pattern) and resulting is wrong output / characters (i
just output "ABC" again and again, around 5 times per second,
including start and stop bits).
Port 0 is fine, no disturbance, so i think, my code for the soft uart
is working correctly. When i remove toggling of P1.16 in main loop,
also P1.18 and P1.21 work fine fine.

What i found so far
A) It seems to be independant if i use Fast-IO or normal IO.
B) MAMTIM and MAMCR settings seems not to influence the problem.
C) When i don't use the timer and call the function by myself, the
baudrate / timing is wrong (of course), but the problem goes away.
Could be because i remove parallelism.
D) I have done some test, and i don't think it has something to do
with errata Timer.1 in LPC2148 errata sheet.

E) FIOCLR is WO (write only) !?! Why ? I used

FIOCLR1 |= (1 << TESTPUNKT_P1_18);

but meanwhile changed it to

FIOCLR1 = (1 << TESTPUNKT_P1_18);

But no effect on my problem.

All the other registers like FIOSET, FIOMASK, FIODIR are R/W...

F) Possible problem: I used SCS |= 3, but meanwhile changed to SCS 3. No effect on the problem.

G) And the most curious thing: The problem just went away, and i
think, i have not changed anything (ok, standard sentence by
programmers...) I am currently no able to reproduce the problem.

H) I can say it is no hardware problem, because on a board, where it
previously happened, i flashed the current software and problem went
away.

Has someone seen a similar problem or even found out why this
happens ? Ok, hopefully it never occurs again, but all at all i am
not very lucky about this problem.

Regards,

Martin

An Engineer's Guide to the LPC2100 Series

> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of capiman26061973
> Sent: Saturday, November 24, 2007 5:39 PM
> To: l...
> Subject: [lpc2000] Interference problems on Port 1 of LPC2148
> Hello,
>
> i currently tring to understand a problem, which almost drives me
> crazy. I hunt for it for a few hours now, just a simple code. I try
> to implement a soft uart, 9600 baud, 8N1, only sending via a timer
> routine.
>
> Processor is LPC2148 (i have a 'A' revision and a not 'A' revision,
> same results). 12 MHz oscillator. MAMTIM = 0x3; MAMCR > 0x2; SCS = 3;
> USB in use. gcc was 3.x, now 4.1.1
> PLLCFG = 0x24; so i get 60 MHz. Embedded Artists Board and also on
> self developed board. No resistor to P1.26 and P1.20, just open, to
> get debug ports disabled.
>
> Some additional info, what i am using:
>
> static void Interruptroutine_Timer1(void) __attribute__ ((interrupt
> ("IRQ")));
>

Please see prior posts in this forum regarding not using the GCC
language extensions that support interrupt handlers. There is a
well known bug in many GCC versions that cause interrupt routines
to fail if optimization is enabled.

Use assembler stubs instead if you want to have fewer problems, or
make sure you have optimizations disabled for interrupt handlers.

Good luck,

Mike