AnsweredAssumed Answered

Can't get SPI1 to work on LPC1517

Question asked by Sukkin Pang on Oct 22, 2017
Latest reply on Nov 23, 2017 by Ian Benton

I'm using the LPC1517 with LPCXpresso 8.2.2 based on the peripheral_spi_polling project. 

The example is on SPI0 and with the loopback turned off I can see the clock and SSEL working correctly on the logic analyser.

 

When I change the code to SPI1 I can only see the clock, the SSEL line is not going low. 

Is there something else I need to do to get SPI1 working ?

 

#define CLK 17
#define SSEL 27
#define MISO 28
#define MOSI 13

static void Init_SPI_PinMux(void)
{

/* Enable the clock to the Switch Matrix */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, CLK, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, SSEL, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, MISO, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, MOSI, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));

Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, CLK); /* P0.0 */
Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, MOSI);/* P0.16 */
Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, MISO);/* P0.10 */
Chip_SWM_MovablePinAssign(SWM_SPI1_SSELSN_0_IO, SSEL); /* P0.9 */

/* Disable the clock to the Switch Matrix to save power */
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);

}

/* Turn on LED to indicate an error */
static void errorSPI(void)
{
Board_LED_Set(0, true);
while (1) {}
}

/* Setup SPI handle and parameters */
static void setupSpiMaster()
{
SPI_CFG_T spiCfg;
SPI_DELAY_CONFIG_T spiDelayCfg;
/* Initialize SPI Block */
Chip_SPI_Init(LPC_SPI1);
/* Set SPI Config register */
spiCfg.ClkDiv = 0xFFFF; /* Set Clock divider to maximum */
spiCfg.Mode = SPI_MODE_MASTER; /* Enable Master Mode */
spiCfg.ClockMode = SPI_CLOCK_MODE0; /* Enable Mode 0 */
spiCfg.DataOrder = SPI_DATA_MSB_FIRST; /* Transmit MSB first */
/* Slave select polarity is active low */
spiCfg.SSELPol = (SPI_CFG_SPOL0_LO | SPI_CFG_SPOL1_LO | SPI_CFG_SPOL2_LO | SPI_CFG_SPOL3_LO);
Chip_SPI_SetConfig(LPC_SPI1, &spiCfg);
/* Set Delay register */
spiDelayCfg.PreDelay = 2;
spiDelayCfg.PostDelay = 2;
spiDelayCfg.FrameDelay = 2;
spiDelayCfg.TransferDelay = 2;
Chip_SPI_DelayConfig(LPC_SPI1, &spiDelayCfg);
/* Enable Loopback mode for this example */
//Chip_SPI_EnableLoopBack(LPC_SPI0);
/* Enable SPI0 */
Chip_SPI_Enable(LPC_SPI1);
}

/* Master SPI transmit in polling mode */
static void WriteSpiMssg(uint16_t *xferPtr, uint32_t xferSize)
{
uint8_t i;
/* Setup Transfer structure, this data should be retained for the entire transmission */
XferSetup.pTx = xferArray; /* Transmit Buffer */
XferSetup.pRx = rx_buff;/* Receive Buffer */
XferSetup.DataSize = sizeof(xferArray[0]) * 8; /* Data size in bits */
XferSetup.Length = sizeof(xferArray) / sizeof(xferArray[0]); /* Total frame length */

/* Assert only SSEL0 */
///XferSetup.ssel = SPI_TXCTL_ASSERT_SSEL0 | SPI_TXCTL_DEASSERT_SSEL1;// | SPI_TXCTL_DEASSERT_SSEL2 | SPI_TXCTL_DEASSERT_SSEL3;
XferSetup.ssel = SPI_TXCTL_ASSERT_SSEL0 | SPI_TXCTL_DEASSERT_SSEL1;

XferSetup.TxCnt = 0;
XferSetup.RxCnt = 0;
/* Transfer message as SPI master via polling */
if (Chip_SPI_RWFrames_Blocking(LPC_SPI1, &XferSetup) > 0) {
/* If transmit successful then verify received data */


}
else {
/* Signal SPI error */
errorSPI();
}
}

/*****************************************************************************
* Public functions
****************************************************************************/

/**
* @brief Main routine for SPI example
* @return Function should not exit
*/
int main(void)
{
int i;
/* Generic Initialization */
SystemCoreClockUpdate();
Board_Init();

/* Clear activity LED */
Board_LED_Set(0, false);

/* Setup SPI pin muxing */
Init_SPI_PinMux();

/* Allocate SPI handle, setup rate, and initialize clocking */
setupSpiMaster();

/* Loop forever */
while (1) {
/* Write simple message over SPI */
WriteSpiMssg(xferArray, sizeof(xferArray) / sizeof(xferArray[0]));

for( i = 0;i <1000000;i++);
}

/* Code never reaches here. Only used to satisfy standard main() */
return 0;
}

Outcomes