cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Contributor
Contributor
299 Views
Registered: ‎07-17-2019

XSpiPs library modification

Jump to solution

hi,

We want to communicate with a device that uses 16 bit addressing with following 8 bit data via SPI in PS. However, XSpiPs uses 8 bit addressing and shift register logic with read and write buffer. I found out that we can write 16 bit adress data in a buffer and feed the SPI write function's write buffer with it. I am confused about how to give the inputs of the function in terms of both write and read. Indeed,

1) what should be the inputs of the SPI transfer functions arguments when writing. Is it ok ,in the following ,if we create WriteBuffer[3] with {WriteBuffer[0], WriteBuffer[1]} is address and WriteBuffer[2] is the data?.

ex:

WriteBuffer[0]=0x10;
WriteBuffer[1]=0x11;
WriteBuffer[3]=0x12;

 

status=XSpiPs_Transfer(SpiInstancePtr, WriteBuffer, NULL, 3); // to send data

2)what should be the inputs of the SPI transfer function arguments when reading is it ok ,in the following ,if we create Writebuffer[2] with {Writebuffer[0], Writebuffer[1]} is address and Readbuffer is the data?.

 

WriteBuffer[0]=0x10;
WriteBuffer[1]=0x11;
ReadBuffer=0;

status=XSpiPs_Transfer(SpiInstancePtr, WriteBuffer, ReadBuffer, 1); // to receive data

 

Not1: Can we use XSpiPs library as 3-wire SPI mode. (i.e. clk, cs and sdio(inout) ,not clk, cs, miso, mosi)

Not2: The SPI type that the device requires is in the attachment for both write and read.

 

Tags (2)
read.jpg
write.jpg
0 Kudos
Reply
1 Solution

Accepted Solutions
Moderator
Moderator
209 Views
Registered: ‎04-09-2019

Hi,

Write operation is fine but you need to transfer dummy byte after the command to read data from slave device so your read should be as follows:

1) what should be the inputs of the SPI transfer functions arguments when writing. Is it ok ,in the following ,if we create WriteBuffer[3] with {WriteBuffer[0], WriteBuffer[1]} is address and WriteBuffer[2] is the data?.

ex:

WriteBuffer[0]=0x10;
WriteBuffer[1]=0x11;
WriteBuffer[3]=0x12;

 

status=XSpiPs_Transfer(SpiInstancePtr, WriteBuffer, NULL, 3); // to send 2 byte write command and 1 byte data to write to slave

2)what should be the inputs of the SPI transfer function arguments when reading is it ok ,in the following ,if we create Writebuffer[3] with {Writebuffer[0], Writebuffer[1]} is address and Readbuffer is the data?.

 

WriteBuffer[0]=0x10;
WriteBuffer[1]=0x11;
WriteBuffer[2]=0x00;

status=XSpiPs_Transfer(SpiInstancePtr, WriteBuffer, Readbuffer, 3); // to send 2 bytes of read command + 1 byte dummy write data to get 1 byte read data parallelly.

Make sure that your sending proper commands for reading and writing the data from slave device

Note: 3 wire SPI is not supported.

Rgards,

Venu

View solution in original post

1 Reply
Moderator
Moderator
210 Views
Registered: ‎04-09-2019

Hi,

Write operation is fine but you need to transfer dummy byte after the command to read data from slave device so your read should be as follows:

1) what should be the inputs of the SPI transfer functions arguments when writing. Is it ok ,in the following ,if we create WriteBuffer[3] with {WriteBuffer[0], WriteBuffer[1]} is address and WriteBuffer[2] is the data?.

ex:

WriteBuffer[0]=0x10;
WriteBuffer[1]=0x11;
WriteBuffer[3]=0x12;

 

status=XSpiPs_Transfer(SpiInstancePtr, WriteBuffer, NULL, 3); // to send 2 byte write command and 1 byte data to write to slave

2)what should be the inputs of the SPI transfer function arguments when reading is it ok ,in the following ,if we create Writebuffer[3] with {Writebuffer[0], Writebuffer[1]} is address and Readbuffer is the data?.

 

WriteBuffer[0]=0x10;
WriteBuffer[1]=0x11;
WriteBuffer[2]=0x00;

status=XSpiPs_Transfer(SpiInstancePtr, WriteBuffer, Readbuffer, 3); // to send 2 bytes of read command + 1 byte dummy write data to get 1 byte read data parallelly.

Make sure that your sending proper commands for reading and writing the data from slave device

Note: 3 wire SPI is not supported.

Rgards,

Venu

View solution in original post