完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好!我已经开发了一个应用与MRF24J40MA收发器的图像传输和设备的设置不正常工作。我发现,当我在一个寄存器中写入时,我总是丢失我发送的最后一个“1”。我知道这是因为下面的任务是读取相同的寄存器(延迟后)。如果我写一个孤立的‘1’(而不是一个‘1’的字符串),我只得到零。例子:Po& & Gt;0000 1000 GET,0000;0000 -----------------------------& 0000;1110GET & 0000;1100i在写了0x2C之后有一个读取结果的例子。不是软件错误。我已经检查过,我没有在寄存器中保留一个位,在所有的操作中都是CS=‘0’。时钟线也以正确的方式工作。读/写的代码是:
以上来自于百度翻译 以下为原文 Hello everyone! I've been developing an application for transmission of images with the MRF24J40MA transceiver and the set up of the of the device is not working properly. I've detected that I always lose the last '1' that I send when I write in a register. I know this because the following task I do is read the same register (after a delay). If I write an isolated '1' (not a string of '1') , I only get zeros. Example: Put-> 0000 1000 Get ->0000 0000 -------------------------------------- Put-> 0000 1110 Get ->0000 1100 I have an example of a read result after having written a 0x2c. As you can seein the image attached the first one can`t be detected but is "present", so that makes me think that is not a software bug. I've already checked that I'm not writing on a reserved bit in the register, and CS = '0' during all the operation. The clock line is working in a proper way too. The code to read/write is: short int SPI1_Write(short int value,bool read) {//read indicates if It's a write/read access if(SPI1STATLbits.SPIROV != 0){//overflow bit short int TempVar; TempVar = SPI1BUFL; // Clears BF SPI1STATLbits.SPIROV =0; } short int dummy_value=0; while((SPI1STATLbits.SPITBF)){ LCD_SendString("TX full!");//wait while TX buffer is full. Verify bit 1*/ } SPI1BUFL=value; if(read==true){//if reading from spi slave SPI1STATLbits.SPIROV = 0; while(SPI1STATLbits.SPITBF); // wait for TX buffer to empty SPI1BUFL=0x00; // write to TX buffer (force CLK to run for RX transfer) while(SPI1STATLbits.SPIRBE){//WAIT while RX buffer not full LCD_SendString("RX empty!"); }//wait while receive buffer not full dummy_value=SPI1BUFL;//SPI1BUFL;RB10;RF7;PORTFbits.RF5; if(SPI1STATLbits.FRMERR==1) while(1) LCD_SendString("error!"); return dummy_value; } else { return 0; } } Attached Image(s) |
|
相关推荐
11个回答
|
|
你的CRO轨迹显示了什么?这些信号看起来都不像时钟。很可能你正在切换错误的时钟边沿,但是你没有显示你的SPI安装代码。
以上来自于百度翻译 以下为原文 What does your cro trace show? Neither of those signals looks like the clock. Most likely you are switching on the wrong clock edge, but you did not show your SPI setup code. |
|
|
|
每次发送完成后,您需要读取SPIPUF。
以上来自于百度翻译 以下为原文 You need to read SPIBUF after EVERY transmit is complete. |
|
|
|
这意味着,试图处理所有的SPI事务都是徒劳的。每一个SPI事务都是一个读和写,而且你需要同时执行这两个操作。每次做一个功能完全相同的事情。如果你只想读,只写0x00,如果你只读的话就丢弃它。想写。
以上来自于百度翻译 以下为原文 which means, it's wasted effort trying to handle reads and writes seperately. EVERY SPI transaction is both a read and a write, and you need to perform both. Make one function that does exactly the same thing every time. Just write 0x00 if you only want to read, and discard the value read if you only want to write. |
|
|
|
|
|
|
|
好的,谢谢大家,我会尝试这个,但我有怀疑,因为根据MRF24J40MA,当我做一个写操作,我不会得到任何答案从它(这就是我在示波器中看到的)。我认为这可能是一个硬件问题,因为当我读的时候,结果总是正确的,除了一个孤立的比特没有足够的断言(如你在图片中可以看到的)。抱歉FoGeTeT说:-红线是SDI(PIC)-黄色SDO(PIC)
以上来自于百度翻译 以下为原文 OK, thanks guys I'll try with this, but i have doubts because according to MRF24J40MA, when I do a write operation I'm not going to get any answer from it (and that's what I'm seeing in the oscilloscope). I thought It could be a hardware problem because when I read the result is always correct except one isolated bit that is not asserted enough (as you can see in the picture). Sorry for fogetting say that: - red line was SDI (of the PIC) - yellow SDO (of the PIC) |
|
|
|
不管设备是否驱动SDO,你必须做一个读来清除BF标志。你也应该显示时钟信号来正确地解释数据信号。
以上来自于百度翻译 以下为原文 It doesn't matter if the device drives SDO or not, you MUST do a read to clear the BF flag. You really should show the clock signal as well to properly interpret the data signals. |
|
|
|
我试过你的建议,但结果并不令人满意。我附加了一个写和读操作的图像,包括SDI、SDO、CLK和CS。我希望你能看到任何错误,这是好奇的,因为传输(从PIC)发生在负的边缘,虽然CKP=0,CKE=0,SDI在正边变化。不管怎样,我已经尝试了CKP和CKE的所有组合。这是我的SPI初始化代码:
以上来自于百度翻译 以下为原文 I tried your suggestions but the outcome was not satisfactory. I've attaches images of a write and read operation which include SDI, SDO ,CLK AND CS. I hope you can see any error. It's curious because transmission (from PIC) happens in the negative edge, though CKP=0 and CKE=0 and SDI changes in positive edge. Anyway, I've tried with all combinations of CKP and CKE. This is my SPI initializing code: void SPI1_Initialize (void) { // AUDEN disabled; FRMEN disabled; AUDMOD I2S; FRMSYPW One clock wide; AUDMONO stereo; FRMCNT 0; MSSEN disabled; FRMPOL disabled; IGNROV disabled; SPISGNEXT not sign-extended; FRMSYNC disabled; URDTEN disabled; IGNTUR disabled; SPI1CON1H = 0x0000; // WLENGTH 7; SPI1CON2L = 0x0007; // SPIROV disabled; FRMERR disabled; SPI1STATL = 0x0000; // SPI1BRGL 79; SPI1BRGL = 0x004f; // SPITBFEN disabled; SPITUREN disabled; FRMERREN disabled; SRMTEN disabled; SPIRBEN disabled; BUSYEN disabled; SPITBEN disabled; SPIROVEN disabled; SPIRBFEN disabled; SPI1IMSKL = 0x0000; // RXMSK 0; TXWIEN disabled; TXMSK 0; RXWIEN disabled; SPI1IMSKH = 0x0000; // SPI1URDTL 0; SPI1URDTL = 0x0000; // SPI1URDTH 0; SPI1URDTH = 0x0000; // SPIEN enabled; DISSDO disabled; MCLKEN FOSC/2; CKP Idle:Low, Active:High; SSEN disabled; MSTEN Master; MODE16 disabled; SMP Middle; DISSCK disabled; SPIFE Frame Sync pulse precedes; CKE Idle to Active; MODE32 disabled; SPISIDL disabled; ENHBUF enabled; DISSDI disabled; SPI1CON1L = 0x8021; } Attached Image(s) |
|
|
|
这是非常奇怪的,因为我用时钟的负边缘获得了小脉冲(附图)。每次我写一个孤立的“1”,我得到这些小脉冲…
以上来自于百度翻译 以下为原文 It's something so weird because I'm obtaining little pulses with the negative edge of the clock (image attached). That's the example of a read opertaion after writing the same register with 0b00001000. Every time I write an isolated '1', I get those little pulses... Attached Image(s) |
|
|
|
注意到你在16位模式下拥有SPI外设(因此每个值都有16个时钟),但是你只发送8位值。我有一种感觉,MRF27 J240MA使用一个8位的接口,所以在你发送的东西和你所需要的东西之间可能是一个错误的匹配。伊文。如果从属节点希望只发送8位,则当交换为MSB时,在低位字节发送命令时,主机将在高位字节中结束任何值。我只能猜测当它期望8时它收到16个时钟的奴隶在做什么。我不认为你已经告诉我们你正在使用的MCU,但是看看一些初始化SPI外围设备的代码,它可能是PIC32。不管是什么,试着确定你使用的是8位交换机。苏珊
以上来自于百度翻译 以下为原文 Just noticed that you have the SPI peripheral in 16-bit mode (and hence you are getting 16 clocks for each value) but you are only sending 8-bit values. I have a feeling that the MRF27J240MA uses an 8 bit interface so ther could well be a miss-match between what you are sending and what you are receiving. If the slave expects to only send 8 bits then, as the exchange is MSB first, the master will end up with any value in the high byte while sending the command in the low byte. I can only guess what the slave is doing if it receives 16 clocks when it expects 8. I don't think you have told us what the MCU is that you are using but looking at some of the code that initialises the SPI peripheral it could be a PIC32. Whatever it is, try making sure that you are using 8 bit exchanges. Susan |
|
|
|
你好,苏珊,我在8位模式下使用SPI外设,16个时钟周期的脉冲串有一个解释。前8个时钟具有读/写操作和寄存器地址的信息,并且下面的8位具有读取/写入的值。根据MRF24J40MA数据表,读/写操作具有这样的结构,并且我已经逐周期地控制到收发器的输入是绝对正确的。对于您的信息,我使用的是PIC24FJ1024GB610。另外,还有一个例子,在写有0x8值的RXFLASH寄存器之后,得到的小的无效脉冲。
以上来自于百度翻译 以下为原文 Hello Susan, I'm using SPI peripheral in 8 bit mode, the bursts of 16 clock cycles have an explanation. The first 8 clocks have the info of a read/write operation and the register address, and the following 8 bits have the value to be read/written. According to the MRF24J40MA datasheet a read/write operation has this structure and I've controlled cycle by cycle that inputs to the transceiver are absolutely correct. For your information I'm using the PIC24FJ1024GB610. Attached there's another example of the little unuseful pulse obtained after having written RXFLUSH register with 0x8 value. Attached Image(s) |
|
|
|
有人知道吗?我找不到解决这个问题的办法,太令人沮丧了……粉红:
以上来自于百度翻译 以下为原文 Does anyone have any idea? I can´t find the way to solve this, It's so frustrating...pink: |
|
|
|
只有小组成员才能发言,加入小组>>
5244 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3214 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2261 浏览 5 评论
781浏览 1评论
676浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
602浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
684浏览 0评论
581浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 09:12 , Processed in 1.616145 second(s), Total 97, Slave 81 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号