Reply by Glen May 8, 20032003-05-08
I'm trying to write SPI Master code to send from a 16F628 to a
MAX7219. Anybody got any example code? I've written what I think
should work, but no luck so far.

I have a logic probe and can see the MOSI, CLK and SS lines toggling
away, but the 7219 doesn't react. A scope would be awesome right
now, but I don't own one.

Here are the Init and Transmit sections of my code (periods are to
hold formatting). If you see anything that seems wrong, please tell
me:

init:
........bsf........STATUS,RP0........;bank 1
........movlw......b'00000000'.......;set PORTB all outs
........movwf......TRISB
........movlw......255...............;set baud rate
........movwf......SPBRG
........bcf........STATUS,RP0........;bank 0
........movlw......b'11111000'.......;turn off LED's & set SS high
........movwf......PORTB
........bsf........RCSTA,SPEN........;set SPEN
........bsf........STATUS,RP0........;bank 1
........movlw......b'10110010'.......;set SYNC,CSRC and TXEN
........movwf......TXSTA
........bcf........STATUS,RP0........;bank 0

transmit:
........bcf........PORTB,3...........;lower SS

........movf.......regbyte,W.........;load register byte
........movwf......TXREG.............;transmit it
........bsf........STATUS,RP0........;bank 1
send1:..btfss......TXSTA,TRMT........;transmission done?
........goto.......send1.............;no, then go again

........bcf........STATUS,RP0........;bank 0
........movf.......databyte,W........;load register byte
........movwf......TXREG.............;transmit it
........bsf........STATUS,RP0........;bank 1
send2:..btfss......TXSTA,TRMT........;transmission done?
........goto.......send2.............;no, then go again

........bcf........STATUS,RP0........;bank 0
........bsf........PORTB,3...........;raise SS to latch data
........return.......................;yes, done