Issue with 20X2 Hardware SPI

beb101

Senior Member
I am working with the MAX3100,

http://datasheets.maximintegrated.com/en/ds/MAX3100.pdf

I selected the MAX 3100 because I thought this chip would give an easy way to get some experience with hardware SPI on the 20X2 (e.g. SPI in, serial out and reading/writing to registers). From the datasheet,

"SPI Interface
=============
The bit streams for DIN and DOUT consist of 16 bits, with bits assigned as shown in the MAX3100 Operations section. DOUT transitions on SCLK’s falling edge, and DIN is latched on SCLK’s rising edge (Figure 4). Most operations, such as the clearing of internal registers, are executed only on CS’s rising edge. The DIN stream is monitored for its first two bits to tell the UART the type of data transfer being executed (Write Config, Read Config, Write Data, Read Data). Only 16-bit words are expected."

This is the 20X2 program. Taking small first steps, I am only writing and reading the configuration register.
Code:
#picaxe 20X2
#no_data
#no_table
#Terminal 9600

; 20X2 pin connections 
; pin9 	C.1	= SDO
; pin13	B.5	= SDI
; pin11     B.7	= SCK
; pin14     B.4	= /CS

symbol cs 	= b.4
symbol sdo 	= c.1
symbol sdi 	= b.5
symbol sck	= b.7
symbol baud = $0B '9600 3.6864MHz crystal
symbol dum1 = b9
symbol dum2 = b8

output cs
output sck

symbol MAX3100_READ_CONFIG 	= w0 'b1 : b0
symbol MAX3100_WRITE_CONFIG 	= w1 'b3 : b2
symbol MAX3100_READ_DATA	= w2 'b5 : b4
symbol MAX3100_WRITE_DATA	= w3 'b7 : b6

MAX3100_READ_CONFIG 	= 0x4000
MAX3100_WRITE_CONFIG 	= 0xC000
MAX3100_READ_DATA  	= 0x0000
MAX3100_WRITE_DATA  	= 0x8000


MAX3100_WRITE_CONFIG = MAX3100_WRITE_CONFIG | baud '--> b3,b2

'setup
'=====

hspisetup spimode00, spislow
output sck
high cs

'SPI transaction (using direct addresses)
'========================================
low cs
hspiout($C0,$0B) 'write confguration
high cs
low cs
hspiin($40,$00, dum1,dum2) ' read configuration  into data (dum1,dum2)
sertxd(#dum1, "  ", #dum2)
The output from this program is always 0,0 even though I tried every permutation of spimode. So I hooked up the Max3100 module to a Bus Pirate and a Saleae Logic. The Bus Pirate dialog is a direct emulation of the Picaxe program,

Bus Pirate Dialog
=================
SPI>
[0xc0 0x0b] <-- write configuration register
/CS ENABLED
WRITE: 0xC0
WRITE: 0x0B
/CS DISABLED

SPI>
[0x40 0x00 r:2] <-- read configuration register (2 bytes)
/CS ENABLED
WRITE: 0x40
WRITE: 0x00
READ: 0x00 0x00
/CS DISABLED
SPI>

This is the same result given by the Picaxe. The attached screen shots of the Saleae Logic show a different result.
Send $c00b
Send $c00b.JPG
Read Configuration Register
Read Configuration Register.JPG

The read screenshot shows that data is immediately clocked out on MISO (DOUT). Note that $0b is being sent back. Am I missing something with hspiin command?

Baxter
 

hippy

Ex-Staff (retired)
The MAX3100 appears to reply at the same time as data is being sent to it. That mode of operation is not directly supported by the PICAXE but can probably be achieved with -

Symbol SSP1BUF = $91 ' $211

hspout($40) : peeksfr SSP1BUF, dum1
hspiout($00) : peeksfr SSP1BUF, dum2
 

beb101

Senior Member
Many thanks for the tip, hippy. I think I managed to kill my last Picaxe 20X2 by shorting it out somehow. I am waiting for some new ones from Techsupplies and will follow up on this when I get them. I did, however, hook the MAX3100 up to a Netduino Plus running the .NET micro framework and it behaves as expected. The full-duplex operation is supported by a command, WriteRead(bufout,bufin).

Baxter
 
Top