cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
thinkingspark
Visitor
Visitor
15,383 Views
Registered: ‎07-15-2009

About the function XSpi_Transfer()

I am appreciate for your help

 

In my MicroBlaze core, a spi module is used to communicate with a fingerprint sensor.Here I am confused  when I use the function

 

XSpi_Transfer(XSpi *InstancePtr,

                        Xuint8 *SendBufPrt,

                        Xuint8 *RecvBufPtr,

                        unsigned int ByteCount) to send/receive data to/from the sensor.

 

Here is the problem:

 

I set the parameter C_FIFO_EXIST =1,which indicates that both receive fifo and send fifo are present in the spi module,and i think this is an appropriate comprehension accroding to the spi datasheet. But I don't know how to define the pointer variables SendBufPtr and RecvBufPtr who can point to the existing FIFOs in the SPI module. And in my later searching for solutions on the web, i find someone defined his fifos as follow in his c-code:

Xuint8 RecvData[num];

Xuint8 SendData[num];

and their usage is XSpi_Transfer(InstancePtr, &SendData[0], &RecvData[0], num).Does this mean that the fifos must be defined manually or there is any other solution for defining the fifos more effectively?

 

 

Thank you for your help!

 

ThinkingSpark

 

0 Kudos
8 Replies
thinkingspark
Visitor
Visitor
15,357 Views
Registered: ‎07-15-2009

Hi there,my experiments for testing the manually defined FIFOs show me that the values in the FIFOs can never be changed. Here is part of my C code:

 

Xuint8 SendData[2]={0x11,0x21}; 

Xuint8 RecvData[2]={0,0};

XStatus status;

 ...................

 

status= XSpi_Transfer(&opb_spi_fgs, RecvData[0], RecvData[0], 1);//receive one byte from the slave device, and don't care about what to be

                                                                                                               // send. 

I am sure the returned status is SUCCESS,but RecvData[0] will always maintain its initialized value. For example, if i initialize RecvData[0] with the data 0xff,the final value of RecvData[0] after successfully calling XSpi_Tranfer() will be 0xff.That's to say, the function has nothing to do with the manually defined FIFOs, who can tell me the truth. thanks!

 

 

0 Kudos
nfogh
Contributor
Contributor
15,347 Views
Registered: ‎02-12-2009

I'm not sure if it is just a typo, but you seem to have forgotten the address of operator (&)

 

status= XSpi_Transfer(&opb_spi_fgs, RecvData[0], RecvData[0], 1)

 

should be

 

status= XSpi_Transfer(&opb_spi_fgs, &RecvData[0], &RecvData[0], 1)

 

or (more clearly)

 

status= XSpi_Transfer(&opb_spi_fgs, RecvData, RecvData, 1)

 

- Cheers

0 Kudos
pumaju1808
Scholar
Scholar
15,334 Views
Registered: ‎08-14-2007

hi,

 

your spi device has two wires (MISO and MOSI)?? or only one??

you only want to acquire data from your spi??

 

well the general steps to use SPI core are:

 

1. declarate a XSpi device:    XSpi TempSensor;

2. Initialization:                        XSpi_Initialize(TempSen,TempID);

3. Set Options to configure CPHA and CPOL and if your Spi core is master or not:        XSpi_SetOptions(TempSen,XSP_MASTER_OPTION);

4. Start the device:    XSpi_Start(TempSen); 

5. is you do not use interrupts, you must disable them:  XSpi_mIntrGlobalDisable(TempSen);

6. Select you device:  XSpi_SetSlaveSelect(TempSen,0x01);     

7. Request data:   XSpi_Transfer(TempSen, &RecvBuf[0], &RecvBuf[0], 2);

in my case i am using a temperature sensor of 16 bits of data, and i only want to receive from this sensor

8. Repeat step 7 as you need data.

 

The use of Spi transfer can be explain next:

 

for more information see the API Documentation for your SPI core

 

Regards

 

 

 

 

 

spi_fig.PNG
0 Kudos
thinkingspark
Visitor
Visitor
15,323 Views
Registered: ‎07-15-2009

