USB - BC1.2检测

如何把USB的D+/D-同时接到Charge IC和HOST IC上?

这个问题,一般是因为HOST IC不支持BC 1.2,需要charge IC来支持。否则的话,可以HOST IC判断出BC 1.2后,再控制charge IC即可。

在TI的网站论坛上,查询到了一个技术回复。

1,Charge ID和HOST ID一起直接连到USB接口上,共享D+/D-。

BQ24253: D+D- connection mode - Power management forum - Power management - TI E2E support forums

BQ25629: USB D+/D- connection and BC1.2 charger detection - Power management forum - Power management - TI E2E support forums

BQ25601D: Does D+/D- detection interfere with USB communication over D+/D- - Power management forum - Power management - TI E2E support forums

BQ25895M: BQ25895M & D+ D- & MCU - Power management forum - Power management - TI E2E support forums

当不需要 D+/D- 引脚进行输入限流检测时,充电芯片将 HIZ D+/D- 引脚,以便其他设备可以驱动 D+/D- 引脚。

The charger will HIZ D+/D- pins when D+/D- pins are not needed for input current limit detection so that other devices may drive D+/D- pins. 

[BQ25629]

请问主机需要在 HIZ 中保持 D+/D- 多长时间才能完成检测过程?

是否有办法在检测完成时检查 bq25629 的寄存器?

Please advise how long does the host need to keep the D+/D- in HIZ for the detection process to complete?

Is there a way to check on bq25629's register when the detection is done?

输入源类型检测完成后,VBUS_STAT 位将被更新,以显示检测到的输入源类型。请同时使用 VBUS_STAT 位(REGx1E[2:0])和 VBUS_FLAG(REGx21[0])来检查检测是否完成。

Upon the completion of input source type detection, VBUS_STAT bits are updated to indicate the detected input source type. Please use VBUS_STAT bits (REGx1E[2:0]) and VBUS_FLAG (REGx21[0]) together to check if the detection is completed.

[ BQ25601D ]

您能告诉我在 uC 开始使用线路之前,D+/D- 必须保持 HiZ 状态多长时间吗?

Can you tell me how long the D+/D- must stay in HiZ state until the uC can start with using the line?   (uC = uController)

输入 DPDM 检测取决于输入源类型。为了安全起见,最好在输入源插入后至少等待 1 秒钟,或者监控下面的位。

The input DPDM detection is dependent on the input source type. To be safe, it is better to wait at least 1 second after an input source plugs in or monitor the bits below.

[ BQ24253 ]

如果我用 USB 给 BQ24253 供电,同时需要 USB 传输数据,是否必须确保 USD 的 D+D- 和 BQ24253 的 D+D- 始终保持连接?在此前提下,BC1.2 检测是在开机后立即进行的,检测完成后,D+D- 就可以正常用于数据传输了,对吗?

If I use USB to power BQ24253 and simultaneously need USB to transfer data, do I have to ensure that USD's D+D- and BQ24253's D+D- are always connected? Under such a premise, BC1.2 detection is carried out right after power-on, and after the detection is completed, D+D- can be used normally for data transmission, right?

充电器仅在首次开机后的 1.5 秒内使用 D+/D- 线路。 之后,D+/D- 引脚将变为高阻抗。

The charger only uses the D+/D- lines for the first 1.5 seconds after initial power up.  After that time, the D+/D- pins go high impedance.

[ BQ25895 ]

在一般应用中,大多数客户会将 BQ25895 的 D+/D- 引脚与 MCU 的 D+/D- 引脚相连。

对于 BQ25895,D+/D- 引脚在完成输入电源检测后将断开。

In general application, most customers will connect BQ25895 D+/D- pins with MCU D+/D- pins.

For BQ25895 D+/D- pin will be open after it finished input power source detection.

2,  使用可以转接D+/D-信号的Charge IC。

TPS25762-Q1: Query regarding BC1.2 and D+, D- - Power management forum - Power management - TI E2E support forums

BQ25895M: BQ25895M & D+ D- & MCU - Power management forum - Power management - TI E2E support forums

如果HOST IC没有集成BC1.2的控制器,那charge IC可以选择TPS254900A-Q1.

Product page:

TPS254900A-Q1 data sheet, product information and support | TI.com

USB的D+/D-,输入到charge IC,然后再输出,可以接到HOST IC上。

3,使用USB switch开关(external multiplexer)来隔离Charge IC和HOST IC的D+/D-,避免互相影响。

BQ25629: USB D+/D- connection and BC1.2 charger detection - Power management forum - Power management - TI E2E support forums

