BusPirate / Bus_Pirate

Community driven firmware and hardware for Bus Pirate version 3 and 4
625 stars 131 forks source link

SPI read ends in deadlock when power if off #150

Open PSLLSP opened 4 years ago

PSLLSP commented 4 years ago

I play with MAX6675K module. I found that when I set power off and than try try to read from SPI, BusPirate ends in deadlock condition.

Configure SPI mode:

HiZ>m
1. HiZ
2. 1-WIRE
3. UART
4. I2C
5. SPI
6. 2WIRE
7. 3WIRE
8. LCD
x. exit(without change)

(1)>5
Set speed:
 1. 30KHz
 2. 125KHz
 3. 250KHz
 4. 1MHz

(1)>4
Clock polarity:
 1. Idle low *default
 2. Idle high

(1)>
Output clock edge:
 1. Idle to active
 2. Active to idle *default

(2)>
Input sample phase:
 1. Middle *default
 2. End

(1)>2
CS:
 1. CS
 2. /CS *default

(2)>
Select output type:
 1. Open drain (H=Hi-Z, L=GND)
 2. Normal (H=3.3V, L=GND)

(1)>
Clutch disengaged!!!
To finish setup, start up the power supplies with command 'W'

Ready

Activate POWER and Pull UPs resistors (SPI device is powered from +5V, VPU wire is connected to +5V). I can read data (16 bits), no problem:

SPI>W
POWER SUPPLIES ON
Clutch engaged!!!
SPI>P
Pull-up resistors ON
SPI>[rr]
/CS ENABLED
READ: 0x03 
READ: 0xF9 
/CS DISABLED
SPI>[rr]
/CS ENABLED
READ: 0x04 
READ: 0x11 
/CS DISABLED
SPI>[r:2]
/CS ENABLED
READ: 0x04 0x11
/CS DISABLED

Power OFF and try to read data. DEADLOCK, a bug! BusPirate device has to be re-pluged to reset...

SPI>w
Clutch disengaged!!!
POWER SUPPLIES OFF
SPI>[rr]
/CS ENABLED
READ: 

Another, related bug. It seems like BusPirate BASIC cannot activate Power or when it is done then it is activated in some wrong way (LED signaling that power is active is ON, so power was activated in BASIC). The following BASIC program ends in deadlock when it is started and power was not activated with W command in manual mode. Power should be activated at line 10, LED is activated. Deadlock is at line 50, the first RECEIVE statement:

10  PSU 1
20  PULLUP 1
30  DELAY 5
40  START 
50  LET A= RECEIVE 
60  LET B= RECEIVE 
70  LET W=A*256+B
80  STOP 
90  PSU 0
100  PRINT A;",";B;",";W

My BusPirate is cute little box, a clone device from eBay:

HiZ>i
Bus Pirate v3.b clone w/different PIC
Firmware v6.3-beta1 r2151  Bootloader v4.4
DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
http://dangerousprototypes.com