lpcware

SSP/SPI on LPC1227 MISO not working

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by nfogh on Mon Jul 25 02:15:53 MST 2011
Hi

I'm trying to get SPI working on a LPCXpresso 1227 board. I have gotten as far as setting up the port and sending data out. On my logic analyser, it is working nicely. However, I cannot get any data in on the MISO port. I have tied MISO and MOSI together with a jumper to get a loopback functionality, and on the logic analyser, it looks fine. However, the SSP DR register always reads 0. If I enable the software loopback mode, I get the data alright, so the code seems to be ok.


int main(void) {
   
    // TODO: insert code here

    LPC_SYSCON->SYSPLLCLKSEL = 0x1;
    __DMB();
    LPC_SYSCON->SYSPLLCLKUEN = 0x0;
    __DMB();
    LPC_SYSCON->SYSPLLCLKUEN = 0x1;

    LPC_SYSCON->MAINCLKSEL = 0x1;
    __DMB();
    LPC_SYSCON->MAINCLKUEN = 0x0;
    __DMB();
    LPC_SYSCON->MAINCLKUEN = 0x1;

    LPC_SYSCON->SYSPLLCTRL = 0x2;

    LPC_IOCON->PIO0_1 = pin0_1_uart;
    LPC_IOCON->PIO0_2 = pin0_2_uart;
    LPC_IOCON->PIO0_8 = pin0_8_uart;
    LPC_IOCON->PIO0_9 = pin0_9_uart;

    LPC_GPIO0->DIR = (1<<20);

    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12) | (1<<13);
    LPC_SYSCON->UART0CLKDIV = 6;
    LPC_SYSCON->UART1CLKDIV = 6;

    LPC_UART0->LCR = 0x3;
    LPC_UART1->LCR = 0x3;

// set up SPI
    LPC_IOCON->PIO0_14 &= ~(0x3);
    LPC_IOCON->PIO0_14 |= mode_spi;

    LPC_IOCON->PIO0_15 &= ~(0x3);
    LPC_IOCON->PIO0_15 = mode_spi;

    LPC_IOCON->PIO0_16 &= ~(0x3);
    LPC_IOCON->PIO0_16 = mode_spi;

    LPC_IOCON->PIO0_17 &= ~(0x3);
    LPC_IOCON->PIO0_17 = mode_spi;

    LPC_SYSCON->SSPCLKDIV = 0x10;

    LPC_SSP->CR0 = (0x0F << DSS) | (1<<CPOL) | (1<<CPHA);
    LPC_SSP->CPSR = 0x8;
    LPC_SSP->CR1 = (0x1 << SSE);

    LPC_SSP->IMSC = (1<<RORIM) | (1<<RTIM);

    NVIC_EnableIRQ(SSP_IRQn);

    int k;
    int dummy;
    for (k = 0; k < 8; k++)
        dummy = LPC_SSP->DR;

    // Enter an infinite loop, just incrementing a counter
    volatile static int i = 0 ;
    while(1) {
        char buf[255];
        uint32_t val;
        LPC_GPIO0->CLR = (1<<20);
        int j;
        for (j = 0; j < 100000; j++)
            __NOP();
        if (LPC_SSP->SR & SR_TNF) {
            outch('.');
            LPC_SSP->DR = (0x0A << ADDR);
        }

        while ( (LPC_SSP->SR & (SR_BSY|SR_RNE)) != SR_RNE );

        while (LPC_SSP->SR & SR_RNE) {
            val = LPC_SSP->DR;
            snprintf(buf, 255, "X %08x %d\n", val, i);
            outstr(buf);
        }

        i++ ;
        LPC_GPIO0->SET = 1<<20;
        for (j = 0; j < 100000; j++)
            __NOP();
    }
    return 0 ;
}
I have made a board of my own with that type of MCU, and that is experiencing the same problem. Therefore it doesn't seem like a hardware problem.

I have also tried to set up the port as a GPIO input port, and it works fine there. I would assume that rules out hardware problems as well.

Have anybody got an idea about what this could be?

Cheers,

Outcomes