How-to: The Bus Pirate, Universal Serial Interface

Aktualizacja: Nowe oprogramowanie układowe z JTAG i więcej

Zawsze jesteśmy ekstatyczni, aby uzyskać nowy wiórek lub kartę SIM do interfejsu, ale nasz entuzjazm jest zazwyczaj zwilżony przez proces prototypowania. Interfucing dowolny układ normalnie wskazuje nabożek obwód, kod pisania i ciągnięcie programatora; Może nawet prototypujący pcb.

Kilka lat temu zbudowaliśmy pierwszy “autobusowy Pirate”, uniwersalny interfejs autobusowy, który rozmawia z dużą ilością frytek z terminalu szeregowego PC. Kilka konwencjonalnych protokołów seryjnych jest wspierany na 3,3-5 wholts, w tym Serial I2C, SPI i asynchroniczne. Dodatkowe biblioteki “RAW” 2- i 3- biblioteki mogą interfejsu prawie wszelkie zastrzeżone protokoły seryjne. Biorąc pod uwagę, że było to dla nas takie korzystne narzędzie, sprzątaliśmy kod, udokumentowaliśmy projekt i wydał go tutaj z specyfikacjami, schematycznym i kodem źródłowym.

Przegląd koncepcji.

Pirat autobusu jest szeregowym mostem terminala do wielu protokołów interfejsu IC. Wpisz polecenia w terminalu szeregowym na komputerze. Polecenia przejdą do autobusu pirata przez port szeregowy PC. Pirat autobusowy rozmawia z mikrochipem we właściwym protokole i zwraca wyniki do komputera.

Wszystkie pinki wyjściowe 3.3wolty, ale są tolerancyjne 5 VOLT. Dostępne są zasilacze zasilania pokładowe 3.3volt i 5 VOLT, aby zasilać podłączony układ. Konfigurowalne oprogramowanie I2C Pull-Up Resistors Ukończ pakiet.

Interfejs terminala szeregowego współpracuje z dowolnym systemem: PC, Mac, Linux, pilotów palmowych, urządzeń wince itp.; Nie wymaga crapware. Uważaliśmy urządzenie USB, ale USB nie jest kompatybilny z znaczną liczbą urządzeń ręcznych, które mają port szeregowy. Chcieliśmy również urządzeniu 3.3volt z wejściami tolerancyjnymi 5 VOLT, ale wiele popularnych mikrokontolerów USB dołączonych do otworek były częściami 5 VOLT (np. PIC18FX550).

Autobus Pirate obecnie “mówi” trzy protokoły sprzętowe do szybkiego interfejsu i posiada dwa biblioteki protokołów oprogramowania dla łatwej manipulacji magistrali. Teoria i specyfikacja każdego protokołu wykracza poza to, co możemy tu przykryć, ale sprawdź niektóre z tych samouczków:

I2c.

Powolny 2 przewodowy autobus. Wikipedia jest wspaniałym miejscem do rozpoczęcia tła I2C. I2C-Bus.org, Robot Electronics, Embedded Systems Academy i Embedded.com mają szanowane samouczki I2C.

Spi.

Podstawowy autobus 3 drutu. Wikipedia ma tło; Embedded.com ma wspaniały samouczek i porównanie do I2C.

Uniwersalny asynchroniczny nadajnik odbiornika (UART lub Serial)

Zegar i protokół seryjny zależny od czasu, najlepiej znany ze względu na swój wygląd jako protokół portu szeregowego PC. Wikipedia ma tło na asynchroniczne protokoły seryjne.

Surowy 2 przewód

Jest to ogólna biblioteka 2-przewodowa biblioteka, podobna do I2C, ale bez bitu ACK. I2C i wiele właściwych protokołów 2 drutu można utworzyć za pomocą manipulacji magistrali dostępnych w tym trybie. Użyj tej biblioteki do pracy z urządzeniami Drut NON-I2C, podobnie jak SmartCards lub Sensirion SHT11 Temperatura / Wilgotność czujniki.

Surowy 3 drut

