Microchip
直播中

简白伊

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

如何准确地读取PixVeDATA以确保我有VS地址?

论坛,函数SPI1_Exchange(取自SD卡当前MLA示例)(见下文)使用指针。以下是我尝试从SPI1_exchange发送和接收数据。includeinclude//我不知道unit8_t之前的*做什么。在这一点上,我想传输值0xFF,RX不在乎或者NULL*pTransmitData=0xFF;pReceiveData=NULL;EnableMSD_SS_Port;SPI1_Exchange(&pTransmitData,&pReceiveData);SPI1_Exchange(&pTransmitData,&pReceiveData);SPI1_Exchange(&pReceiveData);pTransmitData,&pReceiveData;SPI1_Exchange(&p发送数据,&pReceive数据;SPI1_Exchange(&p发送数据,&pReceive数据;SPI1_交换;SPI1_交换(&p发送数据,&p发送数据,&p接收数据;p接收数据;SPI1_交换;SPI1_交换(&p发送数据,&p发送数据,&p接收数据;SPI1_交换;SPI1_交换(&;p发送数据;eData;SPI1_Exchange(&pTransmitData,&pReceiveData);SPI1_Exchange(&pTransmitData,&pReceiveData);//在这一点上,TX并不介意,尽管我需要将其发送为NULL,但不确定我是否需要清除RX*pTransmitData=NULL;pReceiveData=0x00;.bleMSD_SS_Port;SPI1_Exchange(&pTran)SmithDATA和PrPvEDATA),我如何准确地读取PixVeDATA以确保我有VS地址?编译器:XC16 v1.25谢谢,Craigvoid SPI1_Exchange(void*pTransmitData,void*pReceiveData){uint8_t dummyRead=0;uint8_t dummyWrite=0xFF;//spi1DummyData;if(pTransmitData==NULL){pTransmitData=&dummyWrite;}if(pRecei{pReceiveData==NULL) {pReceiveData=&dummyRead;}}_当(SPI1STATLbits.SPITBF==1){{SPI1STAT位SPI1STATTTLbits.SPITBF==1){{{{}/----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*((uint8_t*)pRecEIVEDATA)=(UIT88T)(SPI1BUFL);}

以上来自于百度翻译


      以下为原文

    Forum,

Function SPI1_Exchange (taken from SD card current MLA example) (see below) employs pointers.

The following is my attempt at sending and receiving data from SPI1_exchange.

#include
#include

// I have no idea what the * before unit8_t does.
    uint8_t* pTransmitData, pReceiveData;

// At this point I want to transmit value 0xFF, RX is don't care or NULL
    *pTransmitData    = 0xFF;
    pReceiveData       = NULL;


    EnableMSD_SS_Port;
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);
    SPI1_Exchange(&pTransmitData, &pReceiveData);


// At this point TX is don't care though I need to send it NULL, not sure if I need to clear RX
    *pTransmitData    = NULL;
    pReceiveData    = 0x00;

    DisableMSD_SS_Port;
    SPI1_Exchange(&pTransmitData, &pReceiveData);

How exactly (syntax) to I read pReceiveData to make sure I have value vs address?

A short primer on how to work with this example would be great.

Compiler: XC16 v1.25

Thank you,
Craig




void SPI1_Exchange( void *pTransmitData, void *pReceiveData )
{
    uint8_t dummyRead = 0;
    uint8_t dummyWrite = 0xFF;//spi1DummyData;

    if(pTransmitData == NULL)
    {
        pTransmitData = &dummyWrite;
    }

    if(pReceiveData == NULL)
    {
        pReceiveData = &dummyRead;
    }

    while( SPI1STATLbits.SPITBF == 1 )
    { }

    // ----------------
    // sending data
    // ----------------
    SPI1BUFL = *((uint8_t*)pTransmitData);

    while ( SPI1STATLbits.SPIRBE == 1)
    { }

    // ----------------
    // extracting data
    // ----------------
    *((uint8_t*)pReceiveData) = (uint8_t)(SPI1BUFL);
}























回帖(9)

王焕树

2019-6-26 06:46:30
它声明变量是指针。您不能在那里这样做,因为指针还没有指向任何类型的缓冲区。字符不应该在那里,因为您已经传递了指针。现在可能是回到基本的C教科书并学习ab的好时机。输出缓冲区和指针。

以上来自于百度翻译


      以下为原文

   
It's after, not before.
It declares the variables are pointers.
 

You can't do that there, because the pointer does not yet point to any sort of buffer.


The "&" characters shouldn't be there, as you are already passing a pointer.
 
It's probably a good time to go back to a basic C textbook and learn about buffers and pointers.
 
 
举报

石利军

