K
K
Klaxons2015-09-16 14:32:28
C++ / C#
Klaxons, 2015-09-16 14:32:28

How to read and compare data by UART in STM32f4?

Good afternoon, I tied bluetooth to the board and I'm trying to read and compare data through the com port

void UART4_IRQHandler(void)
{
  static int cnt = 0;
  if( USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
  {
    USART_ClearITPendingBit(UART4, USART_IT_RXNE);
    char ch = UART4->DR;
    if(ch != '\n')
    {
        received_str[cnt] = ch;
        cnt++;
    }
    else
    {
      received_str[cnt] = '\0'; 
      cnt = 0;
      if (USART_GetFlagStatus(UART4, USART_FLAG_RXNE)==RESET)
      {
        LED_Flag = 1;
        LED_Command = (int)received_str;
        USART_puts(UART4, LED_Command); // здесь выводит мое введенное число
        USART_puts(UART4, "\n");
      }
    }
  }
}

comparison of received data
main.c
...
while(1)
{
   switch (LED_Command)
   {
     case 500: USART_puts(UART4, "LED_Command = 500"); break;
     case 600: USART_puts(UART4, "LED_Command = 600"); break;
     case 700: USART_puts(UART4, "LED_Command = 700"); break;
   }
}

and the output code
void USART_puts(USART_TypeDef *USARTx, volatile char *str)
{
  while(*str)
  {
    while(USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET);
    USART_SendData(USARTx, *str);
    *str++;
  }
}

When I enter 500, 600 or 700 in the terminal, UART4_IRQHandler displays them correctly, but for some reason in switch it thinks that LED_Command is not equal to these values

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-09-16
@vilgeforce

received_str you have an array of characters? (int)received_str; - never converting a string to a number.

K
Klaxons, 2015-09-16
@Klaxons

And how then to convert to the type int
tried so
in the terminal now it is not clear what is displayedq.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question