| 
 
| 本文用STM32F0芯片设计485通讯,端口初始化和主程序如下图,此程序为检测程序,编译无误。 int main(void)
 {
 RCC_Configuration();//ʱÖÓ³õʼ»¯SystemInit
 GPIO_Configuration();
 GPIO_SetBits(GPIOB,GPIO_Pin_1);
 USART2_Configuration();
 USART2_NVIC_Config();
 
 while(1)
 {
 GPIO_SetBits(GPIOB,GPIO_Pin_1);
 //        put_c('w');
 //yanshi(1000);//GPIO_SetBits(GPIOB,GPIO_Pin_1);
 }
 
 
 }
 
 void RCC_Configuration(void)
 {
 SystemInit();
 RCC_APB2PeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
 RCC_APB2PeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
 }
 
 void GPIO_Configuration(void)
 {
 GPIO_InitTypeDef GPIO_InitStructure;
 GPIO_InitStructure.GPIO_Pin=hw1|hw2|hw3|hw4|hw5|hw6|hw7|hw8;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOA,&GPIO_InitStructure);
 
 
 
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1;//RE
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOB,&GPIO_InitStructure);
 //        GPIO_SetBits(GPIOB,GPIO_Pin_1);
 
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//TX
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOA,&GPIO_InitStructure);
 
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//RX
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
 //        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 //        GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOA,&GPIO_InitStructure);
 }
 
 void USART2_Configuration(void)
 {
 
 USART_InitTypeDef USART_InitStructure;
 
 USART_InitStructure.USART_BaudRate = 9600;
 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(USART2, &USART_InitStructure);
 
 
 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
 USART_Cmd(USART2, ENABLE);
 USART_ClearFlag(USART2, USART_FLAG_TC);
 }
 
 void USART2_NVIC_Config(void)
 {
 NVIC_InitTypeDef NVIC_InitStructure;
 
 NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
 NVIC_InitStructure.NVIC_IRQChannelPriority=0;
 NVIC_Init(&NVIC_InitStructure);
 
 }
 
 
 不知道什么原因用此方法设计置RE角为高电位时示波器检测反应RE为低 TX常高,不知道是不是设置错误,再次求助,谢谢各位
 
 | 
 |