2020-10-30 03:28 PM
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++;
}
}
}
Solved! Go to Solution.
2020-10-31 06:32 PM
Thank you both. It is working now like I ment.
Using the same kind of routine for 'wait till input is high' (don't know why, but inputs are inverted detected).
void Get1PPS()
while (PPSstate == 1)
{
PPSstate = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_15);
{
if (PPSstate == 0)
{
return; // just exit the loop
}
}
}
PPSstate = 1;
}
2020-10-30 05:52 PM
Ignore the fact there's not a exact example to copy, the loop logic is very confused. It is more likely to exit the loop than it is to wait for the input data.
The equivalent to your ReceiveData() is simply HAL_UART_Receive(&huart1, RXbuffer, 6, 1000), perhaps might want to push the time out further.
This is more like what you actually described
void Get_Instruction()
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_SET); // Pin out high
while (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11)==0) {}; // Wait while low
HAL_UART_Receive(&huart1, RXbuffer, 6, 100000); // Collect 6 characters, blocking
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); // Pin out low
}
2020-10-30 06:46 PM
If you want it blocking, make it actually blocking. Agree with everything else.
HAL_UART_Receive(&huart1, RXbuffer, 6, HAL_MAX_DELAY);
2020-10-31 06:32 PM
Thank you both. It is working now like I ment.
Using the same kind of routine for 'wait till input is high' (don't know why, but inputs are inverted detected).
void Get1PPS()
while (PPSstate == 1)
{
PPSstate = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_15);
{
if (PPSstate == 0)
{
return; // just exit the loop
}
}
}
PPSstate = 1;
}
2020-11-06 12:31 PM
For capturing PPS signals better use hardware timer input capture feature.