完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,我是新的PIC世界,但经验丰富的Atmel AVRS。作为一个学习的尝试,我正在努力赶上PIC12F1840的速度。具体来说,我使用MPLAB X V 3.65和XC8 V. 1.42当前运行在“PRO”评估模式。编程的PIC12F1840工作与好奇板良好。我使用MPLAB代码配置器创建了基本的MCU配置(除了配置SPI从属接口之外,一切都是原样的)和核心SPI通信(从机)确实正在运行:……这确实非常接近我想要做的,即等待命令恢复。从SPI主控器中返回,然后返回可配置数组的内容。工作就像一个魅力。当编译时,上述代码产生以下存储器摘要:程序空间使用了5H(90)的1000小时字(2.2%)数据空间,使用100h字节(6.6%)的11h(17)数据空间,使用100h字节(0%)的0h(0)的数据堆栈空间,使用2H(2)O的E2H字节(0%)配置位的0H(0)。F2H字(100%)ID位置空间使用4H字节(0%)的0H(0),可将问题的大小定为保持64字节。但是一旦ARAYSIZE被定义为大于12,SPI通信就失败了,返回0x00或0xFF。定义数组大小为64:程序空间使用5h(90)的1000小时字(2.2%)数据空间,使用100h字节(27%)EEPROM空间的45小时(69),使用100h字节(0%)的0h(0)数据堆栈空间,使用2h(2)的2h(2)2H字(100%)ID位置SP的AH字节(0%)配置位。ACE使用4H字节的0H(0)(0%),除了没有被称为SPI函数的合理警告外,不输出编译器警告。无论是否在本地/函数范围内或被声明为全局,结果都是相同的。关于如何使尺寸可容纳64×UtiN 8T元素,我感到茫然。任何建议或解决方案都将是最值得赞赏的。
以上来自于百度翻译 以下为原文 Hi, I'm new to the PIC world but reasonably experienced with the Atmel AVRs. As an attempt at learning-by-doing, I'm trying to get up to speed with the PIC12F1840. Specifically, I'm using MPLAB X v. 3.65 and XC8 v. 1.42 currently running in the "PRO" evaluation mode. Programming the PIC12F1840 works fine with the Curiosity board. I've created the basic MCU configuration using the MPLAB Code Configurator (leaving everything as-is, except configuring the SPI slave interface) and the core SPI communication (slave) is indeed up running: #include #include #include "mcc_generated_files/mcc.h" #define ARRAYSIZE 12 void main(void) { uint8_t i, rxData; uint8_t aTable[ARRAYSIZE]; // data to be returned as response to 0x01 command SYSTEM_Initialize(); SPI_Initialize(); // dummy data for(i=0; i while(1) { rxData = SPI_Exchange8bit(0x00); if(rxData == 0x01) for(i=0; i } return; } ...which really is pretty close to what I want to do, i.e. waiting for a command to be received from the SPI master and then returning the contents of the aTable array. Works like a chARM. The above code, when compiled, yields the following memory summary: Program space used 5Ah ( 90) of 1000h words ( 2.2%) Data space used 11h ( 17) of 100h bytes ( 6.6%) EEPROM space used 0h ( 0) of 100h bytes ( 0.0%) Data stack space used 0h ( 0) of E2h bytes ( 0.0%) Configuration bits used 2h ( 2) of 2h words (100.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) Now, problem is - aTable should be dimensioned to hold 64 bytes. But once ARRAYSIZE is defined as greater than 12, the SPI communication fails miserably, returning either 0x00 or 0xFF. Defining ARRAYSIZE as 64 yields: Program space used 5Ah ( 90) of 1000h words ( 2.2%) Data space used 45h ( 69) of 100h bytes ( 27.0%) EEPROM space used 0h ( 0) of 100h bytes ( 0.0%) Data stack space used 0h ( 0) of AEh bytes ( 0.0%) Configuration bits used 2h ( 2) of 2h words (100.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) No compiler warnings are output, except for reasonable warnings of never-called SPI functions. The results are the same, no matter whether aTable remains in the local/function scope or is declared as a global. I'm at loss with regard to how I can dimension aTable to contain 64 x uint8_t elements. Any suggestions or workarounds would be most appreciated. |
|
相关推荐
5个回答
|
|
|
没有理由不起作用。问题在别处。
以上来自于百度翻译 以下为原文 There is No reason it should not work. The issue is elsewhere. |
|
|
|
|
|
它不太可能与你的问题有关,但是如果你使用UIT88.你应该包括Stdit.h。你说你在等待从SPI主机接收,但是你的代码看起来像是SPI大师。你确信你的SPI代码工作正常吗?看起来你假设这个问题与数组大小有关,而不是你从SPI中读取的字节数。你可以通过使数组“静态”来移动数组。
以上来自于百度翻译 以下为原文 It's not likely to be related to your problem, but you should include stdint.h if you're using uint8_t. You say you're waiting to receive from the SPI master, but your code looks like it is the SPI master. Are you sure your SPI code is working correctly? It seems like you're assuming that the problem is related to the array size rather than the number of bytes you're reading from SPI. You could move the array off of the stack by making it "static". |
|
|
|
|
|
谢谢你的输入。Stdit.h已经被MCC。H收录了。声明为静态的可得到与上面描述的相同的结果。SPI代码工作良好。也就是说,直到可定义的尺寸大于12。根据文档,SPIXExchange 8BIT是一个阻塞函数,直到有返回的东西才会返回。当AARYSIZE被定义为12或更小时,下面的代码片断工作得很好。初始代码的一个稍微修改的版本:当增加数组大小超过12:如果我注释了for循环,它初始化了可用的虚拟数据,并且取消了链接器的CLSELSS BSS选项,在发送0x02时,仍然得到预期的0xAA响应。自然,SDENGIN 0x01返回无意义的数据。使用明确的BSS选项(默认情况下)和/或for循环初始化可用数据,0x01和0x02都返回0x00和/或0xFF。问题很可能在别处,但事实上,一旦可阵列包含超过12个字节,并且这些字节被修改,则返回。价值/结果与我预期的不同。谢谢你的时间。
以上来自于百度翻译 以下为原文 Thanks for your inputs. The stdint.h is already included by mcc.h. Including it from the main file does not change anything. Declaring aTable as a static yields the same result as described above. The SPI code works fine. That is, until the size of aTable is defined as greater than 12. According to the documentation, the SPI_Exchange8bit is a blocking function which won't return until there is something to return. The below code snipet works fine when ARRAYSIZE is defined as 12 or less. A slightly modified version of the initial code: #include #include #include #include "mcc_generated_files/mcc.h" #define ARRAYSIZE 12 void main(void) { uint8_t i, rxData; uint8_t aTable[ARRAYSIZE]; // data to be returned as response to 0x01 command SYSTEM_Initialize(); SPI_Initialize(); // initialize dummy data // NOTE: try changing linker options (uncheck CLEAR BSS) AND comment out these two lines for(i=0; i while(1) { rxData = SPI_Exchange8bit(0x00); if(rxData == 0x01) for(i=0; i else if(rxData == 0x02) rxData = SPI_Exchange8bit(0xAA); // return a known value } return; } When increasing the ARRAYSIZE beyond 12: if I comment out the for loop which initializes the dummy data in aTable and uncheck the Clear bss option for the linker, I still get the expected 0xAA response when sending 0x02. Naturally, sending0x01 returns meaningless data. With the Clear bss option checked (as per default) and/or the for loop initializing the aTable data, both 0x01 and 0x02 return 0x00 and/or 0xFF. The issue may very well be elsewhere but it remains a fact that once the aTable array contains more than 12 bytes and these bytes are modified, the return values/results differ from what I expect. Thanks for your time. |
|
|
|
|
|
嗨,对于这个设备来说,不应该像你那样制造一个数组。我创建了一个使用MCC来生成一些SPI代码的项目,但是这是否是你正在构建的代码,我不知道。以12比64的数组大小编译生成指令序列几乎没有变化。一些指令使用数据64而不是12,而主()中的I和RxDATA变量被链接在不同的位置,因此使用了不同的地址。没有什么看起来可疑的。尝试删除SPI代码,并确保您满意的是,一个大数组适用于基本操作。确保测试代码做一些“功能”,以便优化器不删除它。确保看门狗被禁用或你经常踢它,并且没有中断未处理。如果添加SPI代码会导致一些失败,那么一些好的老式调试将帮助您找到事情出错的地方,并且可以从那里返回。注意,在我的示例中,没有需要清除的全局变量,所以检查或取消检查。清除BSS的选项在生成的输出上没有差别。如果您仍然有问题,请联系支持,但它们需要您的整个项目,以便它可以被编译为IS.JEFF。
以上来自于百度翻译 以下为原文 Hi, For that device, there should be no issue making an array as large as you did. I created a project that use MCC to generate some SPI code, but whether this is the same code that you are building, I have no idea. Compiling with the array size at 12 versus 64 produced very little change in the generate instruction sequence. Some instructions use the data 64 instead of 12, and the i and rxData variables in main() were linked in different locations, so there were some different addresses used. Nothing looked suspicious. Try removing the SPI code and make sure you are satisfied that a large array works for basic operations. Make sure you test code does something 'functional' so that the optimizer does not remove it. Make sure that the watchdog is disabled or that you kick it every so often, and that there are no interrupts unhandled. If the addition of the SPI code causes something to fail, then some good old fashion debugging will help you find the point at which things go awry and you can work back from there. Also note that in my example, there were no global variables that needed to be cleared, so checking or unchecking the option to clear bss made no difference in the generated output. If you are still having problems, contact support, but they will need your entire project so that it can be compiled as is. Jeff. |
|
|
|
|
|
正如杰夫所暗示的,你应该确保它不仅仅是在较长传输时触发的看门狗定时器。
以上来自于百度翻译 以下为原文 As Jeff hinted, you should make sure it's not just the Watchdog timer triggering on the longer transfer. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 02:45 , Processed in 1.450877 second(s), Total 82, Slave 65 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
3665