Author Topic: Tiva LaunchPad w/EduBase LEDs won't turn on  (Read 1210 times)

0 Members and 1 Guest are viewing this topic.

Offline mlugo2Topic starter

  • Contributor
  • Posts: 24
  • Country: us
Tiva LaunchPad w/EduBase LEDs won't turn on
« on: September 16, 2017, 11:48:14 pm »
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.h
Code: [Select]
#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_GPIOB 0x00000002 // Port B Clock Gating Control
#define SYSCTL_RCGC2_GPIOD 0x00000008 // Port D Clock Gating Control

Lab4_2.c
Code: [Select]
#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 clock
SysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

// Enable the GPIO PROTB & PORTD
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOB|SYSCTL_RCGC2_GPIOD;

// Set PB0-PB1 as an output pins
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// Set PD3 as an input pin
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_3);

// Check whether both ports are ready to be accessed
res = SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB) | SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD);

if (res) {
while(1) {
ui32Input = GPIO_PORTD_DATA_R;

// If DIP-SW1 is pressed turn on LED
if ((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.
 

Offline mlugo2Topic starter

  • Contributor
  • Posts: 24
  • Country: us
Re: Tiva LaunchPad w/EduBase LEDs won't turn on
« Reply #1 on: September 17, 2017, 12:00:12 am »
Solved it :-DD

Had to set the last param to 0x3
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x3);

I thought the 0x1 just meant set to high haha
 

Offline pigrew

  • Frequent Contributor
  • **
  • Posts: 680
  • Country: us
Re: Tiva LaunchPad w/EduBase LEDs won't turn on
« Reply #2 on: September 17, 2017, 12:07:12 am »
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.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf