cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
1,499 Views
Registered: ‎09-16-2019

XSpi manually control chip select (SS) signal through C code (SDK)

Jump to solution

Hello,

I would like to manually control the slave select line for the Quad SPI peripheral at a certain point in my C code. In PG153 I have read that bit[7] of the SPICR register can be used to toggle the slave select. However, I do not see any examples on how to do this in C code. 

My Quad SPI is set up as follows in my C code:

 

/* normal mode AXI QUAD SPI Initialize */
	ConfigPtr_spi = XSpi_LookupConfig(XPAR_AXI_QUAD_SPI_0_DEVICE_ID);
	Status = XSpi_CfgInitialize(&Spi_AXI, ConfigPtr_spi, XPAR_AXI_QUAD_SPI_0_BASEADDR);
	Status = XSpi_SetOptions(&Spi_AXI, XSP_MASTER_OPTION  | XSP_MANUAL_SSELECT_OPTION |  XSP_CLK_PHASE_1_OPTION);
	XSpi_Start(&Spi_AXI);
	XSpi_SetSlaveSelect(&Spi_AXI, 0x01);
	XSpi_IntrGlobalDisable(&Spi_AXI);

I need to do this to meet the requirements for a device. It requires that after a read command is received, the chip select signal remains active until a certain number of bytes are read in without the chip select toggling. Using the  XSpi_Transfer() function, the chip select signal automatically toggles and I need to stop this from happening. 

 

Thank you 

0 Kudos
1 Solution

Accepted Solutions
venui
Moderator
Moderator
1,425 Views
Registered: ‎04-09-2019

https://github.com/Xilinx/embeddedsw/blob/master/XilinxProcessorIPLib/drivers/spi/src/xspi.c

Line nummber 846 is used to deassert the CS once the transfer completed.

If you don`t want to deassert the CS please comment the same line and test.

Regards,

Venu

View solution in original post

0 Kudos
5 Replies
venui
Moderator
Moderator
1,426 Views
Registered: ‎04-09-2019

https://github.com/Xilinx/embeddedsw/blob/master/XilinxProcessorIPLib/drivers/spi/src/xspi.c

Line nummber 846 is used to deassert the CS once the transfer completed.

If you don`t want to deassert the CS please comment the same line and test.

Regards,

Venu

View solution in original post

0 Kudos
jg_spitfire
Adventurer
Adventurer
1,217 Views
Registered: ‎12-10-2019
Hi, could you tell me which line are you talking about?, I think that the file has been updated and line 846 is a comment, thanks
0 Kudos
jg_spitfire
Adventurer
Adventurer
1,202 Views
Registered: ‎12-10-2019

@venui  I have seen the function you mentioned before, xilinx provide an example for spi master where you use it for select the slave, is the file:

xspi_eeprom_example

path:

embeddedsw\XilinxProcessorIPLib\drivers\spi_v4_4\examples

I have a query in this part, I hope you could help me (line 263)

	/*
	 * Set the SPI device as a master and in manual slave select mode such
	 * that the slave select signal does not toggle for every byte of a
	 * transfer, this must be done before the slave select is set
	 */
	Status = XSpi_SetOptions(&Spi, XSP_MASTER_OPTION |
					XSP_MANUAL_SSELECT_OPTION);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Select the slave on the SPI bus, the EEPROM device so that it can be
	 * read and written using the SPI bus
	 */
	Status = XSpi_SetSlaveSelect(&Spi, SEEPROM_SPI_SELECT);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

 If you are configuring the slave select as manual, why can I see the code to select the slave but I don`t see the code to deselect it?, I expected to find something like this:

	Status = XSpi_SetSlaveSelect(&Spi, 0);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

So, why do you select the slave but never deselect it if we are using "manual option" ???

 

thanks

0 Kudos
jg_spitfire
Adventurer
Adventurer
1,160 Views
Registered: ‎12-10-2019

Hi davidfhorowitz@lmco.com  could you tell me which line did you have to uncomment to prevent the disabling of the SS?, I read the solution but it seems that the code has been updated and now that line is a comment, no code.

thanks

0 Kudos
venui
Moderator
Moderator
1,062 Views
Registered: ‎04-09-2019

Hi,

In the transfer functions assertion ans de-assertion of SS has been taken care.

XSpi_SetSlaveSelectReg(InstancePtr, InstancePtr->SlaveSelectMask); line in function definition of  XSpi_Transfer function can be found in the end of function definition.

Regards,

Venu 

0 Kudos