Answer the question
In order to leave comments, you need to log in
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");
}
}
}
}
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;
}
}
void USART_puts(USART_TypeDef *USARTx, volatile char *str)
{
while(*str)
{
while(USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET);
USART_SendData(USARTx, *str);
*str++;
}
}
Answer the question
In order to leave comments, you need to log in
received_str you have an array of characters? (int)received_str; - never converting a string to a number.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question