Jump to content
43oh

Unable to use Port E for GPIO


Recommended Posts

Hi,

 

Quite new to this forum and the Stellaris launchpad. I've faced a problem and not found any answers after hours of searching. I feel pretty stupid about this one, since it should be very basic.

 

I've set up gcc on my linux desktop and have been able to run several examples and tested some of my own code without any problems. I want to do some temperature readings using a DS18B20 temperature sensor. I soldered a temperature sensor to PE4. The problem I face is that everything seems to hang once I set PE4 as GPIO input.

 

I've stripped down my code to make it easier to debug, please have a look.

#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "utils/uartstdio.h"

#define BLINK
#define LED_RED GPIO_PIN_1
#define LED_BLUE GPIO_PIN_2
#define LED_GREEN GPIO_PIN_3

#define DELAY_MS(ms)    {ROM_SysCtlDelay(ms * (ROM_SysCtlClockGet() / 3000));}
#define DELAY_US(us)    {ROM_SysCtlDelay(us * ((ROM_SysCtlClockGet() / 3000)/1000));}

static char uart_input_buffer[128];

int main()
{
  ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN);
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
  ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
  ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  UARTStdioInit(0);
  UARTEchoSet(false);

  ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);

  ROM_IntMasterEnable();
  UARTprintf("Welcome.\n");

  UARTprintf(". . . . . . . . . . . . . . .");
  for (; {
#ifdef BLINK
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_BLUE|LED_RED);
    DELAY_MS(1000);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED);
    DELAY_MS(1000);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN);
    DELAY_MS(1000);
#else
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0);
#endif
  }

}


The system seems to hang when I run this code. There is no output on the uart and the light is not blinking. If I remove the following line

  ROM_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_4);

everything is as expected.

 

It looks like the same happens if I try to use any pin on port E or B, while port A and F works as expected.

 

Any idea why this is not working?

 

Thanks!

Link to post
Share on other sites

Answering my own question since I found the solution. It was simple as expected, so I don't know why I didn't see this from the beginning.

 

I need to enable the peripheral before I start using it. Adding the following line before setting the pin as input solved the problem:

  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

I assume Port A and F did not cause the same issue since the ports where in use by the driverlib/utils code.

Link to post
Share on other sites

Enable before using? How ironic. ;)

That's like driving the car before starting the engine. :D

 

Yes, I jest. I'm guilty of it as well. I just don't talk about it. :)

Oh we've all done that I think. Go sit in your car, put it in gear, slowly lift up the clutch and apply some throttle and nothing happens... Headbutting of the steering wheel is the only remedy for this

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...