unsigned char SPI_SendorReceiveByte(unsigned char byte)
{
while(!(IFG2&UCB0TXIFG));
UCB0TXBUF = byte;
while(!(IFG2&UCB0RXIFG)); //如果你要判断接收标志,个人觉得,你应该在“写0之前”,先清掉该标志,
byte = UCB0RXBUF;
return byte;
}
发送和接收一起
unsigned char SPI_SendByte(unsigned char byte)
{
while(!(IFG2&UCB0TXIFG));
UCB0TXBUF = byte;
}
unsigned char SPI_Receive(void)
{
unsigned char byte;
while(!(IFG2&UCB0RXIFG)); //如果你要判断接收标志,个人觉得,你应该在“写0之前”,先清掉该标志,
byte = UCB0RXBUF;
return byte;
}
发送与接收分开
unsigned char ReadRawRC(unsigned char Address)
{
unsigned char ucAddr =0;
unsigned char ucResult=0;
NSS522_0;
ucAddr = ((Address<<1)&0x7E)|0x80; // (read) MSB =1 ADDRESS=6 LSB=0
SPI_SendorReceiveByte(ucAddr);
ucResult = SPI_SendorReceiveByte(0x00);
NSS522_1;
return ucResult;
}
unsigned char ReadRawRC(unsigned char Address)
{
unsigned char ucAddr =0;
unsigned char ucResult=0;
NSS522_0;
ucAddr = ((Address<<1)&0x7E)|0x80; // (read) MSB =1 ADDRESS=6 LSB=0
SPI_SendByte(ucAddr);
SPI_SendByte(0x00);
ucResult = SPI_ReceiveByte(0x00);
NSS522_1;
return ucResult;
}
两种不同的读寄存器方法。为什么第二种不可行。感觉代码都一样