This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI problem with LPC2129 (using MCB2100)

I have pull up resistors on the /SSEL pins of the SPI bus. I want to use the LPC2129 as master, let him send 10 bytes .. 1 time Ox55 and 9 times 0x00 but it seems not to work. Is there something wrong with the code?

With a scope I see the P0.0 work well as chip selector but I don't see a clk running also no data on the mosi/miso lines.

Here is my code:

#include <LPC21xx.H>
#include "Timer.h"                                    functions
unsigned int dummy;
unsigned int status = 0x0;
unsigned int s          = 0x0;
unsigned int i          = 0x0;
unsigned int cnt        = 0x0;
unsigned int buf[10];



void SPI0_Init(void)
{
        S0SPCCR         = 0xFA;
        S0SPCR          = 0x28;
        IOSET1          = 0x00020000;
}

int SPI0_WriteAA(void)
{
        S0SPDR = 0x55;

        while(!(S0SPSR & 0x80)){}

        if (S0SPSR != 0x80)
        {
                IOCLR1          = 0x00400000;
                IOSET1          = 0x00800000;
                status          = 0x1;
        }
        else
        {
                IOCLR1          = 0x00800000;
                IOSET1          = 0x00400000;
                status          = 0x0;
        }

        s = S0SPSR;

        return(status);
}

int SPI0_WriteFF(void)
{
        S0SPDR  = 0x00;

        while(!(S0SPSR & 0x80)){};

        if (S0SPSR != 0x80)
        {
                IOCLR1          = 0x00400000;
                IOSET1          = 0x00800000;
                status          = 0x1;
        }
        else
        {
                IOCLR1          = 0x00800000;
                IOSET1          = 0x00400000;
                status          = 0x0;
        }

        s = S0SPSR;

        return(status);
}

int SPI0_Read(void)
{
        dummy = S0SPDR;                                                                 //read data register
        buf[cnt] = dummy;
        if (cnt < 10) {
        cnt++;
        }
        return(dummy);
}

void wait (void)
{
  unsigned long i;

  i = timeval;
  while ((i + 100) != timeval);
}

void waitstartup (void)
{
  unsigned long i;

  i = timeval;
  while ((i + 15) != timeval);
}

int main (void)
{
        int c;

        PINSEL0         = 0x00005500;
        IODIR0          = 0x00010001;
        IOCLR0          = 0xFFFFFFFF;
        IOSET0          = 0x00010001;
        PINSEL1         = 0x154542A8;
        IODIR1          = 0x00FF0000;
        IOCLR1          = 0x00FF0000;
        IOSET1          = 0x00010000;

        SPI0_Init();
        init_timer();
        waitstartup();

        IOCLR0  = 0x00000001;
        IOSET1  = 0x00040000;

        while (1)
        {
                if (i==0)
                {
                        SPI0_WriteAA();

                        if (status == 0x0)
                        {
                                SPI0_Read();
                        }

                        for (c=0;c<9;c++)
                        {
                                SPI0_WriteFF();

                                if (status == 0x0)
                                {
                                        SPI0_Read();
                                }
                        }
                   i=1;

                IOSET0          = 0x00000001;
                wait();
                IOCLR1          = 0x00040000;
                }
        }
}

0