From 96d534ed980fb310783fda1592b05463a9be7b91 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Thu, 15 Oct 2015 12:45:20 +0200 Subject: Delay after setting output pin, to prevent incorrect reading. --- src/short-test/src/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/short-test/src/main.c b/src/short-test/src/main.c index ee1fedb..902a98b 100644 --- a/src/short-test/src/main.c +++ b/src/short-test/src/main.c @@ -94,8 +94,7 @@ void configure_all_as_input(GPIO_TypeDef* GPIOx, uint16_t GPIO_Test_Pins) /* Configure all pins as input. XXX do all pins (0xffff) instead of just GPIO_Test_Pins? */ GPIO_InitStruct.Pin = GPIO_Test_Pins; - //GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; /* XXX does GPIO_PULLDOWN work with GPIO_MODE_INPUT? */ + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOx, &GPIO_InitStruct); @@ -168,6 +167,12 @@ void test_for_shorts(char port, GPIO_TypeDef* GPIOx, uint16_t GPIO_Test_Pins) HAL_GPIO_WritePin(GPIOx, Test_Pin, GPIO_PIN_SET); + /* Slight delay after setting the output pin. Without this, the Test_Pin + bit might read as zero, as it is only sampled once every AHB1 clock cycle. + Reference manual DM00031020 section 8.3.1. + */ + HAL_Delay(1); + /* Read all input GPIOs from port at once. XXX check all pins, not just GPIO_Test_Pins? */ read = GPIOx->IDR & GPIO_Test_Pins; -- cgit v1.2.3