This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hard fault exception

Other Parts Discussed in Thread: TM4C123GH6PM

Im using KEIL 4.74.0.0 for programming TM$C123GH6PM.

when I debug the below program im getting hard fault exception handler

                          ///      PROGRAM FOR  LCD  DISPLAY     //////

#include"tm4c123gh6pm.h"

#define rs 0
#define rw 1
#define en 2
void delay(unsigned int k)
{
int i,j;
for(i=0;i<k;++i)
for(j=0;j<1000;++j);
}

void cmd(unsigned char y)
{
GPIOD->DATA=0<<rs;
//GPIOD->DATA=0<<rw;
//GPIOB->DATA=y;
//GPIOD->DATA=1<<en;
// delay(30);
//GPIOD->DATA=0<<en;
}
void data(unsigned char y)
{
GPIOD->DATA=1<<rs;
GPIOD->DATA=0<<rw;
GPIOB->DATA=y;
GPIOD->DATA=1<<en;
//delay(1000);
GPIOD->DATA=0<<en;
}

void lcd_init()
{
cmd(0x38);
//cmd(0x0e);
// cmd(0x80);

}
int main()
{
int i;
SystemInit();
/* SYSCTL->RCC=1<<11; // set Bypass
SYSCTL->RCC|=(0<<22); // clear USESYSDIV
SYSCTL->RCC|=(0<<13)|(0<<5)|(0<<4)|(0x15<<6); //PWRDN clear, MAIN OSC select,XTAL 16 MHz
SYSCTL->RCC|=(0x3<<23)|(1<<22); //SYSDIV 3, set USESYSDIV
while(((SYSCTL->RIS&0x00000040)==0)); // wait 4 PLL to LOCK
SYSCTL->RIS=1<<6; // clear PLLRIS interrupt
SYSCTL->RCC|=0<<11;
for(i=0;i<1000;++i);
*/
SYSCTL->RCGCGPIO=1<<1;
GPIOB->DIR=0xff;
GPIOB->AFSEL=0x00;
GPIOB->DEN=0xFF;

SYSCTL->RCGCGPIO=1<<3;
GPIOD->DIR=0xff;
GPIOD->AFSEL=0x00;
GPIOD->DEN=0xff;

SYSCTL->RCGCGPIO=1<<5;
GPIOF->DIR=0xFF; //output
GPIOF->AFSEL=0x00; // as GPIO
GPIOF->DEN=0xff; // as DIGITAL pins
GPIOF->DATA=0<<1;
lcd_init();
GPIOF->DATA=1<<1;

while(1)
{

cmd(0x80);
data('V');
}
}

when lcd_init(); function is called it jumps to  hard fault exception handler.

Please help me to solve this problem.

  • Hi,

    This is your second post with the same code (problem). Now I understand you fall into hard fault - seems your code uses a CMSIS mode to make programs. Please note that TI did not officially released such file for it's Tiva micros, so any other file may be with problems, more or less (harder to spot) obvious.

    On the other side, please also use this link to see an example for Keil tools-look for LCD_4C123.zip package - take into account that refers to a display with a single row, so if yours (unspecified) may have more, so you need to make some modifications, but do that only after the first eight characters are correctly displayed.

    Petrei