2 /*函数:uchar SPI_Read(uchar reg)

3 /*功能:NRF24L01的SPI读操作

4 /****************************************************************************************************/

5 unsigned char SPI_Read(unsigned char reg)

6 {

7 unsigned char reg_val;

8 CSN=0; // CSN low, initialize SPI communication.。.

9 SPI_RW(reg); // Select register to read from.。

10 reg_val=SPI_RW(0); // 。.then read registervalue

11 CSN=1; // CSN high, terminate SPI communication

12 return(reg_val); // return register value

13 }

14 /****************************************************************************************************/

15 /*功能:NRF24L01读写寄存器函数

16 /****************************************************************************************************/

17 unsigned char SPI_RW_Reg(unsigned char reg, unsigned char value)

18 {

19 unsigned char status;

20 CSN = 0; // CSN low, init SPI transaction

21 status=SPI_RW(reg); // select register

22 SPI_RW(value); // 。.and write value to it.。

23 CSN = 1; // CSN high again

24 return(status); // return nRF24L01 status uchar

25 }

26 /****************************************************************************************************/

27 /*函数:uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars)

28 /*功能: 用于读数据,reg:为寄存器地址,pBuf:为待读出数据地址,uchars:读出数据的个数

29 /****************************************************************************************************/

30 unsigned char SPI_Read_Buf(unsigned char reg, unsigned char *pBuf, unsigned char uchars)

31 {

32 unsigned char status,uchar_ctr;

33 CSN = 0; // Set CSN low, init SPI tranaction

34 status=SPI_RW(reg); // Select register to write to and read status uchar

35

36 for(uchar_ctr=0;uchar_ctr

37 {

38 pBuf[uchar_ctr]=SPI_RW(0);

39 }

40 CSN = 1;

41

42 re

责任编辑;zl

关于控制,MCU就介绍完了,您有什么想法可以联系小编。