I'm not able to make it work the GPIO P1.0-P1.3 of LPC1114. Both in hardware as in keil debug the GPIO's P1.0 dont clear.
int main() { /* Enable AHB clock to the GPIO domain. */ LPC_SYSCON->SYSAHBCLKCTRL |= (0x1UL << 16); /* enable clock for IOCON */ LPC_SYSCON->SYSAHBCLKCTRL |= (0x1UL << 6); /* enable clock for GPIO */ LPC_IOCON->R_PIO1_0 |= 0x01; /* P1.0 as GPIO */ LPC_GPIO1->DIR |= (1UL << 0); /* P1.0 as GPIO */ LPC_GPIO1->DATA &= ~(1UL << 0); /* Clear P1.0 */ //*********Don't work while(1); }
what's wrong with this code?
Here is example code from a blinky example:
I see a few things that are different: Maybe there is a clue in this code.
#include "LPC11XX.h" #define KEIL_MCB1000_BOARD // Switch LED signal to output port with no pull up or pulldown void LedOutputCfg(void) { // Enable clock to IO configuration block (bit[16] of AHBCLOCK Control register) // and enable clock to GPIO (bit[6] of AHBCLOCK Control register LPC_SYSCON->SYSAHBCLKCTRL = LPC_SYSCON->SYSAHBCLKCTRL | (1<<16) | (1<<6); #ifdef KEIL_MCB1000_BOARD // For Keil MCB1000, use P2.0 for LED output // PIO2_0 IO output config // bit[5] - Hysteresis (0=disable, 1 =enable) // bit[4:3] - MODE(0=inactive, 1 =pulldown, 2=pullup, 3=repeater) // bit[2:0] - Function (0 = IO, 1=DTR, 2=SSEL1) LPC_IOCON->PIO2_0 = (0<<5) + (0<<3) + (0x0); // Initial bit 0 output is 0 LPC_GPIO2->MASKED_ACCESS[1] = 0; // Set pin 7 to 0 as output LPC_GPIO2->DIR = LPC_GPIO2->DIR | 0x1; #else // For LPCXpresso, use P0.7 for LED output // PIO0_7 IO output config // bit[5] - Hysteresis (0=disable, 1 =enable) // bit[4:3] - MODE(0=inactive, 1 =pulldown, 2=pullup, 3=repeater) // bit[2:0] - Function (0 = IO, 1=CTS) LPC_IOCON->PIO0_7 = (0x0) + (0<<3) + (0<<5); // Initial bit[7] output is 0 LPC_GPIO0->MASKED_ACCESS[1<<7] = 0; // Set pin 7 as output LPC_GPIO0->DIR = LPC_GPIO0->DIR | (1<<7); return; #endif } // end LedOutputCfg
.
LPC_IOCON->R_PIO1_0 |= 0x01; /* P1.0 as GPIO */
try writing zero here.
The default for P1.0 pin is TMS function. If writing zero to ICON, will stay in TMS function. Need write 0x01 in ICON->P1.0 for config to GPIO function. The setup is ok, but don't work clear pin.
Oh, Now I see that you are correct, but I see a bit 7 that may need to be one.
7 ADMODE Selects Analog/Digital mode 1 0 Analog input mode 1 Digital functional mode
Maybe you did not understand what I said above. I think you should write a 0x9 instead of 1. The reason is that bit 7 is analog or digital mode of the pin. and you have it in analog mode instead of digital mode. How are you supposed to drive the pin.
to raise bit 7 would actually be 0x81. Wish there was a way to edit mistakes.
You're right, but still don't work!
#include "LPC11XX.h" int main() { LPC_SYSCON->SYSAHBCLKCTRL |= (0x1UL << 16); /* enable clock for IOCON */ LPC_SYSCON->SYSAHBCLKCTRL |= (0x1UL << 6); /* enable clock for GPIO */ LPC_GPIO1->DIR = 0x1; LPC_GPIO1->DATA &= ~0x1; LPC_GPIO1->DATA |= 0x1; while(1) { LPC_GPIO1->DATA &= ~0x1; LPC_GPIO1->DATA |= 0x1; } }
The above code has been tested with my Keil IDE simulator, and it "worked well". Don't know what will happen on a real hardware, I don't have a LPC1114.
I would like to know what board you are using. If it is a board available to the public or is the board a in house custom board.
PIO1_0/AD1/CT32B1_CAP0/TMS 33 PIO1_1/AD2/CT32B1_MAT0/TDO 34 PIO1_2/AD3/CT32B1_MAT1/TRST/ 35 PIO1_3/AD4/CT32B1_MAT2/SWD 39 PIO1_4/AD5/CT32B1_MAT3/WAKEUP
The MCB1000 schematic shows the functions of the pins.
Does your board use a JTAG connector.. Is it possible that these pins are tied to Jtag. The MCB1000 does not have a jtag. but pin PIO1_3 goes to a Debug connector and to a header or socket.
PIO1_3 looks to be the SWD pin for the chip. Probably should not try to use for other purposes if you are using the debug port.
Your code worked fine in Keil IDE simulator, but in the hardware needed config IOCON after config DIR. If config IOCON before the DIR, don't work in the hardware. Thanks
#include "LPC11XX.h" int main() { LPC_SYSCON->SYSAHBCLKCTRL |= (0x1UL << 16); /* enable clock for IOCON */ LPC_SYSCON->SYSAHBCLKCTRL |= (0x1UL << 6); /* enable clock for GPIO */ LPC_GPIO1->DIR = 0x1; LPC_IOCON->R_PIO1_0 |= (0x1UL << 0); LPC_GPIO1->DATA &= ~0x1; LPC_GPIO1->DATA |= 0x1; while(1) { LPC_GPIO1->DATA &= ~0x1; LPC_GPIO1->DATA |= 0x1; } }
Hi,
I would like to use GPIO 1_20 in my lpc11uxx platform. How to define the gpio registers, direction, output high and low.. Again the same gpio will change it in input.. Like 1 wire logic can someone help me how this can be defined to operate and read the gpio.
Regards