MC13213 SRB- SPI to Transceiver Modem

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

MC13213 SRB- SPI to Transceiver Modem

4,217 Views
cschai
Contributor I
hi,

below is 2 subroutine, where:
1. W_Modem is writing to modem register
2. R_Modem is reading from modem register

initially i had set
MOV #$50,SPI1C1 ;enable SPI, Master, no interupt
MOV #0,SPI1C2 ;MSB first, no didirectional
MOV #0,SPI1BR ;highest baud rate
and this setting i never change after initialize.

and Port E bit 2 is is connected to modem CE(chip enable)_bar. so right before write/read operation i low_activate it, and right after finish doing the operation, i high_deactivate it.

my problem is, why i can write to modem register but i cant read from modem register.
for example, i want to read modem IRQ_Status Register (0x24)

so i will
MOV #$A4, SPI4 ;;; for reading, bit 7 must be "1"
JSR R_Modem
after this subroutine, the register 16 bit value should have been stored at my RAM named SPI5, SPI6, right?

the problem is the program TRAPPED at the address label "_G"
i am not sure whether writing to modem register work or not. but at least it can loop out from the subroutine, so i assume it does work. anyone have any idea what's wrong with my "reading-from-modem" subroutine?

could anyone please help me figure this? Thanks.

~.~.~.~ Two subroutine i am talking about:
W_Modem:
BCLR 2,PTED
_A: BRCLR 5,SPI1S,_A
MOV SPI1,SPI1D
_B: BRCLR 5,SPI1S,_B
MOV SPI2,SPI1D
_C: BRCLR 5,SPI1S,_C
MOV SPI3,SPI1D
_D: BRCLR 5,SPI1S,_D
BSET 2,PTED
RTS

R_Modem:
BCLR 2,PTED
_E: BRCLR 5,SPI1S,_E
MOV SPI4,SPI1D
_F: BRCLR 7,SPI1S,_F
MOV SPI1D,SPI5
_G: BRCLR 7,SPI1S,_G ;;; GET TRAPPED HERE
MOV SPI1D,SPI6
BSET 2,PTED
RTS
Labels (1)
0 Kudos
Reply
14 Replies

1,521 Views
rocco
Senior Contributor II
Hi, Cschai:

In order to read each byte from the SPI, you need to write a byte. In your read routine, you write a byte to get the first byte, but you aren't writing a second byte to read the second byte. That is why you hang waiting for the second byte: no second transfer is taking place.

Hope that helps.
0 Kudos
Reply

1,521 Views
cschai
Contributor I
HI rocco,

Thanks. But i don't think so.
Do you have MC1321x Reference Manual (MC1321xRM.pdf)? If yes, please refer to page 4.15

it said that, a singular transaction contains 3 byte (one byte header and 2 bytes payload). so i think that when i send my first byte of header, i should expect 2 bytes of data from that intended register (each modem register is formatted in 16 bits).

so do u have any idea? thanks. thanks a lot.
0 Kudos
Reply

1,521 Views
peg
Senior Contributor IV
Hi cschai,
 
Without getting right into this, I think the problem is this:
 
The radio is slave and the processor is master on the SPI.
 
If you expect a 3 byte response to a 1 byte command you need to send 3 dummy characters out after the command to get the 3 bytes of response in. The slave cannot initiate a transaction on its own!
 
Regards
Peg
 
0 Kudos
Reply

1,521 Views
cschai
Contributor I
sorry i dont get it.
what is dummy character?
Thanks!
0 Kudos
Reply

1,521 Views
peg
Senior Contributor IV
Hi,
 
Slave to master comms can only occur simultaneously with master to slave comms.
So to read anything in the master must send something (anything or "dummy") out.
So you send command byte and then "something" 3 times, transaction finished.
 
Get it?
 
Regards
Peg
 
0 Kudos
Reply

1,521 Views
cschai
Contributor I

is it possible that the dummy thing u said is CE pin (Chip Enable)?
or you mean in order to read 2 byte data, i need to send 2 command?
could you please have a look on the attached doc? i copy it from the reference manual.
please! thanks!

 

SPI_Singular_Transaction.doc

Message Edited by t.dowe on 2009-10-27 12:30 PM
0 Kudos
Reply

1,521 Views
peg
Senior Contributor IV
Hi,
 
