UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Reply

SPI strange behaviour

Highlighted
Visitor
Posts: 5
Registered: ‎08-11-2017

SPI strange behaviour

Hi Xilinx,

 

We have some weird problems in order to get a SPI working example. We are using ZC702 board and we have configured it to use SPI_1 via EMIO. We want to use it as a master. Well, we have also added a ILA debug core to watch the signals, and we generate the bitstream succesfully.

 

Our first example was to perform the spi_selftest. TEST PASSED and everything seems correct. Later on, we made an example to configure the SPI instance as a master and send a buffer over MOSI line. The main code is this:

 

int main()
{
    init_platform();

    print("Hello SPI\n\r");

	int Status;
	XSpiPs_Config *SpiConfig;

	/*
	 * Initialize the SPI driver so that it's ready to use
	 */
	SpiConfig = XSpiPs_LookupConfig(SPI_DEVICE_ID);
	if (NULL == SpiConfig) {
		return XST_FAILURE;
	}

	Status = XSpiPs_CfgInitialize((&SpiInstance), SpiConfig, SpiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	Status = XSpiPs_SetOptions(&SpiInstance, XSPIPS_MASTER_OPTION);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	u8 sendBuffer[MAX_DATA];
	memset(sendBuffer, 0x3, sizeof(sendBuffer));

	// Send data
	Status = XSpiPs_Transfer((&SpiInstance), sendBuffer, NULL, sizeof(sendBuffer));
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

    cleanup_platform();
    return 0;
}

The program simply initializes the device, configures it as a master with MASTER_OPTION, create a buffer of 100 values to send data and initializes it with 0x3. We are able to execute it, but we have detected some strange behaviour related to SCLK, MOSI lines. Attached you can find an snapshot...

SPI.png

As you can see, SCKL not seems to be working properly. Also the data reflected in MOSI line is wrong because we are sending 0x3 (00000011). We thought it could be something related to Zynq FCLK_0, so we changed it to 25MHz to match SPI maximum frequency when using EMIO pins but we achieve the same results. Could you give us any clue about whats is happening?

 

Thank you in advance.

Regards

Voyager
Posts: 1,732
Registered: ‎06-24-2013

Re: SPI strange behaviour

Hey @dromerol,

 

Is your ILA clock high enough, it seems to me a little like sampling issues.

 

Best,

Herbert

-------------- Yes, I do this for fun!
Visitor
Posts: 5
Registered: ‎08-11-2017

Re: SPI strange behaviour

Hi @hpoetzl, thank for your answer.

 

The clock we are using is 25MHz, and it's the same that set-up debug tool assign automatically.

 

Best,

David

Voyager
Posts: 1,732
Registered: ‎06-24-2013

Re: SPI strange behaviour

Hey @dromerol,

 

So you are trying to sample a 25MHz clock with a 25MHz clocked ILA ... not going to work :)

 

The ILA is like a logic analyzer and it is typically used to sample data synchronous to a given clock.

 

Try to increase the ILA clock to at least 100MHz, this will give you a valid (although uneven) clock sample.

 

Hope this helps,

Herbert

-------------- Yes, I do this for fun!
Posts: 661
Registered: ‎07-31-2012

Re: SPI strange behaviour

Visitor
Posts: 5
Registered: ‎08-11-2017

Re: SPI strange behaviour

Hi again,

 

Thank you both for your help, we´ll take this into account and hope it helps to clarify this behaviour.

 

Regards,

David

Voyager
Posts: 1,732
Registered: ‎06-24-2013

Re: SPI strange behaviour

You're welcome!

 

Best,

Herbert

-------------- Yes, I do this for fun!
Visitor
Posts: 5
Registered: ‎08-11-2017

Re: SPI strange behaviour

Hi again @hpoetzl@pvenugo

 

After taking into account your advices, I am able to see things going on. Now, CLK is coherent, and indeed the data I sent trough MOSI line as you can see in the picture below62e17fb7-6aad-49cd-9e28-8c2c7e2078f2.jpgHowever, I am not able to receive any response from my slave trough MISO line, it is like the transfer never ends because my SpiInstance->IsBusy field is always = 1....

I am doing my transfer in the following way (using XSpiPs_Transfer function from xspips.h)

 

 

int Status;
Status = XSpiPs_Transfer((&SpiInstance), pBuffer, NULL, bytes); // only want to send
if (Status != XST_SUCCESS) {
	return XST_FAILURE;
}
return XST_SUCCESS;

 

 

And my receive code is similar...and it gets always trying to receive data but it seems the bus is busy....

 

int Status;
Status = XSpiPs_Transfer((&SpiInstance), pBuffer, pBuffer, bytes);  // only want to receive
if (Status != XST_SUCCESS) {
       return XST_FAILURE;
}
return XST_SUCCESS;

Anyone could help me a little bit? Any clue will be very much appreciated.

 

Thank you

 

 

 

Adventurer
Posts: 74
Registered: ‎06-19-2015

Re: SPI strange behaviour

Hi @dromerol

 

Once again verify MOSI, MISO and CS pins assignment properly.

Which pins from Zynq you have made external? Pls share your BD design screenshot...