AnsweredAssumed Answered

LPCOpen master SPI on 5410x

Question asked by Patroklos Anagnostou on Sep 9, 2017
Latest reply on Sep 20, 2017 by Kerry Zhou

Hello,

I am trying to setup a simple master SPI interface on LPC54102 using LPCOpen. Following the examples, I use:

Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_SPI0);
SPI_CFGSETUP_T spiSetup;
SPIM_DELAY_CONFIG_T masterDelay;
Chip_SPI_Init(LPC_SPIMASTERPORT);
Chip_SPI_Enable(LPC_SPIMASTERPORT);
spiSetup.master = 1;
spiSetup.lsbFirst = 0;
spiSetup.mode = SPI_CLOCK_MODE0;
Chip_SPI_ConfigureSPI(LPC_SPIMASTERPORT, &spiSetup);
Chip_SPI_SetCSPolLow(LPC_SPIMASTERPORT, 0);
Chip_SPIM_SetClockRate(LPC_SPIMASTERPORT, LPCMASTERCLOCKRATE);
masterDelay.PreDelay = 0x4;
masterDelay.PostDelay = 0x4;
masterDelay.FrameDelay = 0x4;
masterDelay.TransferDelay = 0x4;
Chip_SPIM_DelayConfig(LPC_SPIMASTERPORT, &masterDelay);
Chip_SPI_EnableInts(LPC_SPIMASTERPORT, (SPI_INTENSET_RXDYEN | SPI_INTENSET_SSDEN)); //???Needed?
NVIC_EnableIRQ(LPC_SPIMASTERIRQNUM);
spiMasterXfer.cbFunc = master_cb;
spiMasterXfer.state = SPIS_XFER_STATE_IDLE;
spiMasterXfer.txBuff = masterTXBuffer16;
spiMasterXfer.txCount = sizeof(masterTXBuffer16) / sizeof(uint16_t);/* Count is in transfer size */
spiMasterXfer.rxBuff = masterRXBuffer16;
spiMasterXfer.rxCount = sizeof(masterRXBuffer16) / sizeof(uint16_t);/* Count is in transfer size */
mstate = &spiMasterXfer.state;
spiMasterXfer.options = SPIM_XFER_OPTION_SIZE(16) | SPIM_XFER_OPTION_EOT | SPIM_XFER_OPTION_EOF;
spiMasterXfer.sselNum = 0;
masterTXBuffer16[0] = 0x1111;
Chip_GPIO_SetPinOutHigh(LPC_GPIO, 0, 19);
Chip_SPIM_XferBlocking(LPC_SPIMASTERPORT, &spiMasterXfer);
while (*mstate != SPIM_XFER_STATE_DONE) {
__NOP();
}
Chip_GPIO_SetPinOutLow(LPC_GPIO, 0, 19);
masterTXBuffer16[0] = 0x2222;
Chip_GPIO_SetPinOutHigh(LPC_GPIO, 0, 19);
Chip_SPIM_XferBlocking(LPC_SPIMASTERPORT, &spiMasterXfer);
while (*mstate != SPIM_XFER_STATE_DONE) {
__NOP();
}
Chip_GPIO_SetPinOutLow(LPC_GPIO, 0, 19);

To my surprise, I see the gpio toggling 4 times before even the first slave-select. The first word is sent (0x1111), then after a very long, unexplained delay also the second word comes (0x2222). There is no pulsing of the SlaveSelect signal in between, despite the
SPIM_XFER_OPTION_EOT | /* Enable this to assert and deassert SSEL for each individual byte/word */

Am I doing something inherently wrong?
Thank you for your support

Outcomes