Strange behavior of SPIS_PutArray()

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Today, while I was studying the problem of npuruss-san,

https://community.cypress.com/thread/37205

I encountered an interesting behavior of SPIS.

With this project I'm using a couple of CY8CKIT-044s,

one for SPI_Master and the other for SPI_Slave.

When I call SPIM_PutArray(), the SPI_Slave receives exact

data assigned by SPIM_PutArray().

But after I call SPIS_PutArray() and when SPI_Master

send another transaction, the MISO data sent out from

SPI_Slave is 1 byte off from the data assigned by SPIS_PutArray().

For example, for the first loop, before SPI_Master sends anything,

I put 0D,0C,0B,0A,09,08,07,06,05,04,03,02,01 to SPIS_PutArray().

When SPI_Master sends commands,  SPI_Slave sends out

00,0D,0C,0B,0A,09,08,07,06,05,04,03,02

(See attached Oscilloscope Screen Shot)

Oscillo_screen.JPG

Naturally, SPI_Master received

00,0D,0C,0B,0A,09,08,07,06,05,04,03,02

although it was expecting to receive

0D,0C,0B,0A,09,08,07,06,05,04,03,02,01.

Then for the next transaction, SPI_Slave prepares sTxBuffer with

F0,E1,D2,C3,B4,A5,96,87,78,69,5A,4B,3C

But SPI_Master receives

01,F0,E1,D2,C3,B4,A5,96,87,78,69,5A,4B

(This 01 seems to be the last byte of the previous PutArray())

Again, SPI_Slave prepare sTxBuffer with

0D,0C,0B,0A,09,08,07,06,05,04,03,02,01

And SPI_Master receives

3C,0D,0C,0B,0A,09,08,07,06,05,04,03,02

(This 3C seems to be the last byte of the previous PutArray())

So I suppose that with this project,

SPIM_PutArray() generates correct data on MOSI pin

but

SPIS_PutArray() generates 1byte data from previous SPIS_PutArray()

before sending the data assigned by current SPIS_PutArray().

Now my question is:

Am I missing something to make SPIS_PutArray() work correctly?

Or is/are there way to reset the data pointer of SPIS

so that I can send correct data?

Attached are my test projects and log/screen copies.

master_log.JPG

slave_log.JPG

moto

0 Likes
1 Solution

Since you are using the SPI Slave component (instead of the SCB SPI component in slave mode), look at the documentation of the _PutArray() method. It says:

If using modes where CPHA = 0, call the SPIS_WriteTxDataZero() function before calling the SPIS_PutArray() function.

The SPIS_WriteTxDataZero() method directly writes into the SPI shift register, which otherwise is pre-occupied with a zero.

View solution in original post

0 Likes
6 Replies