Microchip
直播中

汤敏树

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

Micro SD SPI无法高速工作

当我尝试发布时,我一直被拒绝访问!所以…我每次发布一点,看看防火墙是什么触发的。显然,我不能发布剩下的代码。所以,如果有人想看的话,告诉我,如果我还没有做的话,我会附上的。根据触发防火墙的帖子,“char”是一个触发字?不管怎样,如果有人能帮忙,请看下面的帖子。谢谢!

以上来自于百度翻译


      以下为原文

    I keep getting Access Denied when I try to post!!  So... I'm posting a little at a time to see what triggers the firewall.  Apparently, I can't post the rest of my code.  So, if anyone wants to look at it, let me know and I'll attach it if I haven't already done so.  According to the post about triggering firewalls, 'char' is a trigger word?  Anyway, if anyone can help, please see below post.  Thanks!

回帖(13)

王焕树

2019-1-28 12:22:11
这可能是你想发表的。你看到了:触发防火墙的表达式。

以上来自于百度翻译


      以下为原文

    It's probably what you're trying to post.
 
Have you seen: Expressions which trigger the firewall 
 
举报

林霆景

2019-1-28 12:35:42
我将张贴一位一次…嗨,我正在阅读文件从一个新的微型SD卡使用PIC32启动器套件和多媒体扩展板II(MEB II)。我正在读取一个文件并显示在一个128×32的RGB LED显示屏上。它运行良好(计划优化更多的速度)使用波特率低于700千赫,但当我把速度改变到上面的任何初始化后,它被卡住(我会强调它在代码-见SPI2Read())。文件说要初始化卡在400千赫,我这样做。我已经证实波特率确实在一个范围内转换。这些信号看起来很干净,而且相当平直。我的代码张贴在下面,我注意到它被卡在哪里。它只是不断尝试发送,好像卡没有接收或发送任何东西回来。我有什么遗漏了吗?MEB II板上有什么东西会弄脏这个吗?如果有人知道这个,我会很感激的。相关代码如下:SPI.cFr.c

以上来自于百度翻译


      以下为原文

    I'll post one bit at a time...
 
Hi,  I'm reading files from a new Micro SD card using the PIC32 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

 
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 = 4; // 10 MHz - I've tried other speeds
    SPI2CON = 0x8220;// SPI ON, 8 bits transfer, SMP=1, Master mode
    SELECT
}
 
unsigned char SPI2_Read(void)
{
   SPI2BUF = 0xff;
    while (!SPI2STATbits.SPITBE); // *********** This is where it gets stuck at baud rate > ~700KHz ***********
    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
    crap = 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;
}
 

 
file.c

//test
举报

杨叶

2019-1-28 12:41:29
嗨,你有PIC32启动套件:PIC32 MZ EF启动器套件?当做

以上来自于百度翻译


      以下为原文

    Hi ,
Which PIC32 starter kit do you have : PIC32MZ EF starter kit ?
Regards
 
举报

林霆景

2019-1-28 12:56:43
是的,这是一个PIC32 MZ EF非密码启动套件。200 MHz PIC32 MZ2048 EFH CPU

以上来自于百度翻译


      以下为原文

    Yes, it's a PIC32MZ EF non-crypto Starter Kit.  200MHz PIC32MZ2048EFH CPU
举报

更多回帖

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