AnsweredAssumed Answered

Help with SPI on the Xpresso-LPC1549

Question asked by Howard Eglowstein on Sep 21, 2017
Latest reply on Sep 24, 2017 by Kerry Zhou

I hope someone can help. I have an application on the LPC1549 that I'm prototyping on an LPCXpresso1549 board Rev C (OM13056). Part of the application requires sending data out an SPI port. According to the schematic of the eval board, PIO0_14 maps to SCK on the Arduino connector, PIO0_12 goes to MISO, PIO0_28 goes to MOSI and PIO0_27 goes to SSEL. I connected my device and a scope to those pins and see nothing. I've tried using both SPI0 and SPI1 and in neither case do I see anything. I'd appreciate it if someone could look at my testcase code and see what stupid thing I did wrong. Eternal thanks and beer money are in it for you if you can help.

 

Howard

 

#if defined (__USE_LPCOPEN)
#if defined(NO_BOARD_LIB)
#include "chip.h"
#else
#include "board.h"
#endif
#endif

 

#include <cr_section_macros.h>

 

// TODO: insert other include files here

 

// TODO: insert other definitions and declarations here

 

#define BUFFER_SIZE         10
#define SPI_MODE_TEST       (SPI_MODE_MASTER)
//#define SPI_MODE_TEST  (SPI_MODE_SLAVE)
#define POLLING_MODE        1

 

#define LPC_SPI           LPC_SPI0

 

   /* Tx buffer */
static uint16_t TxBuf[BUFFER_SIZE];

 

   /* Rx buffer */
static uint16_t RxBuf[BUFFER_SIZE];

 

static SPI_CFG_T ConfigStruct;
static SPI_DELAY_CONFIG_T DelayConfigStruct;

 

static SPI_DATA_SETUP_T XfSetup;
static volatile uint8_t  isXferCompleted = 0;

 


/* Initialize buffer */
static void bufferInit(void)
{
    uint16_t i;
    uint16_t ch = 0;

 

    for (i = 0; i < BUFFER_SIZE; i++) {
        TxBuf[i] = ch++;
        RxBuf[i] = 0xAA;
    }
}

 


int main(void) {

 

#if defined (__USE_LPCOPEN)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "On"
    Board_LED_Set(0, true);
#endif
#endif

 

    // TODO: insert code here

 

    Board_Init();

 

       /* SPI initialization */
    Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO  , 14);
    Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO  , 28);
    Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO  , 12);
    Chip_SWM_MovablePinAssign(SWM_SPI0_SSELSN_0_IO  , 27);

 

    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 14, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));    /* SPI0_SCK */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 28, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));    /* SPI0_MOSI */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 12, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));    /* SPI0_MISO */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 27, (IOCON_FUNC2 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));    /* SPI0_SSEL0 */

 

    ConfigStruct.Mode = SPI_MODE_MASTER;
    ConfigStruct.ClkDiv = Chip_SPI_CalClkRateDivider(LPC_SPI, 100000);
    ConfigStruct.ClockMode = SPI_CLOCK_CPHA0_CPOL0;
    ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST;
    ConfigStruct.SSELPol = SPI_CFG_SPOL0_LO;

 

    Chip_SPI_Init(LPC_SPI);
    Chip_SPI_SetConfig(LPC_SPI, &ConfigStruct);

 

    DelayConfigStruct.FrameDelay = 0;
    DelayConfigStruct.PostDelay = 0;
    DelayConfigStruct.PreDelay = 0;
    DelayConfigStruct.TransferDelay = 0;
    Chip_SPI_DelayConfig(LPC_SPI, &DelayConfigStruct);

 

    Chip_SPI_Enable(LPC_SPI);

 

    bufferInit();
    XfSetup.Length = BUFFER_SIZE;
    XfSetup.pTx = TxBuf;
    XfSetup.RxCnt = XfSetup.TxCnt = 0;
    XfSetup.DataSize = 8;

 

    XfSetup.pRx = NULL;

 

    Chip_SPI_WriteFrames_Blocking(LPC_SPI, &XfSetup);

 

    Board_LED_Set(1, true);

 

 

 

    // Enter an infinite loop, spewing SPI data
    while(1) {
        //bufferInit();
        XfSetup.Length = 2; // BUFFER_SIZE;
        XfSetup.pTx = TxBuf;
        XfSetup.RxCnt = XfSetup.TxCnt = 0;
        XfSetup.DataSize = 8;
        TxBuf[0] = 0;
        TxBuf[1] = 1;
        XfSetup.TxCnt = 0;

 

        Chip_SPI_WriteFrames_Blocking(LPC_SPI, &XfSetup);

 

    }
    return 0 ;
}

Outcomes