Other Parts Discussed in Thread: EK-TM4C123GXL
Good afternoon,
I am trying to set up my TM4C micro to use port B (pins 0 - 2) as a digital input. The datasheet says Pin 2 is special which may or may not have anything to do with this error.
It seems no matter what I try, the next instruction after any access to a port B register causes a hard fault.
Following the indicated directions in the manual, I've tried:
- Configuring the SYSCTRL_RCGCGPIO register to include port B
- Configuring port B as input by writing 0 to the DIR register
- Disabling PORTB_LOCK by writing 0x4C4F434B
- Writing to the commit register (seems necessary but I do it anyways)
- Setting AFSEL to 0
- Configuring as I/O by writing appropriate bit to the DEN register.
In just about every order and combination that is possible. Still it seems to always throw a hard fault after anything to do with PORT B is executed. I can set the SYSCTRL_RCGCGPIO register and watch the registers fine, but any instruction that has to do with PORT B seems to cause a Hard Fault. I am not sure if there is some way to get more information about what is actually causing it.
Here is a code snippet:
#define PORT_A (1U << 0)
#define PORT_B (1U << 1)
#define PORT_C (1U << 2)
#define PORT_D (1U << 3)
#define PORT_E (1U << 4)
#define PORT_F (1U << 5)
#define PORT_G (1U << 6)
#define PORT_H (1U << 7)
#define PORT_J (1U << 8)
#define PORT_K (1U << 9)
#define PORT_L (1U << 10)
#define PORT_M (1U << 11)
#define PORT_N (1U << 12)
#define PORT_P (1U << 13)
#define PIN_0 (1U << 0)
#define PIN_1 (1U << 1)
#define PIN_2 (1U << 2)
#define PIN_3 (1U << 3)
#define PIN_4 (1U << 4)
#define PIN_5 (1U << 5)
#define PIN_6 (1U << 6)
#define PIN_7 (1U << 7)
#define PIN_ALL 0xFF
...
SYSCTL_RCGCGPIO_R |= (PORT_A|PORT_B|PORT_D|PORT_G|PORT_H|PORT_J|PORT_L|PORT_M|PORT_N);
SYSCTL_GPIOHBCTL_R |= (PORT_J|PORT_L|PORT_M|PORT_N);
/*PORT A initializations ... */
//PORT B
GPIO_PORTB_LOCK_R = 0x4C4F434B;
GPIO_PORTB_CR_R = 0x07; //will always hard fault here, no matter what order these are in
GPIO_PORTB_AFSEL_R = 0x0;
GPIO_PORTB_DEN_R = (PIN_0|PIN_1|PIN_2);
GPIO_PORTB_DIR_R = 0x0;
GPIO_PORTB_PCTL_R = 0x0;
Any assistance is appreciated.