標(biāo)題:
STM32使用USART1沒什么問(wèn)題,使用USART3就是搞不出來(lái) 也不知程序哪里錯(cuò)了
[打印本頁(yè)]
作者:
zhangpeng12345
時(shí)間:
2021-11-4 10:47
標(biāo)題:
STM32使用USART1沒什么問(wèn)題,使用USART3就是搞不出來(lái) 也不知程序哪里錯(cuò)了
求一個(gè)stm32f103rct6使用USART3收發(fā)數(shù)據(jù)的歷程,不勝感激!!!
void USART3_init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //??USART3,GPIOB??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //??USART3,GPIOB??
USART_DeInit(USART3); //????3
//USART3_TX PB10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //??????
GPIO_Init(GPIOB, &GPIO_InitStructure); //???Pb10
//USART3_RX PB11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//????
GPIO_Init(GPIOB, &GPIO_InitStructure); //???PB11
//Usart1 NVIC ??
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//?????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ????
NVIC_Init(&NVIC_InitStructure); //??????????VIC???
//USART ?????
USART_InitStructure.USART_BaudRate = bound;//?????115200;
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); //?????
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//??USART3????
USART_Cmd(USART3, ENABLE); //????
}
作者:
黃youhui
時(shí)間:
2021-11-5 11:08
USART3_RX引腳沒有復(fù)用
51hei截圖20211105110814.png
(96.99 KB, 下載次數(shù): 74)
下載附件
2021-11-5 11:08 上傳
作者:
AUG
時(shí)間:
2021-11-5 14:06
去找原子或者野火的demo自己搗鼓他們的USART1的初始化就知道了,或者百度隨便找個(gè)例程也很多,對(duì)比下就知道了。
作者:
zyluglugl
時(shí)間:
2021-11-8 06:36
我在工程應(yīng)用的初始化函數(shù)給你:2樓是正解,學(xué)習(xí)了:
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* 使能 USART3 時(shí)鐘*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能外設(shè)時(shí)鐘
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USART3 使用IO端口配置 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //復(fù)用推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空輸入
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOA
/* USART3 工作模式配置 */
USART_InitStructure.USART_BaudRate = 19200; //波特率設(shè)置:19200 步進(jìn)電機(jī)的通訊率
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //數(shù)據(jù)位數(shù)設(shè)置:8位
USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位設(shè)置:1位
USART_InitStructure.USART_Parity = USART_Parity_No ; //是否奇偶校驗(yàn):無(wú)
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //硬件流控制模式設(shè)置:沒有使能
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//接收與發(fā)送都使能
USART_Init(USART3, &USART_InitStructure); //初始化USART3
/*使能串口3的發(fā)送和接收中斷*/
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);// USART3使能
}
作者:
plb1213
時(shí)間:
2021-11-27 18:49
這樣改行不行
void USART3_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* 使能 USART3 時(shí)鐘*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能外設(shè)時(shí)鐘
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USART3 使用IO端口配置 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //復(fù)用推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空輸入
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOA
/* USART3 工作模式配置 */
USART_InitStructure.USART_BaudRate = 19200; //波特率設(shè)置:19200 步進(jìn)電機(jī)的通訊率
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //數(shù)據(jù)位數(shù)設(shè)置:8位
USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位設(shè)置:1位
USART_InitStructure.USART_Parity = USART_Parity_No ; //是否奇偶校驗(yàn):無(wú)
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //硬件流控制模式設(shè)置:沒有使能
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//接收與發(fā)送都使能
USART_Init(USART3, &USART_InitStructure); //初始化USART3
/*使能串口3的發(fā)送和接收中斷*/
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
USART_Cmd(USART3, ENABLE);// USART3使能
}
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1