stm32串口1和串口3数据互通,经测试同时发256字节不丢包
void usart3_init(u32 bound)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // GPIOBʱÖÓ
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); //´®¿Ú3ʱÖÓʹÄÜ
USART_DeInit(USART3); //¸´Î»´®¿Ú3
//USART3_TX PB10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB10
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
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_IN_FLOATING;//¸¡¿ÕÊäÈë
GPIO_Init(GPIOB, &GPIO;_InitStructure); //³õʼ»¯PB11
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 = 2; //×ÓÓÅÏȼ¶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ
NVIC_Init(&NVIC;_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
TIM4_Int_Init(1000-1,7200-1); //10msÖжÏ
USART3_RX_STA=0; //ÇåÁã
TIM_Cmd(TIM4,DISABLE); //¹Ø±Õ¶¨Ê±Æ÷7
}
//´®¿Ú3,printf º¯Êý
//È·±£Ò»´Î·¢ËÍÊý¾Ý²»³¬¹
2021-05-13 14:51:04
9.6MB
数据互通
1