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_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_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 ;
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)
TxBuf = 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;
/* Get results from Buf and return values */
*MfgNr = (unsigned char)(0x00FF & RxBuf) ;
*FlashIDint = (unsigned int)((0xFF00 & (RxBuf << 8)) | (0x00FF & RxBuf)) ;
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.