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 }
I guess you forgot to configure the port pins (PINSEL1 register). If you configure SPI interface but not port pins, you will see no activity on the pins. Franc
The PINSEL0 register (which is used to configure SPI0) is defined in the main program (not displayed above). But thanx anyway. During simulation the SPI seems to work; I send a byte to the data register. It takes a while to send, and then the SPIF bit is set (causing an interrupt) indicating that the transfer is completed. The ISR takes over the rest. Is there a way to see if the output pins toggle when simulating? Regards, Laurens
Is there noone that has a working SPI-interface??? Please give me some feedback, I'm trying ro use the SPI for more than a week. Still no success
Did you manage to solve the problem??