完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
嗨,我正在阅读文件从一个新的微型SD卡使用PIC32 EF非密码起动器套件和多媒体扩展板II(MEB II)。我正在读取一个文件并显示在一个128×32的RGB LED显示屏上。它运行良好(计划优化更多的速度)使用波特率低于700千赫,但当我把速度改变到上面的任何初始化后,它被卡住(我会强调它在代码-见SPI2Read())。文件说要初始化卡在400千赫,我这样做。我已经证实波特率确实在一个范围内转换。这些信号看起来很干净,而且相当平直。我的代码张贴在下面,我注意到它被卡在哪里。它只是不断尝试发送,好像卡没有接收或发送任何东西回来。我有什么遗漏了吗?MEB II板上有什么东西会弄脏这个吗?如果有人知道这个,我会很感激的。相关代码如下:
以上来自于百度翻译 以下为原文 Hi, I'm reading files from a new Micro SD card using the PIC32 EF non-crypto Starter Kit and Multimedia Expansion Board II (MEB II). I'm reading a file and displaying it on a 128 x 32 RGB LED display. It's working fine (planning on optimizing for more speed) using a baud rate below ~700KHz, but when I change the speed to anything above that after initialization, it gets stuck (I'll highlight it in the code - see SPI2Read()). The documentation says to initialize the card at 400KHz, which I do. I've confirmed that the baud rate does switch with a scope. The signals look clean and fairly square. My code is posted below and I note where it gets stuck. It just keeps trying to transmit as if the card isn't receiving or sending anything back. Is there something I'm missing? Is there something on the MEB II board that could mess this up? If anyone has a clue about this, I would appreciate it. Relevant code posted below: /***** spi.c *****/ #include "main.h" unsigned char r, poo; int t; void InitSPI(void) { int rData, i; IEC4CLR = 0x1c000; // disable all interrupts SPI2CON = 0; // Stops and resets the SPI2. rData = SPI2BUF;// clears the receive buffer IFS4CLR = 0x1c000; // clear any existing event IPC35CLR = 0x1f000000; // clear the priority IPC35SET = 0x0d000000; // Set IPL=3, Subpriority 1 SPI2BRG = 124;// buad rate = PBCLK2 (100MHz) / ((SPI2BRG + 1) / 2) or 400KHz SPI2STATCLR = 0x40;// clear the Overflow SPI2CON = 0x8220;// SPI ON, 8 bits transfer, SMP=1, Master mode // from now on, the device is ready to transmit and receive data } void ChangeSPISpeed(unsigned int newspeed) { DESELECT SPI2CON = 0; // Stops and resets the SPI2. SPI2BRG = 124; // 10 MHz - I've tried other speeds SPI2CON = 0x8220;// SPI ON, 8 bits transfer, SMP=1, Master mode SELECT } unsigned char SPI2_Read(void) { Timer1 = 10; SPI2BUF = 0xff; while (!SPI2STATbits.SPITBE && Timer1); /*************** code getting stuck here ***************/ return SPI2BUF; } // Transmit a byte via SPI channel 2 void SPI2_Xmit( unsigned char data ) { SPI2BUF = (unsigned short)data; // place the data in the buffer while (!SPI2STATbits.SPITBE); // wait until the transmit buffer is empty (data has been sent) while (SPI2STATbits.SPIRBE); // wait until a byte is received poo = SPI2BUF; // byte received during transmit is junk } // Send a command packet unsigned char Cmd_Send ( unsigned char cmd, /* Command unsigned char */ unsigned int arg, /* Argument */ unsigned char crc /* CRC */ ) { if (cmd & 0x80) // if the command is an ACMD (application command), send CMD55 first { cmd &= 0x7F; // all ACMDs have the 7th bit set, so mask it out r = Cmd_Send(CMD55, 0, 0xff); // send CMD55 first if (r > 1) return r; // response should be 0 or 1 } DESELECT SELECT while(SPI2_Read() != 0xff); // give the SD card some time to prepare for the next instruction and flush the bytes or something Timer1 = 10; while (Timer1); /* Send command packet */ SPI2_Xmit(cmd); /* Command */ SPI2_Xmit((unsigned char)(arg >> 24)); /* Argument[31..24] */ SPI2_Xmit((unsigned char)(arg >> 16)); /* Argument[23..16] */ SPI2_Xmit((unsigned char)(arg >> 8)); /* Argument[15..8] */ SPI2_Xmit((unsigned char)arg); /* Argument[7..0] */ SPI2_Xmit(crc); t = 10; do { r = SPI2_Read(); } while ((r & 0x80) && --t); // read until bit 7 is not set return r; } |
|
相关推荐
8个回答
|
|
|
所以,我不能发布比SPI.C更多的代码,否则我会被拒绝访问。我不能附加文件或访问被拒绝!这个糟糕的网站是什么?我读了关于禁止词和SPI.C的帖子,和我想发布的其他文件没有什么不同。这个网站变得没用了!我花了更多的时间试图找到“禁止的词”,并试图找出为什么我不能发布比我花了编码!
以上来自于百度翻译 以下为原文 So, I can't post any more code than spi.c or I get Access Denied. I can't attach files or I get Access Denied! What is it with this lousy site? I read the post about forbidden words and spi.c isn't any different than the other files I want to post. This site is becoming useless! I've spent more time screwing with trying to find "forbidden words" and trying to figure out why I can't post than I've spent coding! |
|
|
|
|
|
什么是“Time1”?它是中断处理程序中使用的计数器吗?在这种情况下,它是否声明为易失性的?
以上来自于百度翻译 以下为原文 What is "Timer1"? Is it a counter used in an Interrupt handler? In this case, is it declared volatile? |
|
|
|
|
|
Time1和Time2用于时间1ms递增。我把它们设置为一个值,它们每1ms减少到0,这样我就可以做超时了。是的,它们是挥发性的。我通过一些修修补补发现,卡在这里意味着卡出了问题。这也发生在我的代码遇到问题时,它发送了一个超出范围的区域来读取。所以,卡不喜欢什么,它停止响应…但是如果我把SPI时钟降低到-700千赫,那么完全相同的代码就可以工作了。
以上来自于百度翻译 以下为原文 Timer1 & Timer2 are used to time 1mS increments. I set them to a value and they decrement every 1mS to 0, so I can do things like timeouts. Yes, they're volatile. I found out through some tinkering that it getting stuck here means the card sensed something wrong. This also happened when I had a problem with my code and it sent it an out-of-range sector to read. So, the card didn't like something and it quit responding... but if I just lower the SPI clock to < ~700KHz, the exact same code works fine. void __ISR(_TIMER_2_VECTOR, IPL3SRS) _InterruptHandler_TMR2(void) { if (Timer1) Timer1--; // decrement Timer1 if (Timer2) Timer2--; // decrement Timer2 IFS0CLR = _IFS0_T2IF_MASK; // be sure to clear the Timer2 interrupt status } |
|
|
|
|
|
我明白了,那好吧。我错过了一部分,“如果你只是跑得慢,一切都好”:在这些情况下,它通常是一个硬件问题。比如说,水平,长的电线,电容在线路。
以上来自于百度翻译 以下为原文 I see, ok then. I missed the part that "if you just run slower everything is ok": in these cases it's usually a problem with hardware... Say, levels, long wires, capacitance at lines |
|
|
|
|
|
当阅读和写作到SPI2BUF时,不要依赖SPITBE。在一切都被剔除之前,这一切都会澄清。也可以将上面的函数组合成一个函数,只需调用0xFF作为读取参数,而忽略写入时的返回值。
以上来自于百度翻译 以下为原文 When reading from and writing to SPI2BUF, don't rely on SPITBE. This clears before everything is clocked out. Use SPIRBF. e.g. unsigned char SPI2_Read(void) { Timer1 = 10; SPI2BUF = 0xff; while (!SPI2STATbits.SPIRBF && Timer1); /*************** code getting stuck here ***************/ return SPI2BUF; } // Transmit a byte via SPI channel 2 void SPI2_Xmit( unsigned char data ) { SPI2BUF = data; // place the data in the buffer while (!SPI2STATbits.SPIRBF); // wait until a byte is received SPI2BUF; // byte received during transmit is junk } Also, the above can be combined into one function unsigned char SPI2_TRX( unsigned char data ) { SPI2BUF = data; // place the data in the buffer while (!SPI2STATbits.SPIRBF); // wait until a byte is received return SPI2BUF; // byte received during transmit is junk } Just call with 0xff as a parameter for reading, and ignore the return value when writing. |
|
|
|
|
|
Cinzia,我检查了10MHz的信号,看起来非常干净。这是PIC32起动器套件,在MeBII上使用微SD端口,所以最好不要有任何长引线,etc. Simong,我会试试…谢谢大家
以上来自于百度翻译 以下为原文 Cinzia, I checked the signals at 10MHz and they look very clean. It's the PIC32 Starter Kit and using the Micro SD port on the MEBII, so it better not have any long leads, etc. Simong, I'll try that... Thanks all |
|
|
|
|
|
嘿,我发现问题了,孩子,我觉得自己是个十足的白痴!这是一个定时器中断,我必须刷新一个小显示器。在较低的频率下,中断可以在接收缓冲器溢出并导致问题之前完成。我没有想到这个,因为我原来有一个中断和缓冲区的SPI接收。我禁用了显示器的计时器,它在10MHz时工作良好。谢谢你的提示。一个秘密和一个问题仍然存在,虽然……神秘-改变代码使用。SpBBF没有工作。在这一点上,这并不重要,但它仍然诱使我为什么。我见过很多其他示例代码,如Simong的上面,但我遇到这个问题时,我第一次开始编码和测试的微型SD卡SPI。只是,斯皮特工作。也许那些例子是MX,而不是MZ。不管怎样,在这一点上并不重要。问题是从SD卡中读取,仍然有一个无闪烁的显示。我想我得用DMA之类的东西。我链接2 AdfRuIT 62×32 RGB LED显示器,使一个128×32,如果时间是关闭的,他们会闪烁。
以上来自于百度翻译 以下为原文 Hey, I found the problem and, boy, do I feel like a complete idiot! It was a timer interrupt that I have to refresh a small display. At lower frequencies, the interrupt could finish before the receive buffer would overflow and cause problems. I didn't think about this because I originally had an interrupt and buffer for the SPI receive. I disabled the timer for the display and it worked perfectly at 10MHz. Thanks for the tips. One mystery and one problem still exist, though... Mystery - changing the code to use .SPIRBF didn't work. At this point, it doesn't matter, but it still intrigues me why. I've seen plenty of other sample code like Simong's above, but I ran into this problem when I first started coding and testing for the Micro SD card SPI. Only .SPITBE works. Maybe those examples were for MX, not MZ. Anyway, it doesn't matter at this point. The problem will be reading from the SD card and still having a flicker-free display. I guess I'll have to use DMA or something. I'm chaining 2 Adafruit 62 x 32 RGB LED displays to make a 128 x 32 and if the timing is off, they will flicker. |
|
|
|
|
|
奇怪那些小家伙会忽悠…通常,他们有一个I2C或SPI接口,因此“保持稳定”一旦收到数据…
以上来自于百度翻译 以下为原文 Stange that those little ones do flicker... usually they have a I2C or SPI interface and hence "stay steady" once data is received... |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
494 浏览 0 评论
5807 浏览 9 评论
2347 浏览 8 评论
2235 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3542 浏览 3 评论
1149浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1117浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
884浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
494浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-10 18:44 , Processed in 1.302619 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
429