2019-6-26 06:59:00
进行建议的更改的唯一问题是SPI端口不再输出数据。我需要将值(0xFF、0x04等)获取到SPI1_Exchange。我设置它的第一种方法实际上是在SPI端口上传输数据。新的方法不是:uint8_t uTransmitData、uReceiveData、uTransmitData;uTransmitData0xFF;uReceiveData=NULL;EnableMSD_SS_端口;SPI1_Exchange(&u发送数据,&u接收数据;SPI1_Exchange(&u发送数据,&u发送数据,&uRecei接收数据;uReceieiveReceiveData;UReceiveData;SPI1_交换(&u发送数据,&u发送数据,&;u接收数据&;u接收数据;u接收数据;SPI1_交换(&;SPI1_交换&交换;交换;交换;交换&;u发送发送发送发送数据,&;u发送数据,&;u发送数据数据,SPI1_Exchange(&uTransmitData, &uReceiveData);SPI1_Exchange(&uTransmitData, &uReceiveData);SPI1_Exchange(&uTransmitData, &uReceiveData);SPI1_Exchange(&uTransmitData, &uReceiveData);禁用MSD_SS_Port;uTransmitData=0x04;SPI1_Exchange(&uTransmitData,&uReceiveData);uTransmitData=0x00;SPI1_Exchange(&uTransmitData,&uReceiveData);uTransmitData=0x00;SPI1_Exchange(&uTransmitData,&uReceiveData);uReceiveData;uTransmitData=0x00;SPI1_Exchange(&uTransmitData,&uReceiveData);uTransmitData=0x95;SPI1_Exchange(&uTransmitData,&uReceiveData);uTransmitData=NULL;uReceiveData=0x00;无符号字符测试;而如果(UnvaveDATA!= 0){测试=1;}空隙SPI1a交换(空隙* pTrimeDATA,Valu*PulvEDATA){UIT88T DimyRead=0;UIT88T DimyDeals= 0xFF;//SPI1DimMyDATA;IF(pPrimeDATA=NULL){pPrimeDATA=&;DimyWrand;}(pPurveDATA=null){pPrimvEdATA=和DimyRead;}(SPI1STATLITSP.SPI)TBF=1){}//--------//发送数据//-------SPI1BUFL**((UIT88*T*)pSimultDATA);而(SPI1STATLITS.SpBube=1){}//--------//提取数据//---------*((UIT88*T*)PrimvEDATA)=(UIT88T)(SPI1BUFL);}

以上来自于百度翻译


      以下为原文

    The only problem with making your suggested changes is that the SPI port no longer outputs data.
 
I need to get values (0xFF, 0x04, etc.) to SPI1_Exchange. 
 
The first way that I had it setup actually transmits data on the SPI port.
 
The new way does not:
 

    uint8_t uTransmitData, uReceiveData;

    uTransmitData    = 0xFF;
    uReceiveData    = NULL;

    EnableMSD_SS_Port;
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    SPI1_Exchange(&uTransmitData, &uReceiveData);

    DisableMSD_SS_Port;
    uTransmitData    = 0x04;
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    uTransmitData    = 0x00;
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    uTransmitData    = 0x00;
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    uTransmitData    = 0x00;
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    uTransmitData    = 0x00;
    SPI1_Exchange(&uTransmitData, &uReceiveData);
    uTransmitData    = 0x95;
    SPI1_Exchange(&uTransmitData, &uReceiveData);


    uTransmitData    = NULL;
    uReceiveData    = 0x00;

unsigned char test;

    while(1)
    {

        SPI1_Exchange(&uTransmitData, &uReceiveData);

        if (uReceiveData != 0)
        {    test = 1;    }
        

    }
 
void SPI1_Exchange( void *pTransmitData, void *pReceiveData )
{
    uint8_t dummyRead = 0;
    uint8_t dummyWrite = 0xFF;//spi1DummyData;

    if(pTransmitData == NULL)
    {
        pTransmitData = &dummyWrite;
    }

    if(pReceiveData == NULL)
    {
        pReceiveData = &dummyRead;
    }

    while( SPI1STATLbits.SPITBF == 1 )
    { }

    // ----------------
    // sending data
    // ----------------
    SPI1BUFL = *((uint8_t*)pTransmitData);

    while ( SPI1STATLbits.SPIRBE == 1)
    { }

    // ----------------
    // extracting data
    // ----------------
    *((uint8_t*)pReceiveData) = (uint8_t)(SPI1BUFL);
}
举报

陈晨

2019-6-26 07:13:46
UIT88tutuvEDATA;UTIN 8UT传输数据;UpRealDATA=0XFF;SPI1X交换机(UpStand Dead and UnvaveDATA);UpStReDATA=0x04;SPI1X交换机(UpStand Dead and UnvaveDATA);UpStReDATA=ETC;SPI1X交换机(UpStand Dead and UnvaveDATA);或者做一个更好的SPIL1Exchange()或马K-ANSPI1交换子块()

以上来自于百度翻译


      以下为原文

     
uint8_t uReceiveData;
 
uint8_t uTransmitData;
 
uTransmitData = 0xFF; 
SPI1_Exchange(&uTransmitData, &uReceiveData);
uTransmitData = 0x04; 
SPI1_Exchange(&uTransmitData, &uReceiveData); 
uTransmitData = etc; 
SPI1_Exchange(&uTransmitData, &uReceiveData);
 
Or make a better SPI1_Exchange()
or Make an SPI1_Exchange_Block()
 
举报

李天竹

2019-6-26 07:30:50
如果你的目标是理解指针,你应该做一些有助于理解指针的事情。一旦你弄清楚它们是如何工作的,你就可以在你的代码中使用它们。这个特殊情况不是很好,因为不需要指针,而且只是不必要地使事情变得更复杂。用这种人造的例子很难理解指针。函数只需要取值发送,那么它可以返回它所接收的任何内容:

以上来自于百度翻译


      以下为原文

    If your goal to understand pointers, you should do something which helps to understand pointers. Once you figure out how they work, you can use them in your code.
 
This particular case is not very good, because pointers are not needed and only needlessly make things more complicated. It is hard to understand pointers with such artificial examples. The function only need to take the value to send, then it can return whatever it has received:
 
uint8_t SPI1_Exchange( uint8_t uTransmitData )
{
    while( SPI1STATLbits.SPITBF == 1 )
    { }

    // ----------------
    // sending data
    // ----------------
    SPI1BUFL = uTransmitData;

    while ( SPI1STATLbits.SPIRBE == 1)
    { }

    // ----------------
    // extracting data
    // ----------------
    return SPI1BUFL;
}
举报

更多回帖

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