完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用PIC24FJ128GA202并试图使用SPI写到微SD卡上。首先,我正在使用的芯片,在引脚RPI4上,也就是当前连接的,它说这只是PPS的输入,所以我使用它作为SDI。在PPS参考手册中,它说“外设不控制TrISX寄存器。TRIS位应该被保持用于输入。“这不意味着我应该做像TRISBbits这样的事情。TRISB4=1;对于我正在使用的相应引脚。除了设置RPNR和/或RPOR之外,我使用的所有PPS管脚都需要这样的东西吗?但是,它不会编译,并且在行上悬停,它表示找不到TRISB4的引用。我想知道这是否是导致我的microSD卡不挂载的问题,或者它是否已经设置为自动输入。我使用RPINR20bits.SDI1R=4;将它配置为PP的输出注意,我认为不可能将RPI4配置为PPS输出,因为没有RPORx具有与RPI4对应的字段,因此,有没有办法调试我是否正确地配置了PPS?
以上来自于百度翻译 以下为原文 I am using PIC24FJ128GA202 and trying to use SPI to write to a microSD card. First of all, the chip I'm using, on pin RPI4, which is what is currently connected, it says this is a input for the PPS only, and so I am using it for the SDI. On the PPS reference manual, it says "Peripheral does not control the TRISx register. The TRIS bits should be maintained for input." Doesn't that mean i should do something like TRISBbits.TRISB4 = 1; for the corresponding pin I'm using. Is something like this necessary for all the PPS pins I'm using in addition to setting RPINR, and/or RPOR? However, this does not compile, and hovering over the line, it says reference to TRISB4 can't be found. I was wondering if this could be the problem causing my microSD card not to mount, or if it is already set to input automatically. I am using RPINR20bits.SDI1R = 4; to configure it as output for PPS. note, I see that its not possible configure RPI4 as PPS output, as there is not a RPORx with field corresponding to RPI4, For that matter, is there a way to debug whether or not I am configuring the PPS correctly? |
|
相关推荐
14个回答
|
|
该引脚没有Tri/LAT/rPrPIT,因为它是只读的。但这是一个振荡器引脚,所以你需要确保SoSC被禁用。4是使用该引脚的RPIN寄存器使用的号码。除了效果之外,没有特殊的方法来调试PPS设置。您启用SPI模块并执行主发送。如果PPS是正确的,当PIN为高或0x00时,当PIN为低时,您将接收0xFF。
以上来自于百度翻译 以下为原文 There's no TRIS/LAT/RPOR bits for that pin because it is read-only. But this is an oscillator pin, so you need to make sure SOSC is disabled. 4 is the number to use with RPINR registers for that pin. There's no special way to debug PPS settings other than by effect. You enable your SPI module and do a master send. If PPS is correct, you will receive 0xff when the pin is high or 0x00 when the pin is low. |
|
|
|
在某些情况下,SPI时钟必须设置为PPS的输入和输出。
以上来自于百度翻译 以下为原文 In some cases, it was the SPI Clock that had to be set as both PPS in and out. |
|
|
|
谢谢您的回复,SOSCSEL是off对不起,我是编程PIC的初学者,并且我正在尝试使用MLA库来写入microSD卡,所以我真的不确定您所说的主发送是什么意思。通过代码,我发现它似乎正在使用SPI1_Exchange函数向SD卡发送数据。在FILEIO_SD_MediaInitialize函数中多次调用它。我打开SFR窗口,转到SPI1BUFL(030C),看到值有时会发生变化,尽管我对确切的需要被发送感到困惑,这主要是因为函数需要数据的指针,并且我还没有弄清楚如何查看数据。初始化有一个do-while循环等待看到它对数据发送的响应是0x01。注意,put.还调用SPI1_Exchange来发送dataFILEIO_SD_MediaInitialize后面有一个if语句,它没有进入(mediaInformation->errorCode!= MealAuthNOnError){Frime= FieloOyErrOrthInITyOrror;},这意味着PPS是正确设置的,对吗?我在DRIVEMUNT函数中的某个地方仍然有错误,但是它不是来自PPS设置,对吗?
以上来自于百度翻译 以下为原文 Thanks for the response, SOSCSEL is off Sorry, I am a beginner at programming PIC, and I am trying to use the MLA library to write to microSD card, so I'm not really sure what you mean by master send. Stepping through the code, I see that it seems to be sending data to SD card usingthe SPI1_Exchange function void SPI1_Exchange( void *pTransmitData, void *pReceiveData ) { uint8_t dummyRead = 0; uint8_t dummyWrite = spi1DummyData; if(pTransmitData == NULL) { pTransmitData = &dummyWrite; } if(pReceiveData == NULL) { pReceiveData = &dummyRead; } while( SPI1STATLbits.SPITBF == true ) { } // ---------------- // sending data // ---------------- SPI1BUFL = *((uint8_t*)pTransmitData); while ( SPI1STATLbits.SPIRBE == true) { } // ---------------- // extracting data // ---------------- *((uint8_t*)pReceiveData) = (uint8_t)(SPI1BUFL); } This is called many times in the FILEIO_SD_MediaInitialize function. I opened the SFR window and go to SPI1BUFL(030C) and I see that the value will sometimes change, though I am really confused on exactly want is being sent, mostly because the function takes pointers for the data, and I haven't figured out how to look at the data. I did notice that in FILEIO_SD_MediaInitialize there's a do-while loop waiting to see it the response to the data sent is 0x01. Note, put slow also calls SPI1_Exchange to send data do { //Toggle chip select, to make media abandon whatever it may have been doing //before. This ensures the CMD0 is sent freshly after CS is asserted low, //minimizing risk of SPI clock pulse master/slave synchronization problems, //due to possible application noise on the SCK line. (*config->csFunc)(1); FILEIO_SD_SPI_Put_Slow(config->index, 0xFF); //Send some "extraneous" clock pulses. If a previous //command was terminated before it completed normally, //the card might not have received the required clocking //following the transfer. (*config->csFunc)(0); timeout--; //Send CMD0 to software reset the device response = FILEIO_SD_SendMediaCmd_Slow(config, FILEIO_SD_GO_IDLE_STATE, 0x0); }while((response.r1._byte != 0x01) && (timeout != 0)); There is an if statement after FILEIO_SD_MediaInitialize, which it does not go into if (mediaInformation->errorCode != MEDIA_NO_ERROR) { error = FILEIO_ERROR_INIT_ERROR; } So this means that the PPS is being set up correctly right? I am still getting an error somewhere in the DriveMount function, but its not from the PPS setup, correct? |
|
|
|
看SPBIF不是一个好主意,因为阅读它会影响SPI操作。而是监视“*((UTI8*T*)PrimvEDATA””。如果你拉RB4高,这个值应该总是0xFF。如果你拉低RB4,值应该总是0x00。如果发生这种情况,PPS被正确设置。
以上来自于百度翻译 以下为原文 It is not a good idea to watch SPIBUF because reading it affects the SPI operations. Rather monitor "*((uint8_t*)pReceiveData)". If you pull RB4 high, this value should always be 0xff. If you pull RB4 low, the value should always be 0x00. If this is happening, PPS is set correctly. |
|
|
|
你能告诉我该如何拉高RB4吗?此外,快速问题是PrTestDATA在RB4上发送的高/低序列?我有点困惑,因为发送的数据的DRV_SPI_Put()是255,所以是0xFF,但是pTransmitData不是0xFF,pRecieveData不是0x00
以上来自于百度翻译 以下为原文 could you tell me how I should pull RB4 high? Also, quick question is pTransmitData a sequence of high/low sent on RB4? I am a bit confused because the DRV_SPI_Put() the data being sent is 255, so 0xFF, but pTransmitData is not 0xFF , and pRecieveData is not 0x00 |
|
|
|
将它从哪里断开,并将其连接到VDD,可能通过电阻器。
以上来自于百度翻译 以下为原文 Disconnect it from where it is and connect it to VDD, possibly through a resistor. |
|
|
|
我把它放在PCB上,这样做有点困难。我试着把VDD上的电线固定在RP4引脚上,然后以调试模式运行代码,pRecieveData不是0xFFFFFF。不过这个测试不是很准确。EDIT.,我感觉我正在正确地进行PPS设置,现在至少知道如何调试它了。如果我的pin设置出现问题,我会在这里发布beck,但是除此之外,我想我会在其他地方查找代码中的错误。谢谢你的帮助。
以上来自于百度翻译 以下为原文 I have it on a PCB so thats a bit harder to do. I tried holding a wire from VDD onto the RP4 pin, and ran the code in debug mode, the pRecieveData is not 0xFFFF. I dont this test was very accurate though. EDIT Well, I feel like I am doing the PPS setup correctly, and now have at least an idea of how to debug it. I will post beck here if there turns out to be a problem with my pin setup, but otherwise, I think I'll look for errors in my code elsewhere. Thanks for your help. |
|
|
|
如果是在PCB上,那么修改PPS任务可能是没有意义的。毕竟,它只是一个寄存器。很有可能是正确的,只要寄存器显示出正确的值。关于SD卡,我认为最好为此启动一个新线程。有些人对SD卡非常了解,但他们可能不读标题为“PPS问题”的帖子。
以上来自于百度翻译 以下为原文 If it is on PCB, then it probably doesn't make sense to alter it just to test the PPS assignment. After all, it's just a single register. Most likely it is correct, as soon as the register shows the correct value. Regarding the SD card - I think it would be a good idea to start a new thread for this. There are people who are very knowledgeable about SD cards, but they may not read the thread titled "Question on PPS". |
|
|
|
是啊。我在30分钟前制作了一张关于SD卡的新线索。谢谢你的帮助。
以上来自于百度翻译 以下为原文 yeah. I made a new thread about the sd card like 30 min ago. thanks for the help. |
|
|
|
只是一个更新,我得到它写,PPS被正确设置
以上来自于百度翻译 以下为原文 Just an update, I got it to write, the PPS was set correctly |
|
|
|
只有在不尴尬的情况下,你需要改变什么才能让SPI设备工作?
以上来自于百度翻译 以下为原文 Only if it's not to embarrassing, what did you need to change to get the write to an SPI device to work? |
|
|
|
长故事短文我清除了无效DRV_SPI_Initialize(DRV_SPI_INIT_DATA*pData)函数中的SPIROV位,并使用了增强缓冲模式(也称为增强主模式)DRV_SPI_STATLbits(1)。
以上来自于百度翻译 以下为原文 long story short I cleared the SPIROV bit in the void DRV_SPI_Initialize(DRV_SPI_INIT_DATA *pData) function and used enhanced buffer mode (aka enhanced master mode) DRV_SPI_STATLbits(1).SPIROV = 0; comment out #define DRV_SPI_CONFIG_ENHANCED_BUFFER_DISABLE where applicable |
|
|
|
正在设置的SPIROV位指示在接收下一个值之前没有读取缓冲区。当这个位被设置为“从”模式时,SPI外围设备将停止,但是在“主”模式中它应该被忽略。改变为增强模式只是在输入和输出端提供一个FIFO,它放松了您必须读取所接收值的时间。这两者都与您有关。没有足够快地读取接收到的值,这可能是根本问题,您只是使用增强缓冲模式来掩盖这一点。
以上来自于百度翻译 以下为原文 The SPIROV bit being set indicates that you are not reading the buffer before the next value is received. When this bit is set in 'slave' mode then the SPI peripheral will stop, but it shoudl be ignored in 'master' mode. Changing to enhanced mode just provides you with a FIFO on the input and output sides which relaxes the time in which you must read the received values a bit. Both of these relate to you not reading the received value quickly enough which may be the underlying problem and you are simply masking this my using the enhanced buffer mode. Susan |
|
|
|
是的,我确信在标准主模式下的代码中有一个我没有发现的bug,我正在用增强的主模式绕过它。如果我没有清除SPIROV位,它仍然挂起,并且家庭参考手册声明清除主模式的接收溢出位
以上来自于百度翻译 以下为原文 yes I'm pretty sure there is a bug(s) in the code in the standard master mode I haven't found, and I am bypassing it with enhanced master mode. Also it still hangs if I don't clear the SPIROV bit, and the family reference manual states to clear the receive overflow bit for master mode |
|
|
|
只有小组成员才能发言,加入小组>>
5171 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
533浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 03:49 , Processed in 1.590910 second(s), Total 106, Slave 87 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号