BQ24295: Help with BQ24295 USB Data Lines, PMID Capacitance - Power management forum - Power management - TI E2E support forums

BQ25886: D+/D- and USB line - Power management forum - Power management - TI E2E support forums

当插入 VBUS 电源时,D+/D- 引脚用于 USB 输入限流检测。在充电器输入限流检测过程中,主机必须能够 HIZ D+/D- 引脚,以便 D+/D- 引脚由充电器驱动。如果主机无法 HIZ D+/D- 引脚,则需要一个 USB 开关来隔离主机和充电器的 D+/D- 引脚。

D+/D- pins are used for USB input current limit detection when VBUS power is plugged in. During the charger input current limit detection process, the host must be able to HIZ D+/D- pins so that D+/D- pins are driven by the charger. If the host is unable to HIZ D+/D- pins, a USB switch is needed to isolate the D+/D- pins of the host and the charger.

只有在插入 VBUS 输入源的第一秒内,D+/D- 线路上的设备能保持高阻抗时,才可以在 D+/D- 线路上连接设备。在此期间,充电器将执行 USB BC1.2 检测,以确定输入电流限制。之后,设备可能会接管 D+/D- 线路。如果该设备不能做到这一点,我建议使用 MCU 控制的 USB 开关。

Attaching a device on the D+/D- lines is only acceptable if that device can keep the D+/D- line high impedance for the first second when the input source on VBUS is plugged in. During this time, the charger will perform the USB BC1.2 detection to determine the input current limit. After that, the device may take over the D+/D- lines. If this device does not do this, I would suggesting utilizing a USB switch with MCU control.

你能说出一个可以用于此目的的 USB 开关吗?Can you name an USB switch that could be used for that purpose?

建议的USB开关(USB mux),TS3USB221A,TS3USB221A data sheet, product information and support | TI.com

[ BQ25895 ]

D+/D- 连接有两种解决方案。一种是如上所述直接连接在一起。另一种是使用外部多路复用器。但是,即使 BQ25895M 开启了 D+/D- 引脚,但仍有少量电容会影响 D+/D- 信号质量。因此,有些客户会使用外部多路复用器来改善 D+/D- 信号质量。

There are two solutions for D+/D- connection. One is directly connected together as mentioned above. The other is using external multiplexer. But even BQ25895M open D+/D- pin but there still has few capacitance to impact D+/D- signal quality. So some customers will use external multiplexer to improve D+/D- signal quality.

您可以使用 BQ25895M 的 DESL 引脚(引脚 24)来控制该多路复用器。通过 10-KΩ 电阻器将 DSEL 连接到逻辑轨。该引脚通常为浮动引脚,通过外部电阻上拉。在输入源类型检测期间,该引脚驱动低电平,表示设备正在进行 D+/D- 检测,需要控制 D+、D- 信号。检测完成后,当检测到 MaxCharge™ 适配器时,该引脚保持低电平。检测到其他输入源类型时,该引脚返回浮动状态,并通过外部电阻拉高。

And you can use BQ25895M's DESL pin (pin24) to control this multiplexer. Connect the DSEL to a logic rail via 10-KΩ resistor. The pin is normally float and pull-up by external resistor. During Input Source Type Detection , the pin drives low to indicate the device D+/D- detection is in progress and needs to take control of D+, D- signals. When detection is completed, the pin keeps low when MaxCharge™ adapter is detected. The pin returns to float and pulls high by external resistor when other input source type is detected.

[ BQ25886 ]

如果有主机共享 D+/D- 线路,则需要在主机上使用多路复用器或软件延迟,以便首先进行检测。检测大约需要 1 秒钟。D+/D- 检测流程完成后,D+ 和 D- 引脚将变为 HIZ。

If there is a host sharing the D+/D- line you will need to use the MUX or a software delay on the host to allow for the detection to occur first. The detection takes approximately 1 second. After the D+/D- detection flow is complete, the D+ and D- pins will go HIZ.

下面几个链接是重复信息:

BQ25620: D+ D- with USB MCU? - Power management forum - Power management - TI E2E support forums

BQ25600D: D+/D- connection - Power management forum - Power management - TI E2E support forums

4,实际案例分析

Host IC: i.MX25

Charge IC: BQ24251

USB Switch: WAS7227Q

a. 硬件设计上,USB connector的D+/D- 同时接到charge IC和USB switch的输入。Host IC的USB接口接到USB Switch的一路D+/D-输出上。

