void USART2_IRQHandler(void)
{
if(USART_GetITStatus(USART2,USART_IT_RXNE)!=RESET)//½óêÕÖD¶Ï
{
USART_ClearITPendingBit(USART2,USART_IT_RXNE);//Çå3yUSART1ÖD¶Ï′y′|àíλRXNE(RXNE=0)
if(Revcomp_Flag != 1)
{
if(Receive_Num <= 7)//½óêÕ·Ö8×Ö½úêy¾Y oí11×Ö½úêy¾Y
{
Receive_Buff[Receive_Num] = USART1->DR;
Receive_Num++;
TIM_Cmd(TIM2, ENABLE);
TIM_SetCounter(TIM2, 0);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
}
}
//òç3ö-èç1û·¢éúòç3öDèòaÏèÇå¿ÕSRμÄòç3öλ,Ôù¶áDR¼Ä′æÆ÷ Ôò¿éÇå3y2»¶ÏèëÖD¶ÏμÄÎêìa
if(USART_GetFlagStatus(USART2,USART_FLAG_ORE)!=RESET)
{
USART_ClearFlag(USART2,USART_FLAG_ORE); //Çåòç3öλ
USART_ReceiveData(USART2); //¶áDR
}
}
void Modbus_SendData()
{
uint8_t i=0;
u8 res;
GPIO_SetBits(GPIOD,GPIO_Pin_7);//ÇD»»Îa·¢ËíÄ£ê½
for(i=0;i<=7;i++)
{
res = Receive_Buff[i];
// USART_SendData(USART2,Receive_Num);
USART_SendData(USART2,res);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);//μè′y·¢Ëííê3é
}
GPIO_ResetBits(GPIOD,GPIO_Pin_7); //ĬèÏÎa½óêÕÄ£ê½
}
int main(void)
{
LED_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
USART2_Init();
TIM3_Init();
while (1)
{
while (Revcomp_Flag == 1)
{
Revcomp_Flag = 0x00;//½óêÕò»Ö¡êy¾Y±êÖ¾Çåáã
Modbus_SendData();
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//ÔêDí½óêÕÖD¶Ï
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>