第一次用STM32串口多机通讯,不能成功唤醒,求指教

2019-12-30 19:22发布

原理图就不贴了,就是两片STM32通过485连接,一主一从。设想是子机设定好地址后主机发送地址帧唤醒串口中断,然后接收后面的地址帧。实测发现无法唤醒。求指点原因。
程序如下:

void USART1_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
        /* config USART1 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
        /* USART1 GPIO config */
        /* Configure USART1 Tx (PA.09) as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);   
        /* Configure USART1 Rx (PA.10) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        /* USART1 mode config */
        USART_InitStructure.USART_BaudRate = 115200;
        USART_InitStructure.USART_WordLength = USART_WordLength_9b;//多发送一位,TB9
        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);
       
        USART_ReceiverWakeUpCmd(USART1,ENABLE);//进入静默模式
        USART_WakeUpConfig(USART1,USART_WakeUp_AddressMark);//设置唤醒模式为地址唤醒
       
  /* 使能串口1接收中断 */
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART1, ENABLE);
}
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)//接收中断
{
  ...
  }
}
int main(void)
{
...
  USART1_Config(void)
  USART_SetAddress(USART1,0x03);
...
}

发送部分:
void MasterToSlave_HandShake(unsigned char iSlaveID)
{
RS485BUS_Write;//485总线写状态
MasterToSlaveSendBuff[0]=0x5a;
MasterToSlaveSendBuff[1]=0xa5;
MasterToSlaveSendBuff[2]=4;
MasterToSlaveSendBuff[3]=0x10;
MasterToSlaveSendBuff[4]=0x01;
MasterToSlaveSendBuff[5]=iSlaveID;
MasterToSlaveSendBuff[6]=0x01;
MasterToSlaveSendBuff[7]=0x02;
       
MasterToSlaveSendLength=8;
MasterToSlaveSendCurrentByte=0;
MasterToSlave_SendStatus=MasterToSlave_SendStatus_Sending;
               
  USART_SendData(USART1, (unsigned int)(MasterToSlaveSendBuff[0])|0x0100);//地址帧,TB9=1
  USART_ITConfig(USART1, USART_IT_TC, ENABLE);//开发送中断
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。