无线通信NRF24L01-发送 作者: 时间:2016-11-29 来源:网络 加入技术交流群 扫码加入和技术大咖面对面交流海量资料库查询 收藏 /****************************************************************************************************//*功能:NRF24L01读写寄存器函数 一次写一个数据/****************************************************************************************************/uint SPI_RW_Reg(uchar reg, uchar value){uint status;CSN = 0; // CSN low, init SPI transaction 启动spi总线status = SPI_RW(reg); // select register 发送寄存器地址 用于选择寄存器 以及选择读或写SPI_RW(value); // ..and write value to it.. 向寄存器写入数据CSN = 1; // CSN high againreturn(status); // return nRF24L01 status uchar}/****************************************************************************************************//*函数:uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars)/*功能: 用于读数据,reg:为寄存器地址,pBuf:为待读出数据地址,uchars:读出数据的个数/****************************************************************************************************/uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars){uint status,uchar_ctr;CSN = 0; // Set CSN low, init SPI tranactionstatus = SPI_RW(reg); // Select register to write to and read status ucharfor(uchar_ctr=0;uchar_ctr(TxBuf+4))t=TxBuf;SetRX_Mode(); //设置为接收状态while(!nRF24L01_RxPacket(&RxBuf)); //等待接收数据P2=RxBuf;Delay(20000);}} 上一页 1 2 下一页
评论