代码烧录以后串口助手发送十个A能让电平翻转接受发送的十个A,输入其他的字符不能翻转但是能接受发送的字符,但是输入十个B以后串口助手不能接受到数据,并且以后发送任何字符都收不到数据了(十个A也不能翻转电平),我一步一步试过,只要这个if里面出现printf就会发生这种现象,其他地方都没问题。
#include "main.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
#include "string.h"
#include "stdio.h"
COLOR_RGBC rgb;
COLOR_HSL hsl;
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
uint8_t TCS34725_GetRawData(COLOR_RGBC *rgbc);
uint8_t TCS34725_Init(void);
uint8_t aTxBuffer[] = "HelloWorld";
uint8_t A[]={"AAAAAAAAAA"};
uint8_t B[]={"BBBBBBBBBB"};
int n,t;
#define COUNTOF(__BUFFER__) (sizeof(__BUFFER__) / sizeof(*(__BUFFER__)))
#define TXBUFFERSIZE (COUNTOF(aTxBuffer) - 1)//
/* Size of Reception buffer */
#define RXBUFFERSIZE TXBUFFERSIZE uint8_t aRxBuffer[RXBUFFERSIZE];//
__IO ITStatus UartReady = RESET;//
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
UartReady=SET;//
}
//
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
n=memcmp(B,aRxBuffer, sizeof(B));
t=memcmp(A,aRxBuffer, sizeof(A));
if(n==0)
{
printf("R=%d G=%d B=%d C=%d\r\n", rgb.r, rgb.g, rgb.b, rgb.c);
HAL_Delay(1000);
}
else if(t==0)
{
TCS34725_GetRawData(&rgb);
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_1|GPIO_PIN_2);
}
else {}
UartReady=SET;
//
}