调试过程中突然需要在添加一个串口,所以就根据已经可以用的串口1,复制进行修改代码如下,加入串口2的初始化原本的FSMC总线直接不行,就把FSMC初始化改到在串口2之前初始化,FSMC正常,但现在串口2一点反应都没有,FSMC与串口2(PA2,PA3)会不会出现冲突问题,求知道的人指点,谢谢了!
/* Uart 2 Modbus */
static void Usart2Init(u32 Baudrate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Clk */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Gpio Cfg */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
GPIO_StructInit(&GPIO_InitStructure); //缺省值填入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Nvic Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Uart Cfg */
USART_InitStructure.USART_BaudRate = Baudrate;//波特率设置
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_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
/* Enable Uart */
USART_Cmd(USART2, ENABLE);
USART_ClearFlag(USART2, USART_FLAG_TC);
/* Enable Uart Int */
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
}
GLOBAL void Usart2Send(char send_data)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2,send_data);
}
void USART2_IRQHandler(void)
{ //定义字符变量
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //判断发生接收中断
{
USART_ClearITPendingBit(USART2, USART_IT_RXNE); //清除中断标志
MbsRtuRxdISR(1,USART_ReceiveData(USART2)&0xFF); //modbus接收解析函数
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
复制粘帖一不小心就中招了啊,这种问题怎么能更好的避免呢
一周热门 更多>