Can't get SPI1 to work on LPC1517

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Can't get SPI1 to work on LPC1517

950 次查看
sukkinpang
Contributor I

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;
}

标签 (1)
0 项奖励
回复
2 回复数

675 次查看
ianbenton
Senior Contributor I

Watch out for the bugs in the SPI module! If an interrupt happens whilst in use, the SSEL signals get into a mess. Much better to set and reset the SSEL signals by toggling the port bits instead of relying on the SPI module to do it.

0 项奖励
回复

675 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Sukkin Pang,

    I don't have LPC1517, so I test it on my LPC1549 with you code, based on the lpcopen peripheral_spi_polling project.

 I just test the SCK on P0_17 and SSEL on P0_27, the following picture is the waveform.

 pastedImage_1.png

You can find the SSEL still have the signal. It means your software is correct.

So, I think you still need to check your hardware, whether you test the correct pin.

Wish it helps you!

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复