中级会员
 
- 积分
- 217
- 金钱
- 217
- 注册时间
- 2012-11-12
- 在线时间
- 0 小时
|

楼主 |
发表于 2013-3-20 09:52:57
|
显示全部楼层
回复【4楼】正点原子:
---------------------------------
是不是串口配置的问题呢,我是直接把f103的串口配置拿过来的,改了一下管脚
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
//串口的IO初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure); //TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure); //RX
//485方向控制
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure); //RX
//USART 初始化设置
USART_InitStructure.USART_BaudRate =9600;//一般设置为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_Cmd(USART2,ENABLE); |
|