Roronoa137
Junior Member level 1
Hi, I'm trying to write the code for SPI communication in SDK.
So I was following these steps:
a) Initialize the SPI driver
b) Perform a self-test
c) Set the SPI device options
d) Select the device on the SPI bus (SPI slave)
e) Start the SPI driver
f) Write data
g) Read the data
I reached step e), but I don't exactly how to proceed for the last two steps.
I am using an SPI QUAD AXI block in the PL connected to an external device and I would like to implement in the PS code the code to send/receive data from/to the external device through the SPI protocol.
I would like to implement two separate functions:
1) send data to the external device via SPI protocol
2) read the data from the external device via SPI protocol.
I discovered that the Spi_Transfer function provides data transfers on the SPI bus, and in particular:
1) XSpi_Transfer (InstancePtr, SendBuf, NULL, ByteCount) should be used if I only want to send data
2) XSpi_Transfer (InstancePtr, RecvBuf, RecvBuf, ByteCount) should be used if I just want to read the data
So I wrote my functions:
1)
2)
Is this the correct way to proceed?
Also, is there a way to check if the transmission was completed?
If anyone could clarify my doubts, I would be really grateful! Thanks!
So I was following these steps:
a) Initialize the SPI driver
b) Perform a self-test
c) Set the SPI device options
d) Select the device on the SPI bus (SPI slave)
e) Start the SPI driver
f) Write data
g) Read the data
I reached step e), but I don't exactly how to proceed for the last two steps.
I am using an SPI QUAD AXI block in the PL connected to an external device and I would like to implement in the PS code the code to send/receive data from/to the external device through the SPI protocol.
I would like to implement two separate functions:
1) send data to the external device via SPI protocol
2) read the data from the external device via SPI protocol.
I discovered that the Spi_Transfer function provides data transfers on the SPI bus, and in particular:
1) XSpi_Transfer (InstancePtr, SendBuf, NULL, ByteCount) should be used if I only want to send data
2) XSpi_Transfer (InstancePtr, RecvBuf, RecvBuf, ByteCount) should be used if I just want to read the data
So I wrote my functions:
1)
Code:
int WriteData (XSpi * SpiInstancePtr, u8 * SpiWriteBuffer, u8 * SpiReadBuffer, u16 ByteCount) {
int Status;
u32 Count;
u8 Test = 0x07;
for (Count = 0; Count <SPI_BUFFER_SIZE; Count ++) {
SpiWriteBuffer [Count] = (u8) (Count + Test);
xil_printf ("WriteBuffer [% d] =% d r", Count, SpiWriteBuffer [Count]);
xil_printf ("RdBuff% d =% x r", Count, ReadBuffer [Count]);
}
Status = XSpi_Transfer (SpiInstancePtr, SpiWriteBuffer, NULL, SPI_BUFFER_SIZE);
if (Status! = XST_SUCCESS) {
xil_printf ("Transfer_failure n");
return XST_FAILURE;
}
return XST_SUCCESS;
}
2)
Code:
int ReadTransfer (XSpi * SpiInstancePtr, u8 * SpiWriteBuffer, u8 * SpiReadBuffer, u16 ByteCount) {
int Status;
Status = XSpi_Transfer (SpiInstancePtr, SpiReadBuffer, SpiReadBuffer, SPI_BUFFER_SIZE);
if (Status! = XST_SUCCESS) {
return XST_FAILURE;
}
return XST_SUCCESS;
}
Is this the correct way to proceed?
Also, is there a way to check if the transmission was completed?
If anyone could clarify my doubts, I would be really grateful! Thanks!