Tiva LaunchPad w/EduBase LEDs won't turn on - Page 1
Forum section: electronics / general

author: mlugo2
author_rank: Contributor
timestamp: September 16, 2017, 11:48:14 pm
content: I'm using the TM4C1230H6PM LaunchPad with the EduBase Arm Training board.According to the schematics the LEDs are connected to PORT B, but only one of the LEDs (PB0) turns on:Here is my code:Lab4_2.hCode:#include <stdint.h>#include <stdbool.h>#define SYSCTL_RCGC2_R(*((volatile uint32_t*)0x400FE108))#define GPIO_PORTB_DATA_R(*((volatile uint32_t*)0x400053FC))#define GPIO_PORTD_DATA_R(*((volatile uint32_t*)0x400073FC))#define SYSCTL_RCGC2_GPIOB0x00000002// Port B Clock Gating Control#define SYSCTL_RCGC2_GPIOD0x00000008// Port D Clock Gating ControlLab4_2.cCode:#include "Lab4_2.h"#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "driverlib/gpio.h"#include "driverlib/sysctl.h"int main(void) {uint32_t ui32Input;bool res;// Set up the clockSysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);// Enable the GPIO PROTB & PORTDSYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOB|SYSCTL_RCGC2_GPIOD;// Set PB0-PB1 as an output pinsGPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);// Set PD3 as an input pinGPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_3);// Check whether both ports are ready to be accessedres = SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB) | SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD);if (res) {while(1) {ui32Input = GPIO_PORTD_DATA_R;// If DIP-SW1 is pressed turn on LEDif ((ui32Input & 0x8) == 0x8) {GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x1);SysCtlDelay(500000);GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x0);SysCtlDelay(500000);}}}}Is there something that I am missing?Thank you.

author: mlugo2
author_rank: Contributor
timestamp: September 17, 2017, 12:00:12 am
content: Solved itHad to set the last param to 0x3GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x3);I thought the 0x1 just meant set to high haha

author: pigrew
author_rank: Frequent Contributor
timestamp: September 17, 2017, 12:07:12 am
content: When you're writing a 1, you are writing 0x01, which will set only the lowest bit. You'd need to write 0x03 (you may write GPIO_PIN_0 | GPIO_PIN_1 instead if that's more clear) to set both LEDs:GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_PIN_0 | GPIO_PIN_1);Look up the GPIOPinWrite function in the peripheral driver lib manual for more info.It looks like you're already using the peripheral driver library (driverlib), so I'd suggest using it to enable all the modules (SysCtlPeripheralEnable), and for most operations in general. It'll make it easier to read, and easier to port between MCUs. The port #defines should be done for you already (somewhere....), I've never had to manually #define the memory addresses.Also, you should check if the port is ready for use in a while loop. Currently, you check if it's not ready, and if not just give up. Use a while loop to continually check the ready status until it is ready. You should move that check a few lines up, to before you write to their configuration register.Finally, I'm confused about which MCU you're using. I can't find any TM4C1230H6PM launchpads. Are you using a TM4C123GH6PM?The reference manual for the MCU says that using RCGC2 is only for legacy applications. They suggest using RCGCGPIO instead, though I'd suggest using the driver library more fully, so you shouldn't need to worry about that, anyway.