I am using the SPI in an LCP824 and will upgrade to the LPC845 (as soon as I can get one). I have an older test routine running in the LPC824 to read/write serial Flash. This used SSEL0, and works fine. Now I am trying to move and expand this code to another project with Serial EEPROM and an Analog part configured over SPI. To save pins in the HVQFN33 package I want to use one SPI block and two SSEL lines to select the correct device. Looking at the example code (from which my SPI Flash code was derived) I do not understand how to load a register or structure before the write/read in order to select SSEL1 during the transfer.
I am #defining the PinSPI_* values as their port numbers and then setting the SPI up as:
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_SWM_MovablePinAssign(SWM_SPI0_SSEL0_IO, PinSPI_NCSM); /* NCSM -33H package pin 11 */
Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL0_IO, PinSPI_NCSE); /* NCSE -33H package pin 5 */
Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, PinSPI_CLK); /* -33H package pin 14 */
Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, PinSPI_MISO); /* -33H package pin 26 */
Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, PinSPI_MOSI); /* -33H package pin 25 */
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_SPI_ConfigureSPI(LPC_SPI, SPI_MODE_TEST | /* Enable master/Slave mode */
SPI_CLOCK_CPHA0_CPOL0 | /* Set Clock polarity to 0 */
SPI_CFG_MSB_FIRST_EN |/* Enable MSB first option */
SPI_CFG_SPOL_LO); /* Chipselect is active low */
Chip_SPI_CalClkRateDivider(LPC_SPI, 100000) ; /*&* ?? NEJ *&*/
DelayConfigStruct.FrameDelay = 100 ;
DelayConfigStruct.PostDelay = 100 ;
DelayConfigStruct.PreDelay = 100 ;
DelayConfigStruct.TransferDelay = 100 ;
Chip_SPI_DelayConfig(LPC_SPI, &DelayConfigStruct);
Chip_SPI_Enable(LPC_SPI);
I have #defined some command and length values for interaction with the Flash (FCMD_* and FCMDLEN_*).
Then to do some function with the Flash I create a function to write the command and read back the response:
unsigned char FlashJEDECRead(unsigned char * MfgNr, unsigned int * FlashIDint)
{
bufferInit();
TxBuf[0] = FCMD_READ_JEDEC_ID ; /* 0x9F */
XfSetup.Length = FCMDLEN_READ_JEDEC_ID ; /* 4 */
XfSetup.pTx = TxBuf;
XfSetup.pRx = RxBuf;
XfSetup.RxCnt = XfSetup.TxCnt = 0;
XfSetup.DataSize = 8;
Chip_SPI_RWFrames_Blocking(LPC_SPI, &XfSetup);
/* Get results from Buf and return values */
*MfgNr = (unsigned char)(0x00FF & RxBuf[1]) ;
*FlashIDint = (unsigned int)((0xFF00 & (RxBuf[2] << 8)) | (0x00FF & RxBuf[3])) ;
return(TRUE) ;
}
My question is, when I want to extend this to use SSEL0 and SSEL1 I will need to specify which one to use for the transaction. Is there a function, or is it bits that get ored into a register and then the configuration is updated? Does this happen at the SPI configuration level, or when I am setting up the structure for the transaction.
I have seen some information in SPI_common_8xx.h that suggests that I want to set one of two bits in the SPI Transmitter Data and Control register. But the #defines there only show de-asserting a (or all) SSELn bit(s). And it is not clear to me what function I would call to use those bits to set the appropriate register.
Carlos:
Thanks for the answer the Driver always assuming SSEL0 was the critical piece of information that I did not have. I had been surprised as to why the old code with one device on SSEL0 worked without specifying which one to use. Now I know how to make the new code with two devices work.
--Norm
Hi Norman,
If you want to use the SSEL1 from the same SPI0 module I believe you have to change the following line:
Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL0_IO, PinSPI_NCSE); /* NCSE -33H package pin 5 */
To this:
Chip_SWM_MovablePinAssign(SWM_SPI0_SSEL1_IO, PinSPI_NCSE); /* NCSE -33H package pin 5 */
The drivers seems to be hardcoded to only use the SSEL0 but you could use the Chip_SPI_SetControlInfo() function to indicate which slave you re going to use and create your own defines to indicate the different SSELx pins. The SPI_TXCTL register can be used to switch between the slaves.
Hope it helps!
Best Regards,
Carlos Mendoza
Technical Support Engineer