MAX7219 and spiout 16bit

hls

New Member
Hi there,
I have this code to initialize and play with MAX7219, using 28X1

symbol data7219 = B.2
symbol cs7219 = B.0
symbol clk7219 = B.1
symbol reg = b9 ' 7219 register
symbol val = b8 ' value to register
symbol datareg = w4 ' 16bit data register

gosub Init7219

do
... some stuf ...
loop


Init7219:
let pins=$0
datareg = $09ff
gosub Write7219
datareg = $0b07
gosub Write7219
datareg = $0a0f
gosub Write7219
datareg = $0c01
gosub Write7219
return

Write7219:
low cs7219
spiout clk7219,data7219,MSBFirst_L, (datareg / 16)
high cs7219
return

the question is why this works
spiout clk7219,data7219,MSBFirst_L, (reg,val)
but
spiout clk7219,data7219,MSBFirst_L, (datareg / 16)
doesnt

w4 = b9:b8 so it should works same way, shouldnt?

Thanks for explanation
 

Buzby

Senior Member
Hi,

According to the command reference the number of bits shifted out may be only 1 to 8 (not 16).

Cheers, Alan.
Although only up to 8 data bits can be shifted out, there is a peculiarity with the command that allows more than 8 clock pulses to be sent.

So in the case above, the OP would have 16 clock pulses, but maybe not the correct data.

In my requirement I did not need any data, just the clock pulses, so I don't know what the data pin was doing.

See here :

https://picaxeforum.co.uk/threads/useful-trick-with-spiout.29886/

Cheers,

Buzby
 

AllyCat

Senior Member
Hi,

The manual seems quite specific that only the values 1 to 8 are "intended", but (as you found), there can be advantages in not actually rejecting other values as an "error".

However, supporting a full word would complicate the compiler / interpreter code considerably, even if the low byte was sent first (which I would have suggested the OP might try). But it is most likely that the data bits will just become zero after the first 8 bits (as does the bit-banging version). Or at best, the byte be arranged to rotate (as opposed to shift left or right) and thus repeat the byte continuously (which might be useful e.g. for driving LED strings).

Cheers, Alan.
 

Buzby

Senior Member
... supporting a full word would complicate the compiler / interpreter code ... , the byte be arranged to rotate ... and thus repeat the byte continuously (which might be useful e.g. for driving LED strings).
What would be even neater would be if the command could accept more than one byte, or a pointer to an array of bytes. Either of these would save a lot of looping in the code, but as you say, they would need a compiler change.

Maybe we'll see it in the X3's.

Cheers,

Buzby
 

hippy

Technical Support
Staff member
What would be even neater would be if the command could accept more than one byte
This works for me, passes Syntax Check and should run on a chip -
Code:
spiout clk7219,data7219,MSBFirst_L,(b0,b1,b2,b3)
 

Aries

New Member
The manual does show more than one byte
SPIOUT sclk,sdata,mode,(data{/ bits}, {data{/ bits},...})
but - as Hippy shows - it has to be done one byte at a time, i.e.
Code:
spiout clk7219,data7219,MSBFirst_L,(b0/8,b1/8)
and not
Code:
spiout clk7219,data7219,MSBFirst_L,(w0/16)
 
Top