Need help on SPI module - MC908GP32

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help on SPI module - MC908GP32

2,838 Views
nennie
Contributor I
Good Day everyone,

I'm doing my project on Eight Bicolor 5x7 LED Matrix Display using GP32. On my previous post, I had problem with the hardware part. Now that I've finished construct my hardware, I'm stucked at this phase where I need to test the SPI module and light up all the LEDs.

Here's my code to light up 4 bicolor LED matrix using 2 MAX6952 display drivers. I'm using ICD08SZ Debugger.

PORTA    EQU     $00
CONFIG1    EQU     $1F
PORTB    EQU     $01
DDRA    EQU     $04
START    EQU     $8000
SPCR    EQU     $10
SPSCR    EQU     $11
SPDR    EQU     $12

    ORG     $FFFE
    FDB     START
    ORG     START
    MOV     #$B1,CONFIG1
    MOV     #$38,SPCR
    BSET     1,SPCR
    MOV     #$11,SPSCR
    MOV     #$06,DDRA                     <== Latch PTA1 and PTA2
    MOV     #$04,SPDR                     <== Configuration
    MOV     #$00,PORTA
                   <== I connected PTA1 and PTA2 to CS pin of both MAX6952
HERE1    BRCLR     3,SPSCR,HERE1
    MOV     #$01,SPDR
HERE2    BRCLR     7,SPSCR,HERE2
    LDA     SPSCR
    LDA     SPDR
HERE3    BRCLR     7,SPSCR,HERE3
    LDA     SPSCR
    LDA     SPDR
    MOV     #$06,PORTA                     <== CS = '1'
    MOV     #$07,SPDR                       <== Display test
    MOV     #$00,PORTA                     <== CS = '0'
    NOP
HERE4    BRCLR     3,SPSCR,HERE4
    MOV     #$01,SPDR                       <== Normal operation
HERE5    BRCLR     7,SPSCR,HERE5
    LDA     SPSCR
    LDA     SPDR
HERE6    BRCLR     7,SPSCR,HERE6
    LDA     SPSCR
    LDA     SPDR
    MOV     #$06,PORTA
AGAIN    BRA     AGAIN


When I execute the program line by line, this is where I got the problem:
HERE3    BRCLR     7,SPSCR,HERE3

The program said that it cannot branch to itself. Could anyone help me on this? I'm jammed now and really need help.

Thanks and regards,
Nennie
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-04-21 05:40 PM
Labels (1)
0 Kudos
Reply
6 Replies

842 Views
fabio
Contributor IV
It looks like you are enabling the MAX by placing the CS line in high state, but the device is enabled by placing the CS line in low state.

Best regards,
0 Kudos
Reply

842 Views
bigmac
Specialist III
Hello Nennie,
 
It is unclear whether you have "daisy chained" the two MAX6952 devices, or alternatively are operating them in parallel.
 
For the first case you will need to lower both CS signals, and then send two bytes, one to each device in the chain, before raising CS to latch the data.
 
For the parallel case, each CS would need to be controlled separately, and the data would need to be sent to each device, in turn.
 
It would also make your code a little clearer by defining a label for CS1 and CS2.  Assuming bit numbers are defined the following might apply -
 
CS1   equ  1  ; PTA1 used
CS2   equ  2  ; PTA2 used
 
 
      bclr  CS1,PORTA  ; Set device 1 active
      bclr  CS2,PORTA  ; Set device 2 active
 
      bset  CS1,PORTA  ; Set device 1 inactive
      bset  CS2,PORTA  ; Set device 2 inactive
 
Regards,
Mac
 


Message Edited by bigmac on 2008-04-22 04:12 AM
0 Kudos
Reply

842 Views
nennie
Contributor I
Hello Bigmac,

I have "daisy-chained" both MAX6952s. In this case, I connected Rset to both MAX6952s Iset pins. For the clock, I use external clock with the frequency of 8MHz to get the maximum speed.

Thanks everyone for the suggestions. I only manage to try those out today, will do as u suggested :smileyhappy:

Regards,
Nennie
0 Kudos
Reply

842 Views
bigmac
Specialist III
Hello Nennie,


nennie wrote:
I have "daisy-chained" both MAX6952s. In this case, I connected Rset to both MAX6952s Iset pins. For the clock, I use external clock with the frequency of 8MHz to get the maximum speed.

If you have the Iset pin for each MAX6952 connected in parallel, and then connected to a single resistor, this is wrong.  There should be separate resistors to each Iset pin.
 
What "clock" do you refer to?  If you mean the CLK pin on each MAX6952, this is also wrong.  The signal for the CLK pin should originate from the SPI module.
 
The following recent thread discusses SPI operation for the GP32 device -
 
For SPI master operation, I would strongly suggest that you wait until each SPI transfer is completed before attempting to send the next byte.  I would also suggest that your code would be more understandable if each SPI send were handled within a common sub-routine.  A lot more comments within your code would also help provide clarity on what you are attempting to achieve.
 
You do not say which assembler you are using (with the non-standard comment format), but the following sub-routine should work with most assemblers -
 
; SPI MASTER BI-DIRECTIONAL TRANSFER
; On entry, ACC = byte value to be sent
; On exit,  ACC = received byte value
 
SPI_TRANS:
          STA    SPDR       ; Send byte value
          BRCLR  7,SPSCR,*  ; Wait until transfer complete
          LDA    SPDR       ; Return received value & clear flag
          RTS
 
The use of the sub-routine may also eliminate some of the incorrect sequencing in the previous code, like attempting to start a SPI transmission prior to CS being activated (set low).  Another important issue is that the MAX6952 contains a 16-bit register which will require the sending of two bytes.  Since you are daisy chaining two devices, you will actually need to send 32 bits of data, or four bytes for each transfer.  You do not appear to have taken this into account.

To send a command to each of the devices would require the following sequence, assuming MOSI is connected to the first device (and MISO to the second device) -
Set CS1 active low
Set CS2 active low
Send command byte for device 2
Send data byte for device 2
Send command byte for device 1
Send data byte for device 1
Release CS1 to inactive
Release CS2 to inactive
 
Finally, I will leave for you to check that the CPOL and CPHA settings match the requirements for the MAX6952.  You will need to closely examine the waveforms given in the MAX6952 datasheet.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-04-24 03:46 PM
0 Kudos
Reply

842 Views
CarlFST60L_3rd
Contributor I
Not 100% sure of the sytax (compiler dependent) but you can just do

BRCLR     7,SPSCR,*

the * is a reference to itself. This is exactly how you write it when using the PEmicro assembler.

another example

bra *
will just branch to self
0 Kudos
Reply

842 Views
peg
Senior Contributor IV
Hi Nennie,

I don't know how to drive the device at the other end of your SPI, but the code you have should run OK.
Indeed I assembled and simulated it OK.
Using branch to a label on the same line and branch to * should produce the same machine code.
I am not sure if the very short CS pulse you have generated is what you wanted.
What assembler/simulator are you using?

0 Kudos
Reply