We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
pls help...
i'm working on LPC1114-FBD/301 series
On my board 4 LED's are connected to P0_8, P0_9, P0_10, P0_11.
I'v written a sample code toggle them. Only on 8 and 9 port pin LED's are blinking but on 10 and 11 there state is always on. here is the sample code
/* by default P0_8 and P0_9 pins are GPIO's */ LED_DIR |= BIT(8); LED_DIR |= BIT(9);
/* 9th and 10th pins are not GPIO's on reset */ // i think here some changes required to make them as GPIO's IOCON_SWCLK_PIO0_10 |= 0x1; IOCON_R_PIO0_11 |= 0x1;
LED_DIR |= BIT(10); LED_DIR |= BIT(11);
On reset all the LED's are ON. I'v writtern a test code to toggle there states. After flashing the code all LED states should be toggled. But only LED's on P0_8 and p0_9 pins are getting toggled. Other two LED's connected on P0_10 and P0_11 are always ON.
I'm sending the code. Pls review.
#define LED_DIR GPIO0DIR #define BIT(n) (1<<n)
void delay( ) { unsigned int i = 0x40000; while ( i-- ); } main ( ) {
/* 10th and 11th pins are not GPIO's on reset */
IOCON_SWCLK_PIO0_10 |= 0x01; /* Set P0_10 pin as GPIO */
IOCON_R_PIO0_11 |= 0x01; /* Set P0_11 pin as GPIO */
while ( 1 ) { GPIO0DATA &= ~(BIT(8)); GPIO0DATA &= ~(BIT(9)); GPIO0DATA &= ~(BIT(10)); GPIO0DATA &= ~(BIT(11)); delay( ); delay( ); GPIO0DATA |= BIT(8); GPIO0DATA |= BIT(9); GPIO0DATA |= BIT(10); GPIO0DATA |= BIT(11); delay( ); delay( ); } }
if you don't have hardware debugging capabilities, you may want to simulate your code.
i have no idea if your is right or not but the following may be more readable:
#define LED_PORT GPIO0DATA //output data register where the leds are on #define LED_DIR GPIO0DIR #define BIT(n) (1<<n) #define LEDs (BIT(8) | BIT(9) | BIT(10) | BIT(11)) //leds on pin8/9/10/11 #define LED_ON(leds) {LED_PORT |= (leds);} //leds active on #define LED_OFF(leds) {LED_PORT &=~(leds);} //leds active off #define LED_TOGGLE(leds) {LED_PORT ^= (leds);} //toggle leds void delay(unsigned long dly ) { while ( dly-- ); } void main (void ) { /* by default P0_8 and P0_9 pins are GPIO's */ LED_DIR |= BIT(8); LED_DIR |= BIT(9); /* 10th and 11th pins are not GPIO's on reset */ IOCON_SWCLK_PIO0_10 |= 0x01; /* Set P0_10 pin as GPIO */ IOCON_R_PIO0_11 |= 0x01; /* Set P0_11 pin as GPIO */ LED_DIR |= BIT(10); LED_DIR |= BIT(11); while ( 1 ) { LED_TOGGLE(LEDs); //toggle leds delay(0x40000 ); //waste some time } }
this will be easier to read.
I'm sending the code. Pls review. please review the instructions Place source code source code .... in the yellow field of the reply (Enter Message Details Below) window
why do you think anyone can do anything with what you saw in the preview?
Erik
Thanks... I'v to improve my coding style...
The details of the NXP (founded by Philips) LPC1114/301 can be found here:
http://www.keil.com/dd/chip/5063.htm
Under the 'Evaluation Boards' section you will see Keil supports this device with the MCB1000 evaluation board.
You can find examples for this board on your hard drive at:
C:\Keil\ARM\Boards\Keil\MCB1000\MCB1114\Blinky\Blinky.uvproj
In Blinky.c, line 64 is LED_Init() This is for GPIO2, but you can use it for a reference.
You can debug blinky in the simulator. On the toolbar, next to the button that says 'LOAD' is the a drop down box. This is the target selector box. Choose 'Simulator'.
Select Project-> Build Select Debug -> Start Stop debug session
You can now debug the code.
Under Peripherals -> GPIOs You can find the simulated peripheral windows. For this example, GPIO 2 should come up by default. As you step through the code, you can watch the GPIO port be configured in this window.
Run the code until you feel comfortable with how GPIO2 is configured.
Modify the code for GPIO0, and use the GPIO peripheral window to debug it.
Then copy and paste this modified code into your project.
You are just refusing to try any debugging?
No verification that the registers you perform logical or/and operations on really have the values you assume? Not considering performing an assign instead of a logic or for IOCON_R_PIO0_11 and IOCON_SWCLK_PIO0_10?
No test of GPIO0DATA? If port is output, then you should be able to set bits and read back the same value. If port is input, then your writes should be thrown away. If port isn't GPIO but special function, then read should correspond to the actual value of the pin (even if driven by special function).
No verification that your LED are connected to the correct pin?
No verification which instruction in the program that makes the LED turn off?
Is GPIO0DATA at the base address? It can be any address between 0x5000:0000 and 0x5000:3ffc and the address of GPIO0DATA will affect which bits of the port that may be accessed or masked away. Maybe you use GPIO0DATA as address 0, in which case all writes are blocked.
No verification that PIO:11 isn't in analog mode?
Don't you get it - you have to do debugging. We can't remote-debug your code.
Also if you run your code in the Keil simulator as I described above, make sure to check out the Peripheral pull down menu -> I/O Configuration window.
As you step through your code you should see
pin P0.10 change from 'SWCLK' to 'GPIO Port 0.10, (when you change IOCON_PIO0_10 to 0x0D1) pin P0.11 change from TDI to "GPIO Port 0.11", (when you change IOCON_PIO0_11 to 0x0D1)
No test of GPIO0DATA? If port is output, then you should be able to set bits and read back the same value. If port is input, then your writes should be thrown away. If port isn't GPIO but special function, then read should correspond to the actual value of the pin (even if driven by special function). working with IAR on a project I sorely missed Keils excellent GPIO debug window. In that window, the OP sholud be able to see exactly what is going on
I still wonder if the OP have reached chapter 9.4.1 yet.
"working with IAR on a project I sorely missed Keils excellent GPIO debug window."
you can do that with iar too.
sure, but much more cumbersome