I'm fairly new to MCU development so there's probably something basic wrong here.
I'm having trouble achieving basic GPIO output control in two different but possibly related situations. Working on a NUCLEO board (STM32U5).
Problem #1:
I was successfully able to control GPIO output level of ADC_SEL0_Pin at one point recently but suddenly HAL_GPIO_WritePin is seemingly having no effect (measuring with a multimeter). Changing the pin's level in STM32CubeIDE does still have an effect - I think generates the below code in MX_GPIO_Init():
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, ADC_SEL1_Pin|ADC_SEL0_Pin, GPIO_PIN_SET);
For some reason trying to modify the pin's level in main() after the call to MX_GPIO_Init() no longer seems to do anything.
I've attached my main.c. Note that the code shows both calls setting to the pin HIGH, but if I change the second call to LOW the pin will measure as HIGH - only the first call has any effect. What might cause this?
Problem #2:
I am responding to an interrupt raised by the Data Ready Line (DRL) signal output by the external ADC I am reading from (SPI configured as read-only master mode). In the ISR I call HAL_SPI_Receive() to read 32 bits. Inspecting the SCK line it rests at digital HIGH following the read, then halfway to the next DRL pulse it drops to LOW, but it seems to bounce a lot on the way (see attached logic analyzer output).
I need the SCK line to remain quiet between reads so to combat this I tried to manually force SCK low immediately following the read (PA5 is the SPI1_SCK pin):
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == SPI1_DRL_Trigger_Pin)
{
HAL_SPI_Receive(&hspi1,(uint8_t *)spi_buf, 1, 100);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);
}
}
/* USER CODE END 4 */
Sadly this seems to have no impact. Why does the SCK line change state when it does, why does it bounce, and why doesn't my code prevent it? What should I do to keep the line quiet?