Hi nfogh,thank you for answering me.

 

I think i had got a mistake because of my carelessness during writing the most recent message. I am sorry for that :-)

 

the following is my whole C code.

 

#include "xparameters.h"
#include "xutil.h"
#include "xgpio.h"
#include "xspi_l.h"
#include "xspi.h"

void delay(Xuint32 value)
{
   Xuint32 i,j;
 for(i=0; i<value; i++)
    for(j=0; j<25; j++);
}

 

int main(void)
{
  
 XGpio LEDs_8Bit;
 
 XSpi  opb_spi_fgs;

 XStatus spi_status;

 Xuint8 sendfifo[2]={0x11,0x21};
 Xuint8 recvfifo[2]={0xEF,0};
 
  
 XGpio_Initialize(&LEDs_8Bit, XPAR_LEDS_8BIT_DEVICE_ID);
 XGpio_SetDataDirection(&LEDs_8Bit, 1, 0xffffffff);
 
 
 XSpi_Initialize(&opb_spi_fgs, XPAR_OPB_SPI_FGS_DEVICE_ID);
 

XSpi_SetOptions(&opb_spi_fgs, 0x11 ); //SET the spi device as the MASTER and manual slave select.


 
 //reset the fingerprint sensor.

 //note: on my fingerprint sensor, there is a RESET_N pin.But, you know, the spi core xilinx given hasn't 

 //the reset output pin. so i set the LED core's LSB as the fingerprint sensor's reset and assign it to an

 //attachable pin on my spartan3e board by chaging the UCF file.
 XGpio_DiscreteWrite(&LEDs_8Bit, 1, 0x000000FF);
 delay(100000);
 XGpio_DiscreteWrite(&LEDs_8Bit, 1, 0x00000000);
 delay(100000);
 XGpio_DiscreteWrite(&LEDs_8Bit, 1, 0x00000003);
 //fgs reset complete
 

 XSpi_Start(&opb_spi_fgs); 
 

 XSpi_SetSlaveSelect(&opb_spi_fgs,0x1); 

 XSpi_mSendByte(XPAR_OPB_SPI_FGS_BASEADDR, 0x11); // send start instruction to the sensor,if

                                                                                                       //XSpi_mSendByte() is insteaded by Xspi_transfer(), and the next

                                                                                                       //XSpi_Transfer() will return the status BUSY! I don't know why.

                                                                                                       //so I use XSpi_mSendByte() to send inst.

 delay(100);
 XSpi_mSendByte(XPAR_OPB_SPI_FGS_BASEADDR, 0x21); // when the sensor received this inst. it will repare the status data contain the

                                                                                                       //information whether the fingerprint data is repared.

 delay(500);
  
 spi_status = XSpi_Transfer(&opb_spi_fgs, &recvfifo[0], &recvfifo[0], 1); //to read the status data, if recvfifo[0]=0x1,then the fingerprint data is

                                                                                                                    // repared, recvfifo[0]=0x0,then data isn't repared.
 delay(500);  

if(spi_status == XST_SUCCESS)

  if(recvfifo[0] == 0xef)
      XGpio_DiscreteWrite(&LEDs_8Bit, 1, 0x000000F3);  //this can always be executed. data of recvfifo[0] was unchanged.
   else
      XGpio_DiscreteWrite(&LEDs_8Bit, 1, 0x0000000F);

}

else

 xil_printf("failed");

 

regards

0 Kudos
thinkingspark
Visitor
Visitor
15,317 Views
Registered: ‎07-15-2009

HI,pumaju1808

 

Think you for your advice! and i think it is useful for me , I'll try your steps.

 

There are both MISO and MOSI pins on my spi fingerprint sensor device, and the MOSI on fgps is used to receive instructions from the master. you can see two of the instructions showed in the message i replied to nfogh.

 

I will come back to the question that  whether the FIFOs must be defined by myself?

 

regards!

0 Kudos
xiaofeip
Xilinx Employee
Xilinx Employee
15,186 Views
Registered: ‎08-07-2007

