MM9Z1_638 SPI communication as slave

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

MM9Z1_638 SPI communication as slave

433 Views
da_jsi
Contributor I

Hello,

 

I have started to work with the MM9Z1_638 reference design board. I want to communicate with the board over SPI. The board should be the slave.

 

My Problem is, that I cannot set the SPI Data Register to send values from the slave to the master.

 

For example, when I execute the code:

// SPIDR before execution: 0x0000

while (!SPISR_SPTEF) DO_NOTHING;           //Wait for empty data register

SPIDR = 0x1111;                             //transmit a 16-bit word 

 

// SPIDR register hasn't changed it is still 0x0000

 

while (!SPISR_SPIF) DO_NOTHING;           //Wait for receiving data

return SPIDR;

 

The master receives 0x0000 from the board. When the master is sending for example 0x0011, the SPIDR is changing from 0x0000 to 0x0011 and return gives me 0x0011 back. But the board is still not able to change SPIDR.

 

I'm using the RD9Z1-638-4LI_APPSP example software. Can somebody help me?

Labels (1)
0 Kudos
1 Reply

238 Views
Martin35804
NXP Employee
NXP Employee

Hi,

-each SPI transfer comprises a transmission and a reception. The master device clocks the slave device and for each bit sent (through the MOSI output) another one is read (through the MISO input).

The SPID register operates as a read/write double buffer: data written to SPID is transferred to the internal shift register at the beginning of the transfer (this sets the transmitter buffer empty (SPIS:SPTEF) flag). When the transfer finishes, the received data (stored in the SPI internal shift register) is transferred to the SPID register and the SPI read buffer full (SPIS:SPRF) flag is set. So check whether the flags are set.

These two flags can be used to control and monitor SPI transfers. SPRF, when set, generates an interrupt request if SPIC1:SPIE = 1.

SPRF is cleared by first reading SPIS (when SPRF is set) and then reading the SPID register.

SPTEF, when set generates a interrupt request if SPIC1:SPTIE = 1. It is cleared by reding SPIS when SPTEF is set and then writing into SPID.

It is necessary to read SPIS:SPTEF before writing data to SPID. Failing to do so causes the write to be ignored by the SPI interface and no data transmitted!

0 Kudos