RS-232 to I2C/SPI/1-Wire Translator
Originated: 11-19-2016 ----> Updated: 6-4-2018
You just got that hot new chip on Ebay and have tracked down the specifications in a (poorly translated) PDF file. Now, you try writing some code to make that puppy work. Initializations are usually the hardest part --- there are just so many variations.
Write code, assembler code, program micro, run code, scratch head, repeat...
This device lets you connect to the chip from a terminal program in your computer. You send it hex bytes, you read back hex bytes. It takes only seconds to try stuff out. The internal structure of some devices may be very complex, but it all comes down to...
That is all you really need to do to work out the code.
(Note: This project has proven so useful over the last 2 years, that I decided it was worth upgrading. This version uses a PIC16F688 chip to get the EEPROM but the rest of the circuit remains the same. --- Luhan)
Here are the commands at your disposal:
xx - any hex byte is sent by default, up to 20 at a time. Always enter as 2 characters.
.ddd - 1-256 hex bytes are read back.
/ - generate START condition for I2C, Chip Select for SPI, Reset for 1-Wire.
If this command is used in I2C mode, a STOP condition is automatically generated at the end of the command line. For SPI mode, a chip de-select is automatically generated.
; - generate STOP condition for I2C, Chip De-Select for SPI.
Wddd - wait for 1-255 milliseconds.
S - scan all 256 possible I2C addresses. This command works only in I2C mode. It returns the read and write addresses.
R - reset to see command list and version number.
Additionally, these commands change the operating mode. They take effect immediately when entered.
ctrl-D - change from I2C to SPI to 1-Wire and back to I2C.
ctrl-R - reverse/unreverse direction of bit transfers (read and write I2C or SPI)
ctrl-C - re-execute last command string.
On power up, a brief list of commands is shown, and the last operational mode is restored.
Full line buffering of command strings with backspacing is supported. Be sure to enter all hex bytes as 2 hex digits (spacing between bytes is optional). Decimal values may be entered as 1-3 digits. If you specified reverse bit mode with the ^R command, '*' will be indicated in front of the prompt.
Set your terminal program for normal CR and LF processing, 9600 baud no handshake. The Scan command depends on this by rewriting data on the same line (issuing CR with no LF) until an address match is found.
Here are some examples:
I2C>/A0 0020 11 22 33 (write hex values 11,22,33 to eeprom location 20).
*SPI>/11 22 33 (write to non standard SPI device with reverse bits)
ONE>/CC44 W5 /CCBE.8 (read scratch data from DS18B20 temperature sensor)
In I2C mode, besides returning hex bytes, the translator also returns either '!' for ACK's or "-" for missing ACK's.
When providing power to the target, this device supports both 5 volt and 3.3 volt devices. A 2-pin jumper on J3 selects voltage (center pin to outside pin). When running at 3.3 volts, the PIC16F688 itself runs on that voltage so the signal levels will match.
The 6 pin connector provides the following signals:
For 1-wire devices, the PIC provides up to 20ma for parasitic power on data line.
The clocking of the translator is deliberately slow for I2C and SPI to show up well on a scope if you need to. Since the protocols are synchronous (clocked), this doesn't matter. The 1-Wire protocol meets the timing specifications for such devices. This protocol has very wide margins because most of these are internally timed.
Note: The RED led must be red! It is used for its voltage drop value. Other led's may be any color.