首先如题
最近在做项目,使用STM32VET6这款芯片,但是在使用USART3的时候遇到了麻烦,使用端口为PD8,9
但是串口发送数据不成功,已经开启AF时钟以及配置完全重映射了,就还是不行,改自原子的HC-05的代码
最后附上代码,求指导
[mw_shl_code=c,true]void usart3_init(u32 bound)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); //
GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);//完全重映射USART3的端口到PD8,9
USART_DeInit(USART3); //????3
//USART3_TX PD9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PD9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //??????
GPIO_Init(GPIOD, &GPIO_InitStructure); //PD9
//USART3_RX PD8
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//PD8
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//????
GPIO_Init(GPIOD, &GPIO_InitStructure); //PD8
USART_InitStructure.USART_BaudRate = bound;//????????9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//???8?????
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_Rx | USART_Mode_Tx; //????
USART_Init(USART3, &USART_InitStructure); //????? 3
USART_Cmd(USART3, ENABLE); //????
//??????
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//????
//???????
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//?????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ????
NVIC_Init(&NVIC_InitStructure); //??????????VIC???
TIM7_Int_Init(99,7199); //10ms??
USART3_RX_STA=0; //??
TIM_Cmd(TIM7,DISABLE); //?????7
}
void u3_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART3_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART3_TX_BUF); //?????????
for(j=0;j<i;j++) //??????
{
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //????,??????
USART_SendData(USART3,USART3_TX_BUF[j]);
}
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>