佚名通过本文主要向大家介绍了stm32usart,解析程序包时出现问题,解析程序包出现问题,程序出现一个问题,此程序存在兼容性问题等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: stm32USART问题:程序如下,问题是接收不到数据
描述:
#include "usart1.h"
void USART1_Config(void);
int main(void)
{
uint8_t text[26]="abcdefghijklmnopqrstuvwxyz";
uint8_t i;
USART1_Config();
for(i=0;i<26;i++)
{
USART_SendData(USART1,(uint16_t)text[i]);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
;
}
}
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 ; //pin9 is tx
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_Init (GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 ;//pin10 is rx
GPIO_Init (GPIOA, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1,&USART_InitStruct);
USART_Cmd (USART1,ENABLE);
}
描述:
stm32单片机c语言
#include "stm32f10x.h"#include "usart1.h"
void USART1_Config(void);
int main(void)
{
uint8_t text[26]="abcdefghijklmnopqrstuvwxyz";
uint8_t i;
USART1_Config();
for(i=0;i<26;i++)
{
USART_SendData(USART1,(uint16_t)text[i]);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
;
}
}
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1, ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP ;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 ; //pin9 is tx
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_Init (GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10 ;//pin10 is rx
GPIO_Init (GPIOA, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 115200;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1,&USART_InitStruct);
USART_Cmd (USART1,ENABLE);
}