硬件平台:
stm32f407+ft232RL
按照手册上的电路,我用USB接口给ft232RL供电,如下图:

我在这个电路的基础上我用单片机串口和芯片对应的TX和RX相连接。
现在单片机上电,ft232不上电,测试的现象如下:
ft232的电源管脚居然有2.6V的电压,也就是说这个电压是由单片机TX引脚倒灌去的。
然后在这个基础上我接上USB,发现电脑警告无法识别。
然后我给单片机断点,直接接上USB,这样ft232就可以正常的被主机检测到了。
但是紧接着又给单片机上电,电脑又会报警无法识别!
下面附上串口配置代码:
- #include <stm32f4xx.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include "SysDebug.h"
- /*
- 功能:串口1IO口初始化
- */
- static void USART1_GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- //打开时钟
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
- //先将对应寄存器配置为缺省值
- GPIO_StructInit(&GPIO_InitStructure);
- //对应,复用、推挽
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
- //复用IO口
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
- //推挽
- GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;//GPIO_OType_OD;//GPIO_OType_PP;
- //带上拉
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- //最大相应速度为50MHZ
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- //将以上设置应用于对应寄存器
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- //对应浮空输入模式
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
- //输入
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
- //浮空
- GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
- //将以上设置应用于对应寄存器
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- //复用功能映射IO
- //注意:不能用|配置多个!!!!!
- GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_USART1);
- GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_USART1);
- }
- /*
- 功能:串口1寄存器配置
- */
- static void USART1_Register_Configuration(void)
- {
- USART_InitTypeDef USART_InitStructure;
- //打开USART1时钟
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- //配置为缺省值
- USART_StructInit(&USART_InitStructure);
- //设置波特率为115200
- USART_InitStructure.USART_BaudRate=115200;
- //传送数据位为8位
- USART_InitStructure.USART_WordLength=USART_WordLength_8b;
- //停止位为1位
- USART_InitStructure.USART_StopBits=USART_StopBits_1;
- //无奇偶校验
- USART_InitStructure.USART_Parity=USART_Parity_No;
- //全双工模式
- USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
- //不采用硬件流
- USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
- //将这些配置对应于USART1
- USART_Init(USART1,&USART_InitStructure);
- //使能串口
- USART_Cmd(USART1,ENABLE);
- }
- /*
- 功能:通信口初始化
- */
- void Com2HostInit(void)
- {
- USART1_GPIO_Configuration();
- USART1_Register_Configuration();
- }
- }
- /*
- 功能:重定向C库函数printf到USART1
- 注意:要在编译器中选中->Use MicroLIB(使用微库)
- 使用:定义好这个函数后,就可以直接使用->printf()函数
- */
- int fputc(int ch,FILE *f)
- {
- //将Printf内容送往串口
- USART_SendData(USART1,(unsigned char)ch);
- //等待发送完成
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
- return (ch);
- }
我试过把TX配置为开漏上拉,这样FT232电源口电压就变为0.8V,但是依然不能被正常识别!
所以现在的问题就是:
在单片机上电,FT232不上电的情况下,单片机串口管脚电压会倒灌到芯片中,并且这个会影响电脑无法识别FT232,
请问该怎么解决?
|