volatile uint8_t data_out = 0xA5; volatile uint8_t data_in; int main(void) { volatile static int i = 0 ; LPC_SC->PCONP |= (1<<8); //switch SPI on LPC_SC->PCLKSEL0 |= (1<<16); //PCLK = CCLK LPC_PINCON->PINSEL0 &= ~(3<<30);//reset LPC_PINCON->PINSEL0 |= (3<<30);//set SCLK LPC_PINCON->PINSEL1 &= ~((3<<0)|(3<<2)|(3<<4)); //reset LPC_PINCON->PINSEL1 |= ((3<<0)|(3<<2)|(3<<4)); //set SSEL, MISO, MOSI LPC_SPI->SPCCR= 250; //>=8 100E6/250 = 400kHz LPC_SPI->SPCR = 0x38; //master 8bit while(1) { LPC_SPI->SPDR = data_out; while ((LPC_SPI->SPSR & 0x80)!=0x80); data_in = LPC_SPI->SPDR; for(i=0;i<100;i++){}//short delay } return 0; } |
LPC_SPI->SPCCR= 250; |
while ( (LPC_SPI->SPIF & 0x0080)!=0x0080 ); data_in = LPC_SPI0->S0SPDR; |