b. 软件设计上,上电后,USB switch默认是关闭的。当Charge IC检测到USB插入,并且Input Source type detect结束后,再根据情况,如果是SDP或CDP,就打开USB switch的一路通道,使Host IC的USB连接到USB接口。如果是DCP或其他情况,就保持USB switch关闭。

c. 为了最大化保证USB通信,可以在USB DCP情况下,也打开USB Switch,并等待一段时间,再检查USB是否有通讯。如果没有通讯,表示USB通讯功能不可用,再关闭USB Switch。

USB连接器接入Charge IC的D+/D-,由Charge IC来负责检测是否有USB设备插入,然后再去操作USB Switch。

Charge IC检测完input source之后会将D+/D-设置为高阻态,不会影响USB通信。

5,USB Switch: WAS7227Q

USB High speed (480Mbps), DPDT Analog Switch。

WAS7227Q 是一款高性能、双刀双掷 (DPDT) CMOS 模拟开关,采用 +2.5V 至 +5.5V 单电源供电。

The WAS7227Q is a high performance, double pole double throw (DPDT) CMOS analog switch that operates from a single +2.5V to +5.5V power supply.

WAS7227Q 专为手机和消费类应用中高速 USB2.0 信号的开关而设计,如手机、数码相机,以及配备集线器或USB控制器, 但USBI/O 数量有限的笔记本电脑。

The WAS7227Q is designed for switching of high-speed USB2.0 signals in handset and consumer applications, such as cell phones, digital cameras, and notebooks with hubs or controllers with limited USB I/Os.

WAS7227Q 采用 QFN1418-10L 封装。标准产品为无铅和 无卤素。

The WAS7227Q is available in QFN1418-10L package. Standard products are Pb-Free and halogen-Free.

Pin descriptions

Function descriptions

Logic symbol and typical applications

控制输入必须保持高电平或低电平,不得悬空。

Control input must be held high or Low, it must not float

6,支持BC 1.2的Host IC

在使用Ingenic的X1600芯片时,Linux kernel里的kernel\drivers\usb\common\common.c,包含了BC 1.2的功能。

static const char *const power_names[] = {

    [USB_POWER_UNKNOWN] = "UNKNOWN",

    [USB_POWER_SDP] = "Standard Downstream Port",

    [USB_POWER_DCP] = "Dedicated Charging Port",

    [USB_POWER_CDP] = "Charging Downstream Port",

};

const char *usb_power_string(enum usb_device_power type)

{

    if (type < 0 || type >= ARRAY_SIZE(power_names))

        type = USB_POWER_UNKNOWN;

    return power_names[type];

}

EXPORT_SYMBOL_GPL(usb_power_string);

代码里判断是否支持BC 1.2:

if(system("grep -E 'Dedicated Charging Port|Charging Downstream Port' /sys/class/udc/13500000.otg/power_type >/dev/null") == 0)

    return true;

而Freescale的i.MX25、i.MX6UL(L)和i.MX93里就没有BC 1.2的功能。

