Microchip
直播中

韩志保

7年用户 184经验值
私信 关注
[问答]

如何在PIC24FJ128GA202中正确配置PPS

我使用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)

李天竹

2019-7-18 08:02:35
该引脚没有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.
举报

张娜

2019-7-18 08:14:44
在某些情况下,SPI时钟必须设置为PPS的输入和输出。

以上来自于百度翻译


      以下为原文

    In some cases, it was the SPI Clock that had to be set as both PPS in and out.
举报

朱虹

2019-7-18 08:28:20
谢谢您的回复,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?
举报

李天竹

2019-7-18 08:40:47
看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.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分