智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 2070|回复: 1
打印 上一主题 下一主题

[编程类] 在读写nrf2401的函数中,只要往2401中写命令,则返回值就是状态寄存器Status中的内容

[复制链接]

1

主题

15

帖子

0

精华

高级会员

Rank: 4

积分
949
威望
519
贡献
244
兑换币
272
注册时间
2012-10-1
在线时间
93 小时
跳转到指定楼层
1#
发表于 2013-4-3 00:13:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5贡献
在读写nrf2401的函数中,只要往2401中写命令,则返回值就是状态寄存器Status中的内容,再接着写一串0,则返回值就是想要读取的寄存器中的内容,各位路过的大侠们,我的理解正确吗,资料上没讲这一点,看例程时对这里有点迷糊,望各位过路的大侠指点指点。小弟在此谢过。

uchar SPI_RW_Reg(BYTE reg, BYTE value)
{
uchar status;
   CSN = 0;                   // CSN low, init SPI transaction  // CS为低,开始SPI传输
   status = SPI_RW(reg);      // select register  // 传送命令与地址
   SPI_RW(value);             // ..and write value to it..  // 写1 BYTE 值
   CSN = 1;                   // CSN high again    // 完成SPI传输
   return(status);      // 返回 status        // return nRF24L01 status byte
}



/**************************************************
Function: SPI_Read();
Description:
  Read one byte from nRF24L01 register, 'reg'
/**************************************************/
BYTE SPI_Read(BYTE reg)
{
BYTE reg_val;
   CSN = 0;                // CSN low, initialize SPI communication...  // CS为低,开始SPI传输
   SPI_RW(reg);            // Select register to read from..  // 设置读地址
   reg_val = SPI_RW(0);    // ..then read registervalue   // 读数据
   CSN = 1;                // CSN high, terminate SPI communication   // 完成SPI传输
   return(reg_val);        // return register value // 返回数据
}



/**************************************************
Function: SPI_Read_Buf();
Description:
  Reads 'bytes' #of bytes from register 'reg'
  Typically used to read RX payload, Rx/Tx address
/**************************************************/
uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
{
uchar status,byte_ctr;
   CSN = 0;                       // CS为低,开始SPI传输// Set CSN low, init SPI tranaction
   status = SPI_RW(reg);          // 传输读接收数据的命令.    // Select register to write to and read status byte
   for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
    pBuf[byte_ctr] = SPI_RW(0);      // 读 1 BYTE数据   // Perform SPI_RW to read byte from nRF24L01
   CSN = 1;                         // 数据传送完成. // Set CSN high again
   return(status);                    // return nRF24L01 status byte
}

0

主题

2

帖子

0

精华

注册会员

Rank: 2

积分
177
威望
89
贡献
50
兑换币
56
注册时间
2013-11-5
在线时间
19 小时
毕业学校
福州大学
2#
发表于 2013-11-27 01:40:00 | 只看该作者
我也想知道,楼主知道了吗,告诉我们吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|亿加合和智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-5-19 12:33 , Processed in 0.046047 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表