你好,我想s12通过SPI通信,但似乎有点问题,程序如下~
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=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=SPI0DR; // clear the spif flag.
}