Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

(stm32f100 Discovery) Can I read output GPIO ports?

Status
Not open for further replies.

Build-A-Burger

Full Member level 1
Full Member level 1
Joined
Oct 27, 2010
Messages
95
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Wyoming
Activity points
2,102
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:

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.
 

OK - I've got it working now without using an ISR:

Code:
void StartKeyPressed(void const * argument)
{
	/* USER CODE BEGIN StartKeyPressed */
//	unsigned long ulReceivedValue;
	uint8_t u8_row;
	uint8_t key_pressed;
	GPIO_PinState state;

	key_pressed = 0;

	/* Infinite loop */
	for(;;)
	{
		key_pressed = 0;
  		for (u8_row = 0; u8_row < NUM_ROWS; u8_row++)
		{
			setOneRowLow(u8_row);
			vTaskDelay(1);
			state = HAL_GPIO_ReadPin(GPIOC,col0);
			if(state == GPIO_PIN_RESET)
			{
			 	key_pressed = (au8_keyTable[u8_row][0]);
				HAL_UART_Transmit(&huart2, &key_pressed, 1, 100);
				vTaskDelay(1);
			}
			state = HAL_GPIO_ReadPin(GPIOC,col1);
			if(state == GPIO_PIN_RESET)
			{
			 	key_pressed = (au8_keyTable[u8_row][1]);
				HAL_UART_Transmit(&huart2, &key_pressed, 1, 100);
				vTaskDelay(1);
			}
			state = HAL_GPIO_ReadPin(GPIOC,col2);
			if(state == GPIO_PIN_RESET)
			{
			 	key_pressed = (au8_keyTable[u8_row][2]);
				HAL_UART_Transmit(&huart2, &key_pressed, 1, 100);
				vTaskDelay(1);
			}
			state = HAL_GPIO_ReadPin(GPIOC,col3);
			if(state == GPIO_PIN_RESET)
			{
			 	key_pressed = (au8_keyTable[u8_row][3]);
				HAL_UART_Transmit(&huart2, &key_pressed, 1, 100);
				vTaskDelay(1);
			}
			drive_row_high();
		}
	}
  /* USER CODE END StartKeyPressed */
}
 

Hi,

What about setting up a timer interrupt every 5ms.
In the according ISR:
* read in ports
* activate new row
* decode the input

With this... the ports have about 5ms to settle
And all keys are processed within 4 x 5ms = 20ms.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top