You are here

Reading from SPIM master mode | Cypress Semiconductor

Reading from SPIM master mode

Summary: 2 Replies, Latest post by ANKS on 18 Nov 2016 01:08 AM PST
Verified Answers: 1
Last post
Log in to post new comments.
user_266054099's picture
User
1 post

I trying to read the MCP23S18-E/SP IO expander from micochip. 

I write operation is working fine but I can not read the port from the IC. 

Please see the attached files .

Ahmed

user_1377889's picture
User
9583 posts

Welcome in the forum, Ahmed.

For every bit (byte) the SPI interface gets, one bit (byte) is returned immediately. When the very first byte is sent, the interface does not "know" yet what to answer, so a dummy byte is returned which should be skipped.
SPI has no read command, so you must send dummy bytes to retrieve the information wanted.
A pitfall is the select line, which is automatically taken low when a byte is sent. When the buffer is empty it is taken high again. This can lead to interface errors when the byte sequence is not provided fast enough resulting in ss-line glitches.

Your WriteByteArray() will not work, because sizeof(data) is always 4 which is the size of a pointer.

In Read_Reg() the number of bytes written do not match the number of bytes read.

It is always more helpful when you post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

 

Bob

ANKS's picture
Cypress Employee
88 posts

Renamed SPIM_ReadByte(), SPIM_WriteByte()APIs to SPIM_ReadRxData(), SPIM_WriteTxData()

SPIM_ReadRxData() API returns invalid data if the FIFO is empty. Call SPIM_GetRxBufferSize(), and if it returns a nonzero value then it is safe to call the SPIM_ReadRxData() function.

Log in to post new comments.