Help with SPI on the Xpresso-LPC1549

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with SPI on the Xpresso-LPC1549

1,247 Views
howardeglowstei
Contributor I

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

Labels (2)
0 Kudos
1 Reply

619 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Howard Eglowstein,

   You can refer to the lpcopen code at first:

LPCOpen Software for LPC15XX|NXP 

static void Init_SPI_PinMux(void)
{
#if (defined(BOARD_NXP_LPCXPRESSO_1549))

    /* Enable the clock to the Switch Matrix */
    Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
    /*
     * Initialize SPI0 pins connect
     * SCK0: PINASSIGN3[15:8]: Select P0.0
     * MOSI0: PINASSIGN3[23:16]: Select P0.16
     * MISO0: PINASSIGN3[31:24] : Select P0.10
     * SSEL0: PINASSIGN4[7:0]: Select P0.9
     */
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 16, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 10, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));

    Chip_SWM_MovablePinAssign(SWM_SPI0_SCK_IO, 0);    /* P0.0 */
    Chip_SWM_MovablePinAssign(SWM_SPI0_MOSI_IO, 16);/* P0.16 */
    Chip_SWM_MovablePinAssign(SWM_SPI0_MISO_IO, 10);/* P0.10 */
    Chip_SWM_MovablePinAssign(SWM_SPI0_SSELSN_0_IO, 9);    /* P0.9 */

    /* Disable the clock to the Switch Matrix to save power */
    Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
#else
    /* Configure your own SPI pin muxing here if needed */
#warning "No SPI pin muxing defined"
#endif
}

You can configure the PinMuxSet at first, and you don't need to select IOCON_FUNC2.

Please modify the lpcopen code, spi_polling directly, then test it again.

If you still have problem, please check the according SPI pin wave, and let me know!


Have a great day,
Kerry

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

0 Kudos