Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LPC2138 does not work correctly

Status
Not open for further replies.

mi14chal

Newbie level 5
Joined
Oct 30, 2010
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
I wrote a simple program as below:
Code:
#include <LPC213x.h>
 
int main (void)
{
	IODIR1 = (1 << 25) | (1 << 24);
	IODIR0 = (1 << 1) | (1 << 2);
	for(;;)
	{
		IOSET1 = (1 << 25) | (1 << 24);
		IOSET0 = (1 << 1) | (1 << 2);
	}
}

I've connected 150 ohm resistor and LED to these ports. But when I turn on the power supply diodes are acting strangely. There are three "cases" of said strange acting - 1) diodes simply don't light up, 2) only one of them light up, 3) three dioes light up. The interesting thing is that diode connected to port P0.2 never happen to light up. Do you have any idea what may cause such a problems?
 
Last edited:

as shown in datasheet as IO1DIR and IO0DIR instead of IODIR1 and IODIR0 and same with IOSET0 and IOSET1.
 

IOSET1 = (1 << 25) | (1 << 24);
IOSET0 = (1 << 1) | (1 << 2);

In the above there is no delay. So LED pins are setting at a very fast rate and you are not able to see it. Insert delay of 500 ms or 1 sec.
 

as shown in datasheet as IO1DIR and IO0DIR instead of IODIR1 and IODIR0 and same with IOSET0 and IOSET1.

I assume you are saying that he has used wrong register names.
Note that the names defined in the header do not always match the names of the datasheet, in this case the header is https://www.keil.com/dd/docs/arm/philips/lpc213x.h and the defined names in the header are


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* General Purpose Input/Output (GPIO) */
#define IOPIN0         (*((volatile unsigned long *) 0xE0028000))
#define IOSET0         (*((volatile unsigned long *) 0xE0028004))
#define IODIR0         (*((volatile unsigned long *) 0xE0028008))
#define IOCLR0         (*((volatile unsigned long *) 0xE002800C))
#define IOPIN1         (*((volatile unsigned long *) 0xE0028010))
#define IOSET1         (*((volatile unsigned long *) 0xE0028014))
#define IODIR1         (*((volatile unsigned long *) 0xE0028018))
#define IOCLR1         (*((volatile unsigned long *) 0xE002801C))
#define IO0PIN         (*((volatile unsigned long *) 0xE0028000))
#define IO0SET         (*((volatile unsigned long *) 0xE0028004))
#define IO0DIR         (*((volatile unsigned long *) 0xE0028008))
#define IO0CLR         (*((volatile unsigned long *) 0xE002800C))
#define IO1PIN         (*((volatile unsigned long *) 0xE0028010))
#define IO1SET         (*((volatile unsigned long *) 0xE0028014))
#define IO1DIR         (*((volatile unsigned long *) 0xE0028018))
#define IO1CLR         (*((volatile unsigned long *) 0xE002801C))
#define FIO0DIR        (*((volatile unsigned long *) 0x3FFFC000))
#define FIO0MASK       (*((volatile unsigned long *) 0x3FFFC010))
#define FIO0PIN        (*((volatile unsigned long *) 0x3FFFC014))
#define FIO0SET        (*((volatile unsigned long *) 0x3FFFC018))
#define FIO0CLR        (*((volatile unsigned long *) 0x3FFFC01C))
#define FIO1DIR        (*((volatile unsigned long *) 0x3FFFC020))
#define FIO1MASK       (*((volatile unsigned long *) 0x3FFFC030))
#define FIO1PIN        (*((volatile unsigned long *) 0x3FFFC034))
#define FIO1SET        (*((volatile unsigned long *) 0x3FFFC038))
#define FIO1CLR        (*((volatile unsigned long *) 0x3FFFC03C))



- - - Updated - - -

IOSET1 = (1 << 25) | (1 << 24);
IOSET0 = (1 << 1) | (1 << 2);

In the above there is no delay. So LED pins are setting at a very fast rate and you are not able to see it. Insert delay of 500 ms or 1 sec.

This lines cause the pins to be set in a high logic state and stay there, after being executed once nothing changes so a delay will not make a difference, this is not a toggle code
 

Can you please tell me that to which pins have you connected the LEDs and have you connected them between (the pin and ground) or (the vcc and the pin).
 

I've connected to pin as you can see in code. Connecting look: Pin -> 150 ohm resistor -> LED -> ground
 

i think you need these logical corrections:

Code:
#include <LPC213x.h>
 
int main (void)
{
	IODIR1 = (25 << 1) | (24 << 1);                 //this will set direction of P1.25 & P1.24    [ not (1 << 25) | (1 << 24) ] 
	IODIR0 = (1 << 1) | (2 << 1);                    // here this will set direction for  P0.1 & P0.2
	for(;;)
	{
		IOSET1 = (25 << 1) | (24 << 1);
		IOSET0 = (1 << 1) | (2 << 1); 
	}
}
 

i think you need these logical corrections:

Code:
#include <LPC213x.h>
 
int main (void)
{
	IODIR1 = (25 << 1) | (24 << 1);                 //this will set direction of P1.25 & P1.24    [ not (1 << 25) | (1 << 24) ] 
	IODIR0 = (1 << 1) | (2 << 1);                    // here this will set direction for  P0.1 & P0.2
	for(;;)
	{
		IOSET1 = (25 << 1) | (24 << 1);
		IOSET0 = (1 << 1) | (2 << 1); 
	}
}

(25<<1) or (24 << 1) don't serve a meaningful purpose, what can be the purpose of shifting 25 or 24 left one time?

On the contrary the original code that shifts 1 left x times (1 << x) is frequently used to set a specific bit by shifting 1 in the appropriate bit position.
 

there is no delay between on and off put a delay simply there and than see result.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top