How OTG usb (master / slave) works

The device has usb OTG

Below are the scenarios

  • when the device is connected to a PC, then the device acts as a slave (as the device knows that it must act as a slave)

  • when the device is connected to the printer, then the device acts as a master. (as the device knows that it must act as a master)

what steps are performed when connecting the device to OTG. how to implement this mechanism (in short)?

0
source share
2 answers

The exact behavior of USB OTG devices is described in the specification , which you can find on usb.org. Inside the zip code is called USB_OTG.

The host negotiation protocol in section 6 describes how two OTG devices determine which one receives an embedded host. This is mainly archived by pulling and pushing resistors on the D + line.

Note. When talking about USB, master / slave conditions are not used. The master is called the host and controls the bus, while the slave is called the device. In the case of OTG (in general, see Specification for Exceptions), both parts have the ability to be a host or device. When a host has been defined by a host negotiation protocol, this part becomes the so-called embedded host.

+3
source

In the two scenarios you talked about, a USB device can find out if it should be a host or a device via cable. USB cables (not Type-C) are not balanced. One side is the host and the other is the device. There is a pin on the connector, called an identifier pin, which floats on the device side and is grounded on the host side. This allows the USB controller on each side to know which side of the cable it is connected to, and therefore what role (host or device) it should have when connecting. These types of devices are called dual-user devices.

If you have such a device, you can connect it to ordinary hosts (for example, a laptop), and it will act as a device. And you can connect it to ordinary devices (for example, to a printer), and it will act as a host. All of this is cable based.

If you connect two dual-processor OTG devices to each other. Their initial roles are defined by the cable in the same way.

After defining the initial roles, they can then change roles from their original frame-defined roles using the Host-Negotiation Protocol (HNP).

Regarding the implementation of this. There is no short way to explain this. Each controller is different, and you will need to read the controller database and programming model to implement all of these procedures. They also understand the specifications of USB and OTG well.

A good place to start is http://usb.org , where you can find all the specifications.

+1
source

Source: https://habr.com/ru/post/928113/


All Articles