你的浏览器版本过低,可能导致网站不能正常访问!为了你能正常使用网站功能,请使用这些浏览器。
举报
zfz0122 发表于 2015-3-20 09:04 板子上的串口位置换了,就把串口换了一下,??没懂
安 发表于 2015-3-20 14:26 RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); 楼主,你看一下这个配置。
安 发表于 2015-3-20 11:17 楼主串口1用的还是PA9 PA10吗?
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
Uart1Conf.RXpoint = 0;
Uart1Conf.RXStart = Uart1Conf.RXpoint;
Uart1Conf.RXlenth = 0;
Uart1Conf.TXlenth = 0;
Uart1Conf.Time = 0;
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ
USART_InitStructure.USART_BaudRate = 38400;
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(USART1, &USART_InitStructure);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
//Configure the USART1_Tx PA9 as Alternate function Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Configure the USART1_Rx PA10 as input power-UP
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
// Configure the RS485DoutEN PA11 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN;
GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
// Configure the RS485RecvEN PA12 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN;
GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);
RS485DoutDIS(); // ½ûÖ¹·¢ËÍ
RS485RecvEN(); // ½ÓÊÕʹÄÜ
// Enable USART1 Receive interrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmpt interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendComplete interrupts
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
// Enable the USART1
USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ
// Enable the USART1 Interrupt
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // USART1ʱÖÓʹÄÜ
USART_InitStructure.USART_BaudRate = 38400;
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(USART1, &USART_InitStructure);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
//Configure the USART1_Tx PA9 as Alternate function Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Configure the USART1_Rx PA10 as input power-UP
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RS485OUTEN_GPIO_CLK | RS485INEN_GPIO_CLK,ENABLE); // I/O¶Ë¿ÚAʱÖÓʹÄÜ
// Configure the RS485DoutEN PA11 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485OUTEN_PIN;
GPIO_Init(RS485OUTEN_GPIO_PORT, &GPIO_InitStructure);
// Configure the RS485RecvEN PA12 as out Push-Pull
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = RS485INEN_PIN;
GPIO_Init(RS485INEN_GPIO_PORT, &GPIO_InitStructure);
RS485DoutDIS(); // ½ûÖ¹·¢ËÍ
RS485RecvEN(); // ½ÓÊÕʹÄÜ
// Enable USART1 Receive interrupts
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
// DisEnable USART1 SendEmpt interrupts
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
// DisEnable USART1 SendComplete interrupts
USART_ITConfig(USART1, USART_IT_TC, DISABLE);
// USART_ClearFlag(USART1,USART_FLAG_TC); // ·ÀÖ¹ÎÞ·¨Êä³ö¸´Î»ºóµÄÊ××Ö·û£¬Õâ¸ö¹¦ÄÜû·¨ÑéÖ¤
// Enable the USART1
USART_Cmd(USART1, ENABLE); // USART1ʹÄÜ
// Enable the USART1 Interrupt
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
原来用着好好的啊 就是换了一下顺序
串口如果想要发送数据的话 除了允许发送,打开串口 还需要别的不
原来用串口1实现功能1,串口2实现功能2,串口3实现功能3
换板子以后,用串口1实现功能3,串口3实现功能1,每个串口的引脚也有变化
恩恩 太马虎了 谢谢
嗯 是的 引脚可以确认是对的
楼主,你看一下这个配置。