Resources » Pololu Wixel User's Guide » 9. Wixel Apps »9.g. Serial-to-I²C AppOverviewThis app turns a Wixel into a serial-to-I²C bridge, acting as a master controller on a single-master I²C bus. To perform I²C operations, another device can issue serial ASCII commands to the Wixel on its radio, UART, or USB interface. I²C is a two-wire interface that is commonly used for communications on peripherals like the LSM303DLHC compass and the BMP085 pressure sensor. The official specification (371k pdf) for the I²C bus is published by NXP. Installation InstructionsDownload Serial-to-I²C App 1.0 (26k wxl). Open it with the Wixel Configuration Utility, choose your parameters, and then write it to a Wixel. See Section 4 for more information on how this is done. Default Pinout
DescriptionThis device appears to the USB host as a Virtual COM Port (with USB product ID 0x2200). If you are using Windows, you should see an entry labeled “Wixel” in your Device Manager in the “Ports (COM & LPT)” category while the app is running. There are three basic bridge modes that can be selected:
You can select which bridge mode you want to use by setting the bridge_mode parameter to the appropriate number (from the list above). The default bridge mode is Radio-to-I²C (0). The UART RX pin has an internal 20 kΩ pull-up resistor. The I²C lines (SCL and SDA) are on P1_0 and P1_1, respectively, by default; these can be changed with the I2C_SCL_pin and I2C_SDA_pin parameters. They do not have pull-ups enabled, so external pull-ups must be added to form a bus that conforms to the I²C specification. (Some carrier boards for I²C devices include pull-ups on these lines.) The I²C bus frequency is 100 kHz by default, which can be changed with the I2C_freq_kHz parameter. This app does not support I²C arbitration, which means it cannot be used on multi-master I²C buses. Serial CommandsThis app listens on the selected serial interface for commands and performs the corresponding I²C transactions. The command format is similar to the one used by the NXP SC18IM700 Master I²C-bus controller with UART interface. Three commands, in the form of ASCII characters, are recognized:
The general format for a command sequence begins with a START command (‘S’), followed by a slave device address, the number of data bytes to be written or read, the data to be written (if a write is being done), and finally a STOP command (‘P’). If a read is being done, the data read from the slave device will be returned on the serial interface. The least significant bit of the slave device address (the data direction bit) indicates whether the operation is a write (0) or a read (1). A repeated START condition can be generated by issuing another START command without sending a STOP command. For example, to write the value 0x2E to register 0xF4 on a slave device with the write address 0xEE, the following sequence of bytes could be sent to the Wixel:
To read a two-byte value from register 0xF6 on the same device, whose read address would be 0xEF, the following sequence could be issued (the second ‘S’ generates a repeated START):
The Wixel would respond with the two data bytes read from the slave. Any invalid or unrecognized command is ignored and causes the Invalid Command error bit to be set. To prevent an unfinished command sequence from leaving the I²C bus in an unusual state, this app will time out and reset the bus if a byte is not received on the serial interface within 500 ms of the last byte. After this happens, the Command Timeout error bit will be set, and a new command sequence must be initiated with a START command. The command timeout delay can be changed with the cmd_timeout_ms parameter; a value of 0 disables this timeout. If the Wixel receives a Get Errors command (‘E’), it will respond with a single byte containing the status of several error conditions. This command can be issued any time the app is not expecting a slave address or data byte. When an error occurs, the corresponding bit in the error byte is set and remains set until the errors are read with the Get Errors command, after which it is cleared internally. The following table shows the error condition that corresponds to each bit:
Indicator LEDsThe green LED behaves as described in Section 1.a, and also flickers when there is data transferred over USB. The yellow LED is on when VIN power is detected. The red LED indicates an error condition when lit; it can be reset by issuing a Get Errors command (described above). General Parameters
Pin Assignment ParametersThe following parameters can be used to reassign the I²C lines to different pins on the Wixel. The value of each parameter must be the number of an unused pin on the Wixel. The number can be computed by multiplying the first digit in the pin name by 10 and adding it to the second digit in the pin name. For example, if you wanted to assign the SCL pin to P1_2, you would set I2C_SCL_pin to 12.
CaveatsData will be lost if the Wixel receives commands on the UART’s RX line faster than they can be processed on the I²C bus. If you have trouble, try reducing the amount of data sent to the RX line by lowering the baud rate or adding delays to your microcontroller’s code. Using the Get Errors command and checking the UART Overflow error bit is a good way to detect this problem. Caution: The Wixel’s I/O lines are not 5V tolerant. You must use level-shifters, diodes, or voltage dividers to connect the Wixel to outputs from 5V systems. Also, avoid drawing more current from an I/O line than it can provide (see the discussion of P1_0 and P1_1 in Section 1.a). Avoid connecting multiple output pins together. The Wixel does not support the RS-232 voltage levels typically used by DB9 serial ports. The Wixel’s I/O lines, including the RX and TX lines, operate on voltages between 0 and 3.3 V. To connect the Wixel to an RS-232 serial signal, you will need additional level-shifting and inverting hardware like the Pololu 23201a serial adapter (RS-232 serial is inverted; the Wixel’s serial interface expects non-inverted serial). Versions
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Log In
|
Wish Lists
|
BIG Order Form
|
Shopping Cart
US toll free: 1-877-7-POLOLU ~
(702) 262-6648 |
|||||||||||||
| Catalog | Forum | Resources | Distributors | Ordering | About | Contact | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|