完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我正在尝试使用PIC24FJ64 GA2000和NFR24L01+无线电接收机模块来构建无线电发射机和接收机模块。我认为我在配置SPI和使用SPIX读写功能方面遇到了问题。EAD是我写的一个值,我接收的值不是我写的值。我只是收到一些随机或不合理的价值。如果可能的话,你能帮我解决我的问题吗?这里是一个代码,我在PIC24上配置SPI:空隙SPILIN(){SPI1CON1=0;//SPI1CON1寄存器设置SPI1CON1BIT.DISSCK=0;//内部串行时钟启用SPI1CON1BITS DISSDO=0;//SODOX引脚由模块SPI1CON1BIT控制。MODE16 16=0;/通信是字宽(8位)。s)SPI1CON1BITS=1;//主模式使能SPI1CON1BITS。SMP=0;/ /输入数据在数据输出时间SPI1CON1BIT.CKE=1结束时被采样;/ /串行输出数据在从/ /空闲时钟状态过渡到活动时钟状态SPI1CON1BIT.CKP=0;/ /用于CL的空闲状态变化Bog是一个低电平;//Active状态是一个高电平的SPI1CON1位。SpRe= 0B111;//二次时钟1:1 SPI1CONBITE。PPRE=0B01;//主时钟1:16 SPI1CON2=0;SPI1STATT=0;SPI1STATBITS.SISEL=0B101;//如果最后一位移位/ /表示SPI XFER时设置。是完整的。SPI1STATBITS。SPIN=1;//启用SPI模块PC2BITS.SPF1IP=6;/ /为SPI/ /中断控制器设置设置高优先级中断IFS0BITS SPI1IF=0;/ /清除中断标志IEC0BITSIP1IE=0;/ /禁用中断}这里也是我的SPI读写功能:UIT88T SPILRW(UIT8RY)T字节){UIT88T DATAYIN;SPI1BUF=字节;//通过SPI发送一个代码到(SPI1IF=0);πSPI1IF=0;/RESET标志变量DATAYIN=SPI1BUF;/ /接收到返回数据DATAIN;}这里是我的测试用例:SPIXRW(0x20);我写的是注册0x00 SPIXRW(0x2e);m为注册0x00 SPIXRW(0x00);我正在读取一个值,从0x00 RealStaseDistabySpRyrw(0xFF);发送一些垃圾值从寄存器0x00获取一个值供参考:数据表:HTTPS://www. SPARKFUN.COM/DATHESETS/CONTRONS/SMD/NFR24L01PLASSSILPRONTIAL OFFICTATION V1.0你可以从PIC24找到命令行、寄存器和状态。PIC24: HTTP:/WW1.MICCHIP.COM/DeLoSs/En/DeVICECD/981E.PDFIF搜索SPI的数据表,你可以找到SPI部分。也许我缺少一些小东西,但是请帮助我。谢谢。
以上来自于百度翻译 以下为原文 Hello, I am trying to build a radio transmitter and receiver module using PIC24FJ64GA002 and nRF24L01+ radio transreceiver module. I think I am having a problem with configuring my SPI and using spi_read_write function. Because, when I just write a certain value to a register of nRF24L01+ and try to read a value that I wrote, the value that I am receiving is not a value that I wrote. Im just receiving some random or unreasonable value. If it is possible, could you help me to figure out my problem? Here is a code that I am configuring my SPI on PIC24: void spi_init(){ SPI1CON1=0; // SPI1CON1 Register Settings SPI1CON1bits.DISSCK = 0; // Internal serial clock is enabled SPI1CON1bits.DISSDO = 0; // SDOx pin is controlled by the module SPI1CON1bits.MODE16 = 0; // Communication is word-wide (8 bits) SPI1CON1bits.MSTEN = 1; // Master mode enabled SPI1CON1bits.SMP = 0; // Input data is sampled at the end of data output time SPI1CON1bits.CKE = 1; // Serial output data changes on transition from // Idle clock state to active clock state SPI1CON1bits.CKP = 0; // Idle state for clock is a low level; // active state is a high level SPI1CON1bits.SPRE=0b111; //secondary clock 1:1 SPI1CON1bits.PPRE=0b01; // primary clock 1:16 SPI1CON2=0; SPI1STAT=0; SPI1STATbits.SISEL = 0b101; // IF set when last bit is shifted out // That means the SPI xfer is complete. SPI1STATbits.SPIEN = 1; // Enable SPI module IPC2bits.SPF1IP = 6; // setting a high priority interrupt for spi // Interrupt Controller Settings IFS0bits.SPI1IF = 0; // Clear the Interrupt flag IEC0bits.SPI1IE = 0; // Disable the interrupt } Also here is my Spi read write function: uint8_t SPI_RW(uint8_t byte) { uint8_t data_in; SPI1BUF=byte; // sending a code to transmitter through SPI while (_SPI1IF == 0) ; _SPI1IF=0; // reset flag variable data_in=SPI1BUF; // data that is received return data_in; } Here is my test cases: SPI_RW(0x20); I am writing to register 0x00 SPI_RW(0x2e); the value that I am writing to register 0x00 SPI_RW(0x00); I am reading a value from 0x00 register data = SPI_RW(0xff); sending some junk value to get a value from register 0x00 For your reference: data sheet for radio: https://www.sparkfun.com/datashe ... cification_v1_0.pdf You can find command lines, registers, and states from here. data sheet for PIC24: http://ww1.microchip.com/downloads/en/DeviceDoc/39881e.pdf if search SPI, you can find spi section. Maybe I am missing some small things, but please help me. Thank you. |
|
相关推荐
5个回答
|
|
相同(可能是由于迟交批准)http://www. McCux.com…/M105732. ASPXα1055732
以上来自于百度翻译 以下为原文 same (possibly due to late approval) https://www.microchip.com.../m1055732.aspx#1055732 |
|
|
|
你好,达里奥,谢谢你的回复。你能详细介绍一下你的评论吗?我不太清楚你说的是什么。谢谢。
以上来自于百度翻译 以下为原文 Hello Dario, Thank you for the reply. Could you elaborate more on your comment? I am not really sure what you are trying to say. Thanks. |
|
|
|
他说你有两个相同的帖子。(关于为什么这可能发生的评论)把所有回复都放在一个主题里要简单得多,所以请坚持另一个。
以上来自于百度翻译 以下为原文 He is saying you have two identical posts. (With a comment about why this probably happened) It's much simpler to keep all the replies in just one topic, so please stick to the other one. |
|
|
|
对不起,我把我的回复写错了。我可以删除这个帖子吗?
以上来自于百度翻译 以下为原文 Ohh sorry I wrote my reply to wrong one. Can I delete this post? |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
774浏览 1评论
664浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
592浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
674浏览 0评论
574浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 18:38 , Processed in 1.486788 second(s), Total 88, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号