Hi,

 

There might be a misunderstanding here regarding the SPI FIFO. The  RecvData[num] and SendData[num] are buffers localed in the memory. They have nothing to do with the SPI FIFO. When SPI tranfer a data, the function will read the data from the buffer and sent them into the SPI FIFO0. it's similar for the read, the SPI driver will read the FIFO and store the data into the buffer.

 

-XF 

0 Kudos
jshukla1234
Visitor
Visitor
11,529 Views
Registered: ‎12-12-2012

I have the same issue here, my code is attached. I have been trying everything, can someone please tell me why the READBUFFER never fills? or goes back to the original value. Please see attached code.

 

SPI_Status = XSpi_Initialize(&SpiJig, SPI_DEVICE_ID);
xil_printf("XSpi_Initialize, Status: %d \n\r", SPI_Status);
if(SPI_Status != XST_SUCCESS) {
return XST_FAILURE;
}

//SPI_Status = SetupInterruptSystem(&SpiJig);
//XSpi_SetStatusHandler(&SpiJig, &SpiJig, (XSpi_StatusHandler)SpiHandler);
// if(SPI_Status != XST_SUCCESS) {
// return XST_FAILURE;
// }
SPI_Status = XSpi_SetOptions(&SpiJig, XSP_MASTER_OPTION |
XSP_MANUAL_SSELECT_OPTION |
XSP_CLK_PHASE_1_OPTION |
XSP_CLK_ACTIVE_LOW_OPTION);
xil_printf("XSpi_SetOptions, Status: %d \n\r", SPI_Status);
if(SPI_Status != XST_SUCCESS) {
return XST_FAILURE;
}
//XSpi_mIntrGlobalDisable(&SpiJig);
u32 EnableMask = 0x00;
XSpi_IntrGlobalDisable(&SpiJig);
SPI_Status = XSpi_SetSlaveSelect(&SpiJig, ATMEL_SPI_SELECT);
if(SPI_Status != XST_SUCCESS) {
return XST_FAILURE;
}
XSpi_Start(&SpiJig);
/*
* Specify the address in the flash device for the Erase/Write/Read
* operations.
*/
//unsigned int ByteCount = 5;
u32 Index;
u32 Address = ATMEL_FLASH_TEST_ADDRESS;
u16 chunk = 0xEE;
unsigned int ByteCount=2;
int jigaloop = 0, STOPNOW=200000000;
int *runnings = 1;

SPI_Status = SpiAtmelFlashRead(&SpiJig, Address, ByteCount);

//SPI_Status = SpiAtmelFlashWrite(&SpiJig, Address, chunk, ByteCount);
if(SPI_Status != XST_SUCCESS) {
Send_String("failed");
return XST_FAILURE;
}

for (jigaloop = 0; jigaloop < STOPNOW; jigaloop++)
{
*runnings = !runnings;
}

int pun;
for(pun = 0; pun < 6; pun++) {
if(ReadBuffer[pun] != (u8)0x01)
{
Send_String("\n\r");
Send_String("good");
}
else
{
Send_String("\n\r");
Send_String("bad0");
}
}

0 Kudos
nelly
Visitor
Visitor
10,852 Views
Registered: ‎11-06-2013

I had a very simple but big problem, in my case the fpga is the master and I receive MISO line from an arduino microcontroller, I try to save data in my outbuffer using:

 

SendWord=0x10;
XSpi_Transfer(&SpiInstance,SendWord,&outbuffer,2);

 

were:
u8 SenWord[2]={0,0};
u8 outbuffer[2]={0,0};

 

I should receive another byte as a response but the only I can always read or store in the outbuffer is the same 0x10 I am sending. I know arduino is sending because I can see the signals with the osciloscope.

 

In options I have:

XSpi_SetOptions(&SpiInstance, XSP_MASTER_OPTION| XSP_MANUAL_SSELECT_OPTION| XSP_LOOPBACK_OPTION);

 


Can anyone please help me? THANKS

Tags (1)
0 Kudos