Using spiout from a 28x2

john thorne

New Member
I am trying to send a number between 1 and 34 to light any one of 34 leds attached to a M5450 led driver.
I am using a Picaxe 28x2 with pin B,7 as clock and B.5 as data.
The question is how is the data arranged what is the spiout command for 1 to be sent, what is the spiout command for 34 to be sent.
And what mode is required.
Any help will be appreciated.
 
Last edited:

hippy

Technical Support
Staff member
The M5450 receives a stream of 36 bits - a high start bit, high/low for bit1/output1, then more bits up to bit34/output34, and a final high/low for bit35 which has no output pin on an M5450 -

http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00020632.pdf

So to set output 34, send a High, 33 x low, 1 x high and a final 1 x anything, 36 bits in total.

How you'd send the data and the mode would depend on how you are holding the data in variables, but if just wanting to turn output 1 on I would guess (untested) ...

Code:
;                                            111111   11112222   22222233   3333
;                                1234567   89012345   67890123   45678901   2345
spiout CLK, DAT, MSBFirst_L, ( %1[b]1[/b]000000, %00000000, %00000000, %00000000, %00000000/4 )
And for output 34 ...
Code:
;                                            111111   11112222   22222233   3333
;                                1234567   89012345   67890123   45678901   2345
spiout CLK, DAT, MSBFirst_L, ( %10000000, %00000000, %00000000, %00000000, %00[b]1[/b]00000/4 )
 

john thorne

New Member
Fantastic....Thanks that works! A very clear explanation. I thought you only needed the first byte to give the number, the data looks more like switches.
When sending the number could you use decimals instead of binary? ie 192 for the first byte if sending 1.
The 28x2 is receiving the number via a serin from another chip.
I will have to change the number into the 5 data bytes.
 

westaust55

Moderator
Here is some code that should on receiving a value from 1 to 34 in the byte variable received will automatically transmit the right data to the M5450 chip.
There is no code presented here to received the incoming data nor any checking for the incoming value outside the range 1 to 34 inclusive (I leave that to you to work upon)

The method will work with any X1 or X2 part which have the DCD command.

Code:
; set a bit from 'bit 1' to 'bit 35' plus extra band send to the M5450 chip

; receive a value form 1 to 34 corresponding to LED to be illuminated.

#PICAXE 28X2 ; also works with other X1 and X2 parts


SYMBOL CLK = B.7
SYMBOL DAT = B.5

 
SYMBOL reserved1 = w0 ; b1:b0
SYMBOL reserved2 = w1 ; b3:b2
SYMBOL reserved3 = b4 ; for bits 32, 33, 34 and 35

SYMBOL received = b5 ; incoming value from 1 to 34

;clear the full set of bits
w0 = 0
w1 = 0
b4 = 0

IF b5 < 16 THEN 
	W0 = DCD b5
ELSEIF b5 < 32 THEN
	b5 = b5 - 16
	w1 = DCD b5
ELSE
	b5 = b5 - 32
	b4 = DCD b5 AND $07 ; 'bit 35' always low and others are not required
ENDIF

w0 = w0 [COLOR="#FF0000"]OR[/COLOR] $01 ; set the start bit high


; bytes are constructed with the first bit to be sent in bit0 as lsb so we must send as LSBFirst
SPIOUT CLK, DAT, LSBFirst_L, ( b0, b1, b2, b2, b4/4 )

DO
LOOP
 
Last edited:

john thorne

New Member
Thanks... I didn't know about the DCD command (my first X chip)
I put part of the code in the programmer to see how the DCD bit worked
Code:
#picaxe 20x2

Start:
 serin C.0,n2400,b5
 	W0 = DCD b5
	pause 500
	w0 = w0 AND $01 ; set the start bit high
goto start 
[code]
I can see if I enter.. 1.. the the first bit is missed and a 1 appears in the second bit as I enter 2..3..4..5 I see the bit moving to the left..perfect.
But after the pause 500 all the bits get wiped? I expected it to make the first bit a 1.
 

john thorne

New Member
I changed the AND to OR and it worked.
Thanks to both of you for the help. I think I will work fine.
I will put the whole thing together and report the result.
Again very helpfull forum.
 
Top