初级会员

- 积分
- 79
- 金钱
- 79
- 注册时间
- 2018-4-9
- 在线时间
- 27 小时
|

楼主 |
发表于 2018-9-12 11:22:37
|
显示全部楼层
这是照抄原子哥你裸机485通信的配置,用了2个串口,串口1正常,串口2只能发,不能收,不知道问题出在什么地方啦,加上操作系统,我是不是要修改ucos里面的配置
void RS485_Init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD, ENABLE);//ê1ÄüGPIOA,Dê±Öó
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);//ê1ÄüUSART2ê±Öó
USART_DeInit(USART2); //¸′λ′®¿ú1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //PD7¶Ë¿úÅäÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //íÆíìêä3ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸′óÃíÆíì
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //¸¡¿Õêäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,ENABLE);//¸′λ′®¿ú2
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2,DISABLE);//í£Ö1¸′λ
#ifdef EN_USART2_RX //èç1ûê1Äüá˽óêÕ
USART_InitStructure.USART_BaudRate = bound;//2¨ìØÂêéèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8λêy¾Y3¤¶è
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;///ÆæÅ¼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(USART2, &USART_InitStructure); ; //3õê¼»ˉ′®¿ú
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; //ê1Äü′®¿ú2ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //ÏèÕ¼óÅÏè¼¶2¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //′óóÅÏè¼¶2¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//¿aÆôÖD¶Ï
USART_Cmd(USART2, ENABLE); //ê1Äü′®¿ú
#endif
RS485_TX_EN=0; //ĬèÏÎa½óêÕÄ£ê½
} |
|