No, see the SPICLK? Only the master can generate the clock. The only way to get it to do that is to send something. The clock is required to clock the slave data across to the master. Also see where it says "valid data"? Well there is "don't care" or "dummy" data actually moving on the other line in the other direction at the same time.
 
Looks like you need to read the SPI chapter of the GB60 manual!
 
Also the first sentence on the second page where it says "send data" i think this should be qualified with "valid" (i.e. send valid data)
 

Message Edited by peg on 2007-02-0408:21 PM

0 Kudos
Reply

1,521 Views
cschai
Contributor I
ok. thanks. thanks so much, i think i know what you mean already. thanks.

and one more thing: for any first byte data, i need to low_activate CE first then write to SPI data register, OR write to SPI data register first then low_activate CE?

thanks...
0 Kudos
Reply

1,524 Views
peg
Senior Contributor IV
Hi,
Drive CE first as the transmission starts as soon as you write to the SPI data register!
 
0 Kudos
Reply

1,524 Views
cschai
Contributor I
so is it that i should write as below?
from the attached doc, you see with one byte command i should expect 2 bytes data
then how many dummy should i send?
a. i try send 2 dummy (included part that i had commented), but still hang, at different place, this time at label _F
b. i try one dummy but it seem that the data i get is not correct


for example: reading from modem register (0x25)

MOV #$B5,SPI4 ;bit7=1 as reading
JSR R_Modem
.....
.....
R_Modem:
BCLR 2,PTED ;enable CE
_E: BRCLR 5,SPI1S,_E ;cheack SPI Transmit Buffer flag to write the cammand
MOV SPI4,SPI1D

/*_EF: BRCLR 5,SPI1S,_EF ;send 1st dummy,
/* MOV DUMMY,SPI1D

_F: BRCLR 7,SPI1S,_F ;read 1st data
MOV SPI1D,SPI5
_FG: BRCLR 5,SPI1S,_FG ;send 2nd dummy
MOV DUMMY,SPI1D
_G: BRCLR 7,SPI1S,_G ;read 2nd data
MOV SPI1D,SPI6
RTS

.....

THANKS
0 Kudos
Reply

1,524 Views
bigmac
Specialist III
Hello,
 
To reiterate what Rocco and Peg have already said, for each byte sent by the master, there will be a corresponding byte simultaneously returned by the slave (not the response to the byte just sent), and conversely, for each byte returned from the slave, this will have been initiated by the master sending a byte.  The following code might make this a little more evident -
 
R_Modem:
  BCLR  2,PTED     ; Enable CE
  LDA   SPI4       ; Command byte
  JSR   SPI_TXRX   ; Ignore returned value
  LDA   #0         ; Dummy value sent
  JSR   SPI_TXRX
  STA   SPI5       ; First returned value
  LDA   #0         ; Dummy value sent
  JSR   SPI_TXRX
  STA   SPI6       ; Second returned value
  BSET  2,PTED     ; Disable CE
  RTS
  
SPI_TXRX:
  BRCLR 5,SPI1S,*  ; Wait for Tx buffer empty
  STA   SPI1D      ; Send value
  BRCLR 7,SPI1S,*  ; Wait for Rx buffer flag
  LDA   SPI1D      ; Returned value - also clears flag
  RTS
 
Regards,
Mac
 

Message Edited by bigmac on 2007-02-0511:42 AM

0 Kudos
Reply

1,524 Views
peg
Senior Contributor IV
Hi,
One caveat on using bigmac's code "as is"
The radio may require some setup time to process the command and load its tx buffer with the response, so there may need to be some delay prior to the first LDA #0 (or maybe even the second also but less likely).
This is more likely at higher SPI clock speeds.
Otherwise the code is as I intended.
 
0 Kudos
Reply

1,525 Views
cschai
Contributor I
Thanks you guys...
I really appreciate it.

Yea. it successfully write to and read from Modem register. I try to write some data to modem register and read back the data, and the data i read back correct.

Thanks.

so may be anyone can help me on MC13213 Transceiver this time! i had filed another question "MC13213 (SRB) TxRx Operation Sequence" on this forum! so i hope some helps from you guys.

Thanks. Thanks a lot!!!
0 Kudos
Reply

1,525 Views
cschai
Contributor I
Hi MAC,

Thanks.... any idea on sequence how to send/receive data using the modem? i had filed question on that, titled MC13213 (SRB) TxRx Operation Sequence. Could you please have a look?

Thanks again...
0 Kudos
Reply