再利用串口向上位机发送数据时,会自己加一个问号,怎么解决?求助
1
下面是程序
- void USART1_Init(void)
- {
- USART_InitTypeDef USART_InitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
-
- USART_InitStructure.USART_BaudRate = 115200;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Tx;
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
- USART_Init(USART1,&USART_InitStructure);
- USART_Cmd(USART1, ENABLE);
-
- USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
- }
- void USART_SendString(USART_TypeDef* USARTx,char *string)
- {
- uint8_t i=0;
- while(string[i]!='\0')
- {
- USART_SendData(USARTx,string[i]);
- while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET){}
- i++;
- }
- }
- int main(void)
- {
- char a[4]={'a',' ','b',' '}
- USART1_Init();
- while(1)
- {
- delay_ms(300);
- USART_SendString(USART1,a);
- }
- }
复制代码
|