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

No SPI activity on MCB2100

Hello,

I'm trying to use the SPI-interface on the MCB2100 board (with the LPC2129) but it just doesn't work.

I can initialize the SPI0 and simulate the sending of data. But when I download it to the microcontroller the SPI-pins just don't work. I cannot see a clock or data on the pins. Below follows the code I use to set-up the SPI and the interrupt routine for SPI-interrupts:

void init_SPI0(void)
{
 S0SPCCR        =    30;                   //SCLK = 15Mhz/30 = 500kHz
 S0SPCR         =    0xA8;                 //CPHA=1,CPOL=0,MSTR=1,LSBF=0,SPIE=1
 VICVectCntl0   =    0x2A;                 //Enable vector for SPI0 interrupt
 VICVectAddr0   =    (unsigned)SPI0_ISR;     //Set ISR
 VICIntEnable    =    0x0400;               //Enable interrupt
}

void SPI0_ISR(void)     __irq
{
 switch(status)
 {
  case(0x01):                                //Busy with WREG
    S0SPINT     =    0x01;                 //Clear interrupt flag
     S0SPDR     =    *SPI_buffer++;        //Send next byte
     if(--SPI_bytecount)                    //Another byte???
     {
      status =  0x01;                      //Yes
     }
     else
     {
      status    =    0x02;                 //No
     }
     break;

  case(0x02):                               //Last byte sent
     S0SPINT    =    0x01;                 //Clear interrupt flag
     IOSET0     =    0x01;                 //Pull chipselect high
     lock  =    0;                         //Clear flag
     status     =    0x00;                 //End of interface
     break;

  case(0x03):                               //Busy with RDATA
     S0SPINT         =    0x01;            //Clear interrupt flag
     *SPI_buffer     =    S0SPDR;          //Read data
     SPI_buffer++;                         //Increment pointer
     if(--SPI_bytecount)                    //Another byte???
     {
      status    =    0x03;                 //Yes
     }
     else
     {
      status    =    0x00;                 //No
      lock =    0;                         //Clear flag
     }
  break;

  default:                                  //Default case
  break;
 }

VICVectAddr     =    0x00;            //Reset interrupt hardware
}

void ADC_WREG(unsigned char *buffer, unsigned char bytecount)
{
 lock           =    1;                    //Set flag
 SPI_buffer     =    buffer;
 SPI_bytecount  =    bytecount;
 IOCLR0         =    0x02;                //Pull Chipselect low
 S0SPDR         =    0x50;                //Send WREG, starting at adress 0
 status         =    0x01;                 //Set state
}

void ADC_RDATA(unsigned char *buffer)
{
 lock           =    1;                    //Set flag
 SPI_buffer     =    buffer;
 SPI_bytecount  =    3;                    //3 bytes expected
 IOCLR0         =    0x02;                //Pull chipselect low
 S0SPDR         =    RDATA;                //Send RDATA
 status         =    0x03;                 //Set state
}

What I typically want to do is to call the ADC_WREG function once and then to continuously read the ADC by calling the ADC_RDATA function.

But the SPI-output pins do nothing… During simulation the byte is sent (I guess) because an interrupt occurred.and the SPIF bit (indication the completion of a data transfer) is set…

I do not not what to do or where I / the program go(es) wrong, Can anyone help?

Kind Regards,

Laurens Swaans

Parents Reply Children
  • Hi,

    Try this. In a nut shell it came down to how you load the register. Ie using '=' did not work for some reason.

    #include <LPC21xx.H> // LPC21xx definitions


    int main (void)
    {
    unsigned short i;

    PINSEL0 |= 0x00005500; // configure SPI0 pins

    S0SPCCR = 16; // = Pclk/16 = 3,8MHz, counter > 8 and even
    S0SPCR = 0x20; // Initialize SPI hardware

    while(1)
    {
    S0SPDR = 0x55;
    while(!(S0SPSR & 0x80)) // wait until tx or rx is complete
    {
    }

    i = S0SPSR; // read S0SPSR to clear
    }
    }

    Note that the original ARM7 from Philips use a different SPI block. (diff are LPC213x/LPC214x/LPC2101-2-3)
    P0.7 (pin 31) is pulled high in order to prevent the micro from entering SPI slave mode (the pin has no internal pull-up). The device I was working with was the LPC2210.