void SPIInit(void){ SPI0BR =0b00000001;//clock divisor is 2 SPI0CR2=0b00000010; // SS is not used SPI0CR1=0b01010000; //as master } char getchar_spi0(void) { unsigned char te; while(!(SPI0SR_SPTEF)); /* wait until write is permissible */ SPI0DR = 0x00; /* trigger 8 SCK pulses to shift in data */ while(!(SPI0SR_SPIF)); /* wait until a byte has been shifted in */ te=SPI0SR; te=SPI0DR; // clear the spif flag. return te; /* return the character */ } void putchar_spi0 (char cx) { char temp; while(!(SPI0SR_SPTEF)); /* wait until write is permissible */ SPI0DR = cx; /* output the byte to the SPI */ while(!(SPI0SR_SPIF)); /* wait until write operation is complete */ temp=SPI0SR; temp=SPI0DR; // clear the spif flag. } void main(void) { char temp;
/* put your own code here */ EnableInterrupts; SPIInit(); while(1) { putchar_spi0(0x0f); temp=getchar_spi0(); } for(;;) {} /* wait forever */ /* please make sure that you never leave this function */ }
|