lundi 20 juin 2016

LPC812 SPI initialling based on the LPCOPEN

I'm trying to customize LPCOPEN SPI examples for LPC812 MCU's. Both periph_spi & periph_spi_sm_int examples run correctly on my LPC812 board and I'm able to trace signals on the MCU's pins by logic analyzer.But when I make my own project based on this examples ,I can't see any data on the MCU's pin , although that compiled successfully. below is my own project's codes:

#include "chip.h"

/*****************************************************************************
 * Private types/enumerations/variables
 ****************************************************************************/
#define SPI_MODE_TEST       (SPI_MODE_MASTER)
// #define SPI_MODE_TEST        (SPI_MODE_SLAVE)
#define POLLING_MODE        1

#define LPC_SPI           LPC_SPI0
#define SPI_IRQ           SPI0_IRQn
#define SPIIRQHANDLER     SPI0_IRQHandler


// static SPI_CONFIG_T ConfigStruct;
static SPI_DELAY_CONFIG_T DelayConfigStruct;

static SPI_DATA_SETUP_T XfSetup;

/*****************************************************************************
 * Public types/enumerations/variables
 ****************************************************************************/

/*****************************************************************************
 * Private functions
 ****************************************************************************/

/* Initializes pin muxing for SPI1 interface - note that SystemInit() may
   already setup your pin muxing at system startup */
static void Init_SPI_PinMux(void)
{
    /*
     * Initialize SSP0 pins connect
     * SCK1: PINASSIGN4[31:24]: Select P0.12
     * MOSI1: PINASSIGN5[7:0]: Select P0.14
     * MISO1: PINASSIGN5[15:8] : Select P0.6
     * SSEL1: PINASSIGN5[23:16]: Select P0.13
     */
    Chip_SWM_DisableFixedPin(SWM_FIXED_VDDCMP);
    Chip_SWM_MovablePinAssign(SWM_SPI1_SCK_IO, 12);
    Chip_SWM_MovablePinAssign(SWM_SPI1_MOSI_IO, 14);
    Chip_SWM_MovablePinAssign(SWM_SPI1_MISO_IO, 6);
    Chip_SWM_MovablePinAssign(SWM_SPI1_SSEL_IO, 13);

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

}

    void Board_SystemInit(void);


int main(void)
{
    SystemCoreClockUpdate();

    /* SPI initialization */
    Init_SPI_PinMux();

    /*
       ConfigStruct.Mode = SPI_MODE_TEST;
       ConfigStruct.ClkDiv = Chip_SPI_CalClkRateDivider(LPC_SPI, 100000);
       ConfigStruct.ClockMode = SPI_CLOCK_CPHA0_CPOL0;
       ConfigStruct.DataOrder = SPI_DATA_MSB_FIRST;
       ConfigStruct.SSELPol = SPI_SSEL_ACTIVE_LO;
     */
    Chip_SPI_Init(LPC_SPI);
    Chip_SPI_ConfigureSPI(LPC_SPI, SPI_MODE_TEST |  /* Enable master/Slave mode */
                          SPI_CLOCK_CPHA0_CPOL0 |   /* Set Clock polarity to 0 */
                          SPI_CFG_MSB_FIRST_EN |/* Enable MSB first option */
                          SPI_CFG_SPOL_LO); /* Chipselect is active low */

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

    Chip_SPI_Enable(LPC_SPI);

    XfSetup.Length = 1;
    XfSetup.pTx = (uint16_t*)0xFFFF;
    XfSetup.RxCnt = XfSetup.TxCnt = 0;
    XfSetup.DataSize = 8;

    XfSetup.pRx = NULL;


    Chip_SPI_WriteFrames_Blocking(LPC_SPI, &XfSetup);

    while (1)
    {
        Chip_SPI_WriteFrames_Blocking(LPC_SPI, &XfSetup);


    }
}

Aucun commentaire:

Enregistrer un commentaire