Microchip
直播中

汤敏树

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

Micro SD SPI无法高速工作

嗨,我正在阅读文件从一个新的微型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)

林霆景

2019-1-28 10:01:51
所以,我不能发布比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!
举报

李兆峰

2019-1-28 10:12:57
什么是“Time1”?它是中断处理程序中使用的计数器吗?在这种情况下,它是否声明为易失性的?

以上来自于百度翻译


      以下为原文

    What is "Timer1"? Is it a counter used in an Interrupt handler? In this case, is it declared volatile?
举报

林霆景

2019-1-28 10:30:45
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
}
 
举报

李兆峰

2019-1-28 10:36:53
我明白了,那好吧。我错过了一部分,“如果你只是跑得慢,一切都好”:在这些情况下,它通常是一个硬件问题。比如说,水平,长的电线,电容在线路。

以上来自于百度翻译


      以下为原文

    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
举报

更多回帖

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