Build-A-Burger
Full Member level 1
I'm interfacing a 4x4 keypad to an STM32F100 Discovery board - using PC0->3 as the 4 columns and PB12->15 as the rows. The rows are outpus and the columns are inputs. The 4 rows do a scan (each bit goes low one at a time) in one task and when a key is pressed one of the inputs causes an ISR to be triggered. I want to read the current state of the output port (GPIOB) within the ISR so I can do a lookup for the keypad.
Here's my code:
All I get is slashes. There's goto be an easier way to do this other than possible doing a HAL_GPIO_ReadPin(GPIOB, x);
BTW, I'm compiling with Atollic TrueStudio and using FreeRTOS.
Here's my code:
Code:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
UCHAR crow;
volatile long unsigned int *regb;
volatile long unsigned int regb3;
volatile long unsigned int regb3a;
unsigned int regb4;
uint8_t col;
uint8_t key_pressed;
regb = (long unsigned int*)GPIOB->ODR;
regb3 = *regb;
regb3a = regb3;
regb4 = (unsigned int)regb3;
crow = (UCHAR)regb4;
crow += 0x30;
HAL_UART_Transmit(&huart2, &crow, 1, 100);
regb4 = (unsigned int)regb3;
regb4 >>= 8;
crow = (UCHAR)regb4;
crow += 0x30;
HAL_UART_Transmit(&huart2, &crow, 1, 100);
regb4 = (unsigned int)regb3;
regb4 >>= 16;
crow = (UCHAR)regb4;
crow += 0x30;
HAL_UART_Transmit(&huart2, &crow, 1, 100);
regb4 >>= 8;
crow = (UCHAR)regb4;
crow += 0x30;
HAL_UART_Transmit(&huart2, &crow, 1, 100);
/*
col = (UCHAR)GPIO_Pin;
switch(col)
{
case 1:
col = 0;
break;
case 2:
col = 1;
break;
case 4:
col = 2;
break;
case 8:
col = 3;
break;
default:
col = 0;
break;
}
key_pressed = (au8_keyTable[glrow][col]);
glrow += 0x30;
HAL_UART_Transmit(&huart2, &glrow, 1, 100);
crow = 0x20;
HAL_UART_Transmit(&huart2, &crow, 1, 100);
*/
}
All I get is slashes. There's goto be an easier way to do this other than possible doing a HAL_GPIO_ReadPin(GPIOB, x);
BTW, I'm compiling with Atollic TrueStudio and using FreeRTOS.