你好,我想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. }
在Main中是: while(1){ putchar_spi0(0x0f);
temp=getchar_spi0(); } 在线调试的时候是可以执行的,但用示波器在SCK口没有信号输出,MOSI口也没有信号输出,而且SPI0DR一直都是0,不知道是为什么呢? 假如我在输出0x0f,是不是应该可以在M0SI口看到一定的波形呢?
[此贴子已经被作者于2007-4-24 16:26:31编辑过] |