<think>好的,我现在需要帮助用户分析为什么他们的代码存在冲突。首先,用户提供的代码是关于电机控制的,特别是步进电机的驱动。用户提到“与这串代码冲突了”,但并没有具体说明冲突的表现是什么,比如编译错误、运行时错误,还是电机运转不正常。因此,我需要先通过代码分析可能的问题点。 首先,我看看代码结构。Motor_GPIO_Init函数初始化了GPIO引脚,包括GPIOA的5、6、7脚和GPIOC的4脚,设置为推挽输出。这应该是用来控制步进电机的四个相位。 然后是Motor_one函数,这个函数接收一个速度参数,通过依次设置不同的引脚高低电平来驱动电机。每次设置后有一个delay_ms(speed)的延时。看起来像是四相步进电机的单相励磁驱动方式,每个相位依次激活,间隔由speed控制,speed越大,延时越长,电机转速越慢。 但有几个可能的问题点: 1. **GPIO配置冲突**:检查是否有其他部分的代码使用了相同的GPIO引脚,导致多个地方同时控制同一引脚,产生冲突。比如,如果其他模块或函数也初始化或操作了PA5、PA6、PA7或PC4,就会导致电平状态异常。 2. **延时函数的影响**:delay_ms函数如果在中断中被调用,或者在多任务环境中使用,可能会导致系统阻塞,影响其他任务的执行。如果系统中还有其他需要及时响应的操作,长时间延时可能导致系统不响应。 3. **电机驱动逻辑问题**:Motor_one函数中的驱动顺序是否正确?四相步进电机通常需要按照特定的相位顺序来转动,比如单相八拍或双相四拍。当前的驱动顺序是否会导致电机振动而不转动?例如,是否每个相位切换的时间间隔不合适,或者相位顺序错误。 4. **speed参数的使用**:delay_ms(speed)中的speed参数是否合理?如果speed太小,可能导致电机无法正确响应;如果speed太大,电机转动会非常慢。另外,是否有其他地方修改了speed变量,导致意外行为? 5. **硬件连接问题**:虽然代码本身可能没有问题,但硬件连接错误,如引脚连接错误、驱动电路(如ULN2003)故障,电源不足等,都可能导致电机不转或表现异常。 6. **缺少HAL库初始化**:代码中使用了HAL_GPIO函数,但主函数中是否初始化了HAL库?比如没有调用HAL_Init()或系统时钟配置不正确,导致GPIO无法正常工作。 7. **重复初始化GPIO**:如果其他地方也调用了Motor_GPIO_Init,或者在初始化之前已经配置了这些引脚,可能会导致配置冲突。 接下来,我需要考虑用户可能的冲突表现。例如,编译错误的话,可能包含头文件路径错误,或者函数重复定义。如果是运行时问题,比如电机不动或抖动,可能是驱动逻辑或延时问题。用户需要提供更多信息,但根据现有代码,可以推测常见问题。 例如,在Motor_one函数中,每次设置一个引脚为高,其他为低,然后延时。但最后一个阶段设置的是PC4为高,其他为低。如果电机是四相的,可能需要循环四个相位,但这里第四个相位可能对应PC4,而前三相是PA5、6、7。这样的配置是否正确?可能电机的四相需要按顺序激活PA5、PA6、PA7、PC4,但硬件连接是否正确? 另外,每次切换相位后,是否应该保持一段时间的高电平?比如,是否应该将delay_ms放在每个相位激活之后,而不是立即改变?或者延时时间是否过短,导致电机无法响应? 还有,可能用户同时调用了Motor_one和其他电机控制函数,导致GPIO状态冲突。例如,在多个地方同时设置同一引脚,导致电平混乱。 总结可能的问题点,我需要逐步列出这些可能性,并建议用户逐一排查,比如检查硬件连接、确认GPIO没有冲突、验证驱动顺序和延时是否正确,以及是否有其他代码影响。</think>根据代码分析,可能存在的冲突原因及解决方案如下: $$冲突原因分析$$ 1. **GPIO引脚冲突** $•$ 检查GPIOA(5/6/7)和GPIOC4是否被其他外设复用 $•$ 确认没有重复初始化这些引脚(如多个模块同时配置同一引脚) $•$ 使用STM32CubeMX工具验证引脚分配 2. **时序控制异常** $•$ `delay_ms(speed)`在中断服务函数中调用会导致系统阻塞 $•$ 若speed值过小(<5ms)可能导致步进电机失步 $•$ 建议改用定时器PWM控制相位时序: $$定时器配置公式:ARR = \frac{T_{clk}}{Prescaler \times f_{step}} - 1$$ 3. **相位驱动顺序问题** 当前单相励磁时序表: | 步序 | PA5 | PA6 | PA7 | PC4 | |-----|-----|-----|-----|-----| | 1 | 1 | 0 | 0 | 0 | | 2 | 0 | 1 | 0 | 0 | | 3 | 0 | 0 | 1 | 0 | | 4 | 0 | 0 | 0 | 1 | $→$ 建议改用双相励磁提高扭矩: `1-2相励磁模式:A-AB-B-BC-C-CD-D-DA` 4. **硬件驱动能力不足** $•$ 检查是否使用电机驱动芯片(如ULN2003) $•$ 测量GPIO输出电压是否满足电机工作电压 $•$ 添加续流二极管防止反电动势损坏MCU $$推荐改进方案$$ ```c // 使用定时器实现阶梯式加速控制 void Motor_SmoothRun(int target_speed) { const uint8_t ACCEL_STEPS = 20; // 加速步数 uint16_t base_delay = 100; // 初始延时(ms) float accel_rate = (base_delay - target_speed)/(float)ACCEL_STEPS; for(int i=0; i<ACCEL_STEPS; i++){ Motor_one(base_delay - (int)(i*accel_rate)); } // 保持匀速运行 while(1) { Motor_one(target_speed); } } ``` **验证步骤**: 1. 使用逻辑分析仪抓取GPIO波形 2. 测量电机相电流(正常范围:50-800mA) 3. 检查供电电源稳定性(建议增加1000μF滤波电容) 若问题仍未解决,请提供: $•$ 原理图中电机驱动部分电路 $•$ 电机型号参数(步距角/相电阻/额定电流) $•$ 实际运行时GPIO的波形图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值