我用的原子哥的USART2的485程序修改为USART6的485程序,可是程序执行时,卡死在while(USART_GetFlagStatus(USART6,USART_FLAG_TXE)==RESET); 请问各位老师们,到底是什么原因呢?非常感谢。
下面贴的程序,一个是发送数据的子程序,一个是USART6口设置的子程序,就卡死在发送数据子程序的“while(USART_GetFlagStatus(USART6,USART_FLAG_TXE)==RESET)”语句。
再次非常感谢。
void RS485_1_Send_Data(u8 *buf,u8 len)
{
u8 t;
RS485_1_TX_EN=1; //éèÖÃÎa·¢ËíÄ£ê½
for(t=0;t<len;t++) //Ñ-»··¢Ëíêy¾Y
{
while(USART_GetFlagStatus(USART6,USART_FLAG_TXE)==RESET); //μè′y·¢Ëí½áêø
USART_SendData(USART6,buf[t]); //·¢Ëíêy¾Y
}
while(USART_GetFlagStatus(USART6,USART_FLAG_TC)==RESET); //μè′y·¢Ëí½áêø
RS485_1_RX_CNT=0;
RS485_1_TX_EN=0; //éèÖÃÎa½óêÕÄ£ê½
}
void RS485_1_Init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //ê1ÄüGPIOAê±Öó
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //ê1ÄüGPIOBê±Öó
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //ê1ÄüGPIOBê±Öó
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);//ê1ÄüUSART2ê±Öó
//′®¿ú2òy½Å¸′óÃó3éä
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6); //GPIOA2¸′óÃÎaUSART2
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6); //GPIOA3¸′óÃÎaUSART2
//USART2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOA2óëGPIOA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸′óÃ1|Äü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Ëù¶è100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //éÏà-
GPIO_Init(GPIOC,&GPIO_InitStructure); //3õê¼»ˉPA2£¬
A3
//PB0íÆíìêä3ö£¬485_1Ä£꽿ØÖÆ
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //GPIOB0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//êä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Ëù¶è100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíìêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //éÏà-
GPIO_Init(GPIOC,&GPIO_InitStructure); //3õê¼»ˉPG8
//USART6 3õê¼»ˉéèÖÃ
USART_InitStructure.USART_BaudRate = bound;//2¨ìØÂêéèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö3¤Îa8λêy¾Y¸ñê½
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎTÆæżD£Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //êÕ·¢Ä£ê½
USART_Init(USART6, &USART_InitStructure); //3õê¼»ˉ′®¿ú2
USART_Cmd(USART6, ENABLE); //ê1Äü′®¿ú 2
USART_ClearFlag(USART6, USART_FLAG_TC);
#if EN_USART6_RX
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);//¿aÆô½óêüÖD¶Ï
//Usart2 NVIC ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//ÇàÕ¼óÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷¡¢
#endif
RS485_1_TX_EN=0; //ĬèÏÎa½óêÕÄ£ê½
}
时钟都开错了!!
APB1的时钟开启函数,用来开APB2的外设....
细心点啊。
一周热门 更多>