Jest to ogólna biblioteka protokołu 3 drutu, podobna do SPI, ale bez ograniczeń modułu sprzętowego. Użyj tej biblioteki do pracy z urządzeniami, które używają kompatybilnych 3-przewodowych protokołów innych niż 8bit, takich jak sparkfun Nokia 6100 LCD. Dużo 3 protokołów drutu można utworzyć za pomocą manipulacji magistrali dostępnych w tym trybie.

Sprzęt komputerowy

Kliknij, aby uzyskać pełny obraz umieszczenia PCB (PNG). Zaciski śrubowe łączą się z zasilaczami. Wiersz siedmiu nagłówków PIN łączy się z kołkami IO. Pomimo etykiety wymagana jest tylko 7Volts DC.

SZPILKA

Spi.

I2c.

RS232.

B9.

MOSI.

SDA.

B8.

Clk.

Scl.

B7.

Miso.

Rx.

B6.

Cs.

TX.

B5.

Aux.

Aux.

Aux.

Grunt

Gnd.

Gnd.

Gnd.

Ta tabela przedstawia połączenia PIN dla każdego trybu magistrali. RAW 2 Tryb drutu wykorzystuje tę samą konfigurację PIN jako I2C. RAW 3 Tryb drutu wykorzystuje tę samą konfigurację PIN jako SPI.

Kliknij, aby uzyskać pełny obraz obwodu (PNG). Obwód i PCB są tworzone przy użyciu wersji Freeware Cadsoft Eagle. Pobierz Archiwum Projektu (ZIP).

PIC 24FJ64GA002.

Użyliśmy mikrokontrolera PIC24FJ64GA002 w piratach autobusowych; Jest to ten sam chip, którego używaliśmy w naszym projekcie Mini-Server. Jest wystarczająco szybki, aby zrobić wszystko, co chcemy (16mips), a funkcja pinezki pinezki pinezki umożliwia moduły sprzętowe SPI, UART i I2C do udostępniania pinów wyjściowych. Każdy pin zasilający wymaga kondensatora odsprzęgania (C12,13), a funkcja MCLR wymaga rezystora (R7) między PIN 1 a 3,3 rano. Zdjęcie ma wewnętrzny regulator napięcia, który wymaga kondensatora 10UF Tantalum (C3), choć użyliśmy zwykłego kondensatora elektrolitycznego bez problemu. Przeczytaj o programowaniu i pracy z tym układem w naszym samouczku PIC24F. Jeśli nie masz debugera zdjęć, kilka czytelników zaleca klony 40 $ ICD2 w serwisie eBay.

Zdjęcie działa na 3,3 r., Ale piny Tylko cyfrowe są tolerancyjne 5 VOLT do interfejsu Logika 5 VOLT. Szpilki 14,15,16,17,18,21, a 22, są tylko cyfrowe, które wymyśliliśmy, patrząc przez arkusz danych i eliminując dowolne kołki z typem połączenia analogowego (Tabela 1-2, strony 11-16). Według arkusza danych,I2C pins are also 5volt tolerant. There’s a bunch of conflicting information on the web, but datasheet page 230, parameter DI28, clearly states that the max input for a 24FJ64GA002 I2C pin without analog circuitry is 5.5volts.

Pins 21 and 22 (RB10/11) can pull-up SDA/SCL through resistors R4 and R5.

MAX3223CPP

This chip converts 3.3volt serial output to +/-10volt RS232 signals compatible with a PC serial port. The MAX3223CPP is a 3-5volt version of the MAX202, with extra power saving features. MAX RS232 transceivers require four 0.1uF capacitors for a charge pump (C4,5,7,8), and one decoupling capacitor (C17). We used the same capacitors for everything.

We used a MAX3223CPP, which doesn’t seem to be available anymore. MAX3223EEPP+ is a pin-compatible newer version, available at Digikey for $7. Auć! None of the 3223’s power saving features are used, so a cheaper, simpler 3.3volt RS232 transceiver must be substituted if in any way possible.

Zasilacze

Most chips can be powered from the Bus Pirate’s on-board 3.3volt and 5volt supplies. 5volts is supplied by a common 7805 regulator (VR2) and two decoupling capacitors (C9,10). An LM317 adjustable regulator (VR1) is set to 3.3volts using two resistors (R2,3), and requires two decoupling capacitors (C6,7). The circuit requires a 7-10volt DC supply (J1).

Lista części

Część
Wartość

IC1.
PIC24FJ64GA002-DIP

IC2.
MAX3223CPP (try MAX3223EEPP+)

C3
10uF capacitor (preferably tantalum)

C4-13,17
0.1uF capacitors

R1
330 ohm resistor

R2
240 ohm resistor

R3
390 ohm resistor

R4,5,7
2K2 ohm resistor

VR1.
LM317

VR2.
LM7805

X1.
Screw clamp (3 terminals) *untested

X2
DB9 female connector (serial port) *untested

ICSP,SV3
.1″ pin header, ideal angle

J1.
Power jack, 2.1mm pin

LED1
3mm LED (optional)

Oprogramowanie

The firmware is written in C using the complimentary demonstration version of the photo C30 compiler. learn all about working with this photo in our introduction to the photo 24F series. Pobierz Archiwum Projektu (ZIP).

main.c – Handles the user terminal interface.

busPirate.c – Abstraction routines that convert syntax to actions on the proper bus.

uartIO.c – IO routines for both hardware UARTs.

m_i2c_1.c – software I2C routines by [Michael Pearce]. We couldn’t get the photo hardware I2C to work, so we used this valuable library. The software doesn’t take into account the I2C speed setting, and seems to work at about 5KHz.

SPI.c – routines that drive the hardware SPI module.

raw2wire.c – software 2-wire interface library.

raw3wire.c – software 3-wire (SPI) interface library.

User input is held in a 4000 byte buffer until a newline character (enter) is detected. If the first character of the input is a menu option (see below), the menu dialog is shown, otherwise the string is parsed for data to send over the bus (see syntax). The code consists of an embarrassing number of switch statements and spaghetti code.

Terminal interface

Rather than write a junk piece of software to control the device, we gave it a serial command line interface that will work with any ASCII terminal.  The bus pirate responds to commands with three digit result codes and a short message. The codes are created with PC automation in mind. We’ve included a table of result codes in the project archive (zip).

Opcje menu

Menu options are single character commands that don’t involve data transfers. enter the character, followed by , to access the menu.

? – show a help menu with commands and syntax.

M – set the bus mode (SPI, I2C, UART, raw 2 wire, raw 3 wire). followed right away by a prompt for speed, polarity, and output state (mode dependent).

Bus speeds: SPI:30, 125, 250, 1000KHz. I2C:100, 400, 1000KHz. UART: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200bps. Raw modes: 1, 10, 50KHz.

Inverse clock setting sets the idle state opposite of normal (normal SPI:idle low; normal UART:idle high): SPI:idle high; UART:idle low.

Some modes have optional high-z output modes for use with pull-up resistors (Low=ground, High=input).

L – Toggle bit transmit/receive order: most/least significant bit first.

P – SDA/SCL pin pull-up resistor toggle (3.3volts). only valid in I2C and raw 2 wire modes.

O – set number output display format. The terminal can display numbers as decimal, hexadecimal, and binary ASCII values. A fourth format sends the raw, unprocessed byte for reading ASCII formatted text.

Składnia

A basic syntax is used to communicate with chips over a bus.  Syntax commands have generic functions that normally apply to all bus types.

A/a/@ – Toggle auxiliary pin. capital “A” sets AUX high, small “a” sets to ground. @ sets aux to input (high impedance mode) and reads the pin value.

[ – start data write. SPI/raw 3 wire: chip select enabled. I2C/raw 2 wire: start condition. RS232: open UART, discard received bytes.

{ – start data write with reads. same as [, except: SPI/raw 3 wire: show the read byte for each write. RS232: display data as it arrives asynchronously.

] or } – end data write. SPI/raw 3 wire: chip select disabled. I2C/raw 2 wire: stop condition. RS232: close UART.

R/r – read byte. SPI/raw 3 wire: send dummy byte, return read. I2C: read byte with ACK. Raw 2 wire: read 8 bits. RS232: check UART for byte and return, or fail if empty. use 0r1…255 for bulk reads up to 255 bytes.

0b – write this binary value. format is 0b00000000 for a byte, but partial bytes are also fine: 0b1001.

0h or 0x – write this HEX value. format is 0h01 or 0x01. Partial bytes are fine: 0xA. A-F can be lower-case or capital letters.

0-255 – write this decimal value. any number not preceded by 0x, 0h, or 0b is interpreted as a decimal value.

, or space – Value delimiter. use a coma or space to separate numbers. any combination is fine, no delimiter is required between non-number values: {0xa6,0, 0 16 5 0b111 0haF}.

Direct bus manipulation commands for raw 2 wire mode and raw 3 wire mode.
^ – send one clock tick. use 0^1…255 for multiple clock ticks.

/ and \ – Toggle clock level high (/) and low (\). includes clock delay (100uS).

-/_ – Toggle data state high (-) and low (_). includes data setup delay (20uS).

! – read one bit with clock.

. – read data pin state (no clock).

& – delay 1uS. use 0&1…255 for multiple delays.

Użyj tego

Here are two examples that show the Bus Pirate in action. Terminals must be set to ASCII mode with local echo, we used the Windows serial terminal. The PC-side serial connection is 115200bps, 8N1. The Bus Pirate must respond to any single line feed type (0x0a, 0x0d), or both (Windows style).

.I2C/SPI – Flash 24LC1025 EEPROM

Microchip’s EEPROMS are popular permanent-storage memory chips, the 24LC1025 has 128Kbytes of storage with an I2C interface.  We can test this chip without bread-boarding a big circuit or writing code.

The picture shows an 24LC1025 connected to the Bus Pirate. The EEPROM works from 2.7 to 5volts, so we used the 3.3volt supply from the Bus Pirate to power the circuit. The on-board SDA/SCL pull-up resistors hold the I2C bus high, and eliminate the need for external resistors. A single 0.1uF capacitor decouples the EEPROM from the power supply.

Setup I2C mode

First, we setup the Bus Pirate for I2C mode and enable the pull-up resistors. considering that the Bus Pirate currently uses a software I2C library, the speed setting doesn’t really have an effect.

SPI>m  <–enter m for mode select 1. SPI 2. i2c. 3. UART. 4. RAW 2 WIRE 5. RAW 3 WIRE MODE>2  <–enter 2 for I2C Zestaw trybów 900. Ustaw prędkość: 1. 100KHz (Standard) 2. 400KHz (Fast Mode) 3. 1MHz (High Speed) SPEED>1 <–speed doesn’t really do anything… 901 speed SET 202 I2C READY, P/p FOR PULLUPS I2C>P   <–enable the I2C pull-up resistors 205 I2C PULLUP ON I2c >.

Write to EEPROM (I2C)

All I2C operations begin with a start condition { or [, and end with a stop condition } or ]. A write begins by addressing the device (1 byte) and trying to find an acknowledgment bit (ACK). If the EEPROM responds, we can send the data location to write (2 bytes) and data payload (n bytes). The Bus Pirate automatically checks for an ACK at the end of each write, and ACKs each read.

The 24LC1025 base address is 1010xxy, where xx is figured out by the state of pins 2 and 3, and y is read (1) or write (0) mode. We tied pins 2 and 3 high, making the full write address 1010110.  We’ll start writing to the device at the first data location (0 0), and write one to thirteen using a mix of data input formats (1…13).

I2C>{0b10100110 0 0 1 2 3 4 5 6 7 8 9 10 0xb 0xc 13} <–I2C command 210 I2C start condition <–bus start 220 I2C WRITE: 0xA6 got ACK: yes <–address sent and ACK received 220 I2C WRITE: 0x00 got ACK: yes <–write address 220 I2C WRITE: 0x00 got ACK: yes <–write address 220 I2C WRITE: 0x01 got ACK: yes <–data ... 220 I2C WRITE: 0x0D got ACK: YES Stan zatrzymania 240 I2C I2c >.

Read from EEPROM (I2C)

Reading the 24LC1025 takes two steps. First, a write command with no data sets the address pointer. Second, a read comm