Can you Please Repeat from the Start?
Figure 1. Proof that Raspberry Pi supports Repeated Start conditions (annotated with Green Left Brackets)
I2C is not as straightforward as some people think and there are a couple of wrong assumptions floating out in cyberspace.
Unlike the asynchronous RS-232 protocol where there is always a start bit followed by some payload with optional parity bits and terminated with some stop bits, I2C support transactions that contain multiple Start conditions without corresponding End conditions.
These are known as combined access requests and are typically used for register based devices where a register address is specified followed by a read or write of some data to it.
The lack of End condition before the restart condition is deliberate for a couple of reasons. Firstly it indicates to the device that transaction is still active and secondly stops any other I2C masters from acquiring the I2C bus.
Contrary to many posts out on the Internet the Standard Raspberry Pi I2C driver does support it. It just happens to be disabled by default.
The picture above is taken with the Tektronix TBS1052B-EDU's bigger and older sister the MSO2024 with protocol decoding module.
For I2C it shows start conditions with green left brackets and stop conditions with red right brackets.
The attached figure is configured to show the I2C device address with the R/W bit included.
The 40 (address 0x20 in 7 bit addressing) indicates a write request and the 41 indicates a read request.
The device under test is a MicroChip MCP23017 16-bit IO port expander. It's the I2C version of the MCP23S17.
After installing the appropriate I2C packages on the Raspberry Pi all that is required to get combined access working is to enable it using something like
echo -n 1>/sys/module/i2c_bcm2708/parameters/combined
and optionally configuring the Linux user security to the I2C bus.
To program a combined access sequence using the standard driver, you'll need to construct the desired sequence using an array of i2c_msg structures with a corresponding i2c_rdwr_ioctl_data structure and calling ioctl( <file_descriptor>, I2C_RDWR, &<i2c_rdwr_ioctl_data_structure> )
The i2c_msg structures contain the construction detail of each access component and the i2c_rd_wr_ioctrl structure is used by ioctl() to access the array of i2c_msg structures.