I want to know if I have this right for the STM32 with the HAL library. I have this working on an Atmega. And Arduino has also a lot more examples to find then STM. So due lack of examples I have wrote this.
1) Set output high
2) When input is low wait till it is high
3) When input is high read 6 characters
4) When having read 6 characters then output low and return
(or leave while loop)
void Get_Instruction()
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET);
while (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11)==0)
{
if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11)==1)
{
for (;;)
{
HAL_UART_Receive(&huart1, RXbuffer, 6, 1000);
}
}
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
return;
}
}
///////////////////////////////////////////////////////////////////////////////////////
Except the input/output this is how I have it with the Atmega.
void ReceiveData()
{
ByteCount = 0;
while (ByteCount <6)
{
if (STM32.available()> 1)
{
ByteData[ByteCount] = (STM32.read());
ByteCount++;
}
}
}