We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi
I have been working on LPC2148 for a project. I have tried to get the spi0 working.
Currently the code compiles without a problem but is not responding as it is supposed to. I would like to know if there is any problem with the code in terms of SPI.
#include <lpc214x.h> //Includes LPC2148 register definitions
void spi_init(); void spi_send(char p); char spi_receive();
int main(void) { char p; int i=0; PINSEL0 = (1<<8)|(1<<10)|(1<<12)|(1<<14); // Enable UART1 Rx and Tx pins PINSEL1 = 0x00000000; PINSEL2 = 0x00000000; IO0DIR = (1<<14); IO0CLR |=(1<<14); IO1DIR = (1<<19) | (1<<18) | (1<<17) | (1<<16); spi_init();
while (1) { spi_send('0'); while(p!='0') { p=spi_receive(); }
spi_send('x'); while(p!='x') { p=spi_receive(); }
spi_send('f'); while(p!='f') { p=spi_receive(); }
spi_send('f'); while(p!='f') { p=spi_receive(); } i+=1; p='o'; switch(i%4) { case 1: IO1CLR=(1<<19)|(1<<18)|(1<<17)|(1<<16); IO1SET=(1<<19); break; case 2: IO1CLR=(1<<19)|(1<<18)|(1<<17)|(1<<16); IO1SET=(1<<18); break; case 3: IO1CLR=(1<<19)|(1<<18)|(1<<17)|(1<<16); IO1SET=(1<<17); break; case 0: IO1CLR=(1<<19)|(1<<18)|(1<<17)|(1<<16); IO1SET=(1<<16); break;
} } } void spi_init() { S0SPCR|=(1<<5); S0SPCCR=0x60;
} void spi_send(char p) { int value; value=(int)p; S0SPDR = value; while (!(S0SPSR & 0x80)); } char spi_receive() { char p; while (!(S0SPSR & 0x80)); p=(char)S0SPDR; return p; }
Thanks for the help!!