Lens Serial Interface

Nikon F-mount cameras use a serial protocol to communicate with attached lenses and convey information such as maximum aperture, focal length, rough focus distance setting, and so on.

The pinout can be found on the F-Mount page.

=Electrical Interface= The lens serial interface is a variant of SPI with the following changes:
 * The Slave Select (SS) line is omitted.
 * SO and SI are tied together at each end to form the singular Data line (pin 4 on the F-Mount connector).
 * A handshake line is added. This line is sometimes referred to as R/W or In/Out.

The interface operates at 5V and uses 3 lines: The bus also has a "Power-Down" or "Sleep" state where all three lines are low.

=Protocol= Data is always sent one byte (8 bits) at a time, least significant bit first.

Command Sequence
The camera body always initiates communication by asserting (pulling low) the H/S line for at least 8μs (time based on testing with D5100), then releasing it. The camera then waits for the lens to assert H/S in response, indicating the lens is ready to receive a command. If the lens does not respond within some timeout period, the command is aborted. Otherwise, seeing that the lens is ready, the camera clocks out the command byte. The lens continues to assert H/S throughout reception of the command byte, finally releasing it to acknowledge full receipt of the byte.

A command is only one byte, but may have data following it in either direction. Based on observation, it appears that the amount of data and direction of each data byte is fixed for a given command and is known by the camera and lens ahead of time. In other words, the protocol itself does not convey any information about the length or direction of data bytes.

If a command has associated data, the lens asserts H/S when it is ready to receive or transmit the next byte, releasing H/S to acknowledge completion of the byte just like with the initial command byte. In the case of data from lens to camera, the lens asserts H/S when the next byte to be transmitted is in its output buffer. Likewise, when the lens is receiving data from the camera it asserts H/S when its receive buffer is empty.

Misc Notes
A lens responds to unrecognized commands with a single 0xFF byte.

The camera is able to terminate commands early, such as if only the first few bytes of a lens response are needed, by simply not toggling SCLK after the lens asserts H/S to indicate readiness for the next byte. After some predetermined escape time, the lens MCU will timeout and abort the command, returning to idle state. Provided the escape time is less than the time required to transmit the remaining bytes, this can be used to speed up bus transfers.