完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
论坛,函数SPI1_Exchange(取自SD卡当前MLA示例)(见下文)使用指针。以下是我尝试从SPI1_exchange发送和接收数据。include
以上来自于百度翻译 以下为原文 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个回答
|
|
它声明变量是指针。您不能在那里这样做,因为指针还没有指向任何类型的缓冲区。字符不应该在那里,因为您已经传递了指针。现在可能是回到基本的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. |
|
|
|
进行建议的更改的唯一问题是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); } |
|
|
|
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() |
|
|
|
如果你的目标是理解指针,你应该做一些有助于理解指针的事情。一旦你弄清楚它们是如何工作的,你就可以在你的代码中使用它们。这个特殊情况不是很好,因为不需要指针,而且只是不必要地使事情变得更复杂。用这种人造的例子很难理解指针。函数只需要取值发送,那么它可以返回它所接收的任何内容:
以上来自于百度翻译 以下为原文 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; } |
|
|
|
指针只有在每个函数调用需要发送/接收多于一个字节时才有意义。
以上来自于百度翻译 以下为原文 Quoted for agreement. Pointers would only make sense here when you need to send/receive more than one byte per function call. |
|
|
|
|
|
|
|
const ut88t u传输数据={0xFF,0x04,等};-gt;const ut88t uTrimeDATABOR[]= {0xFF,0x04,等};
以上来自于百度翻译 以下为原文 const uint8_t uTransmitData = {0xFF, 0x04, etc}; -> const uint8_t uTransmitData[] = {0xFF, 0x04, etc}; |
|
|
|
好的,我想真正的问题是,我需要用一个指针来更新SPI1BUFL,如Exchange函数所示吗?如果不是那样,我能像所有其他寄存器一样正确对待吗?克雷格
以上来自于百度翻译 以下为原文 Ok, I guess the real question is do I need to update SPI1BUFL with a pointer as shown in the exchange function? If not then I can treat like all other registers correct? Craig |
|
|
|
你指的是哪个版本的代码?第一个邮局里的人太复杂了?NorthGuy在post#6中的代码会更好,完全不使用指针。不会为了发送一个虚拟字节而伪造空指针。
以上来自于百度翻译 以下为原文 Which version of the code are you referring to? The overcomplicated/buggy one in the first post? NorthGuy's code in post#6 would be much better, and doesn't use pointers at all. There's no faffing around with null pointers just to send a dummy byte. |
|
|
|
只有小组成员才能发言,加入小组>>
5146 浏览 9 评论
1993 浏览 8 评论
1921 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3162 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2218 浏览 5 评论
714浏览 1评论
601浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
484浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
615浏览 0评论
513浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-13 05:29 , Processed in 1.205052 second(s), Total 63, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号