GPIO pin does not stay high
Hi everyone,
I am trying to use CubeMX and the HAL library to get two STM32F411E discovery boards to communicate with each other via SPI. In a first step I am simply trying to configure the master correctly. I want to drive the NSS pin of the slave with a standard GPIO pin from the master and to this end have the following code in the while loop:
while (1)
{
slaveStatus = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4); // check status 1
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET); // activate slave
slaveStatus = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4); // check status 2
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET); // deactivate slave
slaveStatus = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4); // check status 3
}
slaveStatus is set as a global variable so I can monitor its value with breakpoints in the Keil debugger. During the first run through the while loop, everything is fine. The GPIO pin is at first high for check status 1, then low during check status 2, and at the end of the loop high again for check status 3. However, for all subsequent loops slaveStatus will always be 0 for check status 1.
Looking around on different forums for an afternoon I figured that sometimes problems like these are caused because no pull-up / pull-down is configured, but I am fairly certain that this is not my problem. I have tried every possible combination of the GPIO configuration for this pin and even switched to another pin, to no avail. It looks like the pin is brought low between each cycle, but I have no clue why.
Any suggestions as to what I can try to remedy this situation would be much appreciated.
