Hi there,
I can't seem to get the other two colours on the LPCXpresso1769CD to light up. I'm using the LPCOpen libraries in the LPCXpresso IDE and to the best of my understanding initialized the GPIO direction (using LPCOpen) and set the LED states analogously to the code provided for the red LED but referencing different port and pins (port 3, pins 25 and 26).
I'm pretty new to this but I have reviewed this with others and the process seems to make sense but it's not working. I've also stepped through the process but the registers don't seem to update. I must be doing something wrong and would appreciate your input. Noob issues I'm sure.
Thanks,Florian
Solved! Go to Solution.
To summarise the changes needed in board.c ...
Add defines for the other two LEDS:
#define LED1_GPIO_PORT_NUM 3
#define LED1_GPIO_BIT_NUM 25
#define LED2_GPIO_PORT_NUM 3
#define LED2_GPIO_BIT_NUM 26
Update Board_LED_Init() to add:
Chip_GPIO_WriteDirBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM, true);
Chip_GPIO_WriteDirBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM, true);
Update Board_LED_Set() to add :
if (LEDNumber == 1) {
Chip_GPIO_WritePortBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM, On);
}
if (LEDNumber == 2) {
Chip_GPIO_WritePortBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM, On);
}
Update Board_LED_Test() to add:
if (LEDNumber == 1) {
state = Chip_GPIO_ReadPortBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM);
}
if (LEDNumber == 2) {
state = Chip_GPIO_ReadPortBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM);
}
Replace code in Board_LED_Toggle :
if (LEDNumber < 3) {
Board_LED_Set(LEDNumber, !Board_LED_Test(LEDNumber));
}
Optimising the above left as an exercise for the reader :smileywink:
Then in your main code, you can call Board_LED_Toggle() with 0,1 or 2 appropriately.
Regards,
LPCXpresso Support
To summarise the changes needed in board.c ...
Add defines for the other two LEDS:
#define LED1_GPIO_PORT_NUM 3
#define LED1_GPIO_BIT_NUM 25
#define LED2_GPIO_PORT_NUM 3
#define LED2_GPIO_BIT_NUM 26
Update Board_LED_Init() to add:
Chip_GPIO_WriteDirBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM, true);
Chip_GPIO_WriteDirBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM, true);
Update Board_LED_Set() to add :
if (LEDNumber == 1) {
Chip_GPIO_WritePortBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM, On);
}
if (LEDNumber == 2) {
Chip_GPIO_WritePortBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM, On);
}
Update Board_LED_Test() to add:
if (LEDNumber == 1) {
state = Chip_GPIO_ReadPortBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM);
}
if (LEDNumber == 2) {
state = Chip_GPIO_ReadPortBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM);
}
Replace code in Board_LED_Toggle :
if (LEDNumber < 3) {
Board_LED_Set(LEDNumber, !Board_LED_Test(LEDNumber));
}
Optimising the above left as an exercise for the reader :smileywink:
Then in your main code, you can call Board_LED_Toggle() with 0,1 or 2 appropriately.
Regards,
LPCXpresso Support
Hi thank you both LPCX Support and Brandon Slade,
I had already updated all those functions...and from your responses found I was using:
Chip_GPIO_WritePortBit(LPC_GPIO3, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM, On);
Chip_GPIO_WritePortBit(LPC_GPIO3, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM, On);
instead of:
Chip_GPIO_WritePortBit(LPC_GPIO, LED1_GPIO_PORT_NUM, LED1_GPIO_BIT_NUM, On);
Chip_GPIO_WritePortBit(LPC_GPIO, LED2_GPIO_PORT_NUM, LED2_GPIO_BIT_NUM, On);
as you suggested.
Thanks, for dealing with my dumb mistake. :smileyblush:
Hi Florian,
The LPCOpen package for the CD board is the same as from the original LPCXpresso1769 board so only supports the one LED, as you have found. The CD board was intended as a drop in replacement, so we didn't change the LPCOpen package. Enough of the background...
To enable the other LEDs you need to:
- ensure the pin muxing is set up correctly in SystemInit(). As it happens, these are already set to what you need, so no work there.
- handle them in the various Board LED functions in board.c
- handle the different enumeration of the LED number in board.c/systick.c
I modified board.c and systick.c, and also used some existing enumerations to remove the "magic number" value (of 0) used for the LED selection in the original. I don't think I forgot any other changes made, but let me know if it works ... just in case.
Regards,
Brendon
Not a big deal, it still works within my main() loop.
Florian
Hi Florian,
I admit I did rush the code out to you so there might be something subtle there, but I just looked again and cant see what you mean. The port numbers and the true/false value propagate all the way to the low level function that sets/clears the GPIO value:
void Chip_GPIO_SetPinState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool setting)
If that doesn't make sense maybe you can provide a little more info on what you see.
Regards,
Brendon
Hey Brendon,
I tried to incorporate your initial LED state off code:
/* Turn off all the LEDs as we start */ | |
Board_LED_Set(LEDS_LED1, FALSE); | |
Board_LED_Set(LEDS_LED2, FALSE); | |
Board_LED_Set(LEDS_LED3, FALSE); |
}
and found that the boolean values don't pass though all the nested functions within the Board_Init() function. I'm not sure why. Did this work for you?