cancel
Showing results for 
Search instead for 
Did you mean: 

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.

RBrou.1595
Associate

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++;

          }

    }

}

1 ACCEPTED SOLUTION

Accepted Solutions
RBrou.1595
Associate

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;

}

View solution in original post

4 REPLIES 4

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

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

If you want it blocking, make it actually blocking. Agree with everything else.

HAL_UART_Receive(&huart1, RXbuffer, 6, HAL_MAX_DELAY);

If you feel a post has answered your question, please click "Accept as Solution".
RBrou.1595
Associate

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;

}

Piranha
Chief II

For capturing PPS signals better use hardware timer input capture feature.