[求助] 关于SPI 的发送 接收函数的问题

chy2298691   2013-4-25 14:17 楼主
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;
}
两种不同的读寄存器方法。为什么第二种不可行。感觉代码都一样

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复