Board logo

标题: 请教关于SPi的问题~~~ [打印本页]

作者: xiaohe1985    时间: 2007-4-8 08:41     标题: 请教关于SPi的问题~~~

你好,我想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.
}


mian里面在测试的时候分别是是这样的:

while(1){
putchar_spi0(0x0f);
}
while(1){
temp=getchar_spi0();
}
但在执行的时候,在putchar函数中一直在while(!(SPI0SR_SPIF)); 等待,而在getchar_spi0();中收过来的值一直是0xff;我的/SS是一直提供了高电平,请问到底是哪里出了问题呢?谢谢~~~

作者: strongchen    时间: 2007-4-9 09:41

用示波器看一下主机SPI的MOSI口和时钟口是否有信号输出?




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0