frankiboy 0 Posted March 13, 2014 Share Posted March 13, 2014 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! Quote Link to post Share on other sites
frankiboy 0 Posted March 13, 2014 Author Share Posted March 13, 2014 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. spirilis and abecedarian 2 Quote Link to post Share on other sites
spirilis 1,265 Posted March 13, 2014 Share Posted March 13, 2014 That's one of those things that drives me up the wall sometimes... used to the MSP430 where you usually don't have to "enable things" abecedarian 1 Quote Link to post Share on other sites
abecedarian 330 Posted March 15, 2014 Share Posted March 15, 2014 Enable before using? How ironic. That's like driving the car before starting the engine. Yes, I jest. I'm guilty of it as well. I just don't talk about it. dubnet 1 Quote Link to post Share on other sites
SixSixSevenSeven 23 Posted March 15, 2014 Share Posted March 15, 2014 Enable before using? How ironic. That's like driving the car before starting the engine. 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 abecedarian 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.