Other Parts Discussed in Thread: EK-TM4C123GXL
platform : EK-TM4C123GXL
IAR Embedded Workbench 32kb limit version, v.9.20.4.47112
IAR Embedded Workbench shared components v.9.0.11.9006
Used timers example from (TivaWare_C_Series-2.2.0.295) as a foundation for the program, added I2C for LCD display, removed timers and LED, wrote routine to scan 8x10 keys array (see below)
void InitKBScanner()
{
UARTprintf("\033[2JKBScannerf initializing...\n");
// Initializing pin groups
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
// Configuring scanning pins
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |GPIO_PIN_3);//MATC0,1,2 and 3
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);//MATC4,5,6 and 7
//Configuting scanner reading pins
MAP_GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1| GPIO_PIN_2| GPIO_PIN_3| GPIO_PIN_4| GPIO_PIN_5);//MATL0-5
MAP_GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);//MATL6-9
// Turning all scanning pins LOW
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 |GPIO_PIN_2 |GPIO_PIN_3, 0);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7, 0);
}
Code compiles and works well if the char* KB_MAP[] contains no more than 20 elements, biggest element is 9 char string.
I have split array in 8 separate arrays x10 elements each and implemented data display (see below)
char* KB_MAP_MATC0[10]=
{
"1", "2", "3", "K", "L", "M", "N", "O", "blank", "CLR"
};
char* KB_MAP_MATC1[10]=
{
"4", "5", "6", "P", "Q", "R", "S", "T", "BRT", "LEFT"
};
char* KB_MAP_MATC2[10]=
{
"7", "8", "9", "U", "V", "W", "X", "Y", "DIM", "RIGHT"
}; etc
//data display:
void displayLabel(char* LBL)
{
UARTprintf(LBL);
SetCursorPos(11, 3);
WriteString(LBL);
}
//example of scanning one column of the matrix with data display
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 1);
keyCode=KeyDetectf();
if(keyCode)
{
displayLabel(KB_MAP_MATC0[(keyCode-1)]);
keyCode=0;
SysCtlDelay(50000);
}
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);
//keyDetecf detects high input and returns line number for activated key
uint8_t KeyDetectf()
{
uint8_t matL=0; //returning active MATLx line value
//UARTprintf(" KeyDetectf called...\n");
// SysCtlDelay(5000000);
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0))
matL=1;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1))
matL=2;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2))
matL=3;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3))
matL=4;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4))
matL=5;
if(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_5))
matL=6;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4))
matL=7;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5))
matL=8;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6))
matL=9;
if(GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_7))
matL=10;
return matL;
}
Code executes perfectly well, only when any two out of eight column scans use "displayLabel(KB_MAP_MATCx[(keyCode-1)]);"
Adding third arbitrary column call "displayLabel(KB_MAP_MATCx[(keyCode-1)]);" compiles without errors or warnings, but debugging and execution hangs and upon stopping debugger results in hard fault:
"Fri May 20, 2022 14:31:31: HardFault exception.
Fri May 20, 2022 14:31:31: The processor has escalated a configurable-priority exception to HardFault.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: A precise data access error has occurred (CFSR.PRECISERR, BFAR)
Fri May 20, 2022 14:31:31: At data address 0x1ffffff0.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: A derived bus fault has occurred on exception entry (CFSR.STKERR, BFAR)
Fri May 20, 2022 14:31:31: At data address 0x1ffffff0.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: Could not determine the location where the exception occurred.
Fri May 20, 2022 14:31:31:
Fri May 20, 2022 14:31:31: See the call stack for more information."
Call stack displays:
" FaultISR()
<Exception frame> "
Any and all help will be greatly appreciated.