AnsweredAssumed Answered

Help!How to solve the problem "JUMP.S __unknown_exception_occurred "?

Question asked by wxc on Apr 22, 2013
Latest reply on May 20, 2013 by ColinJ

hello,everyone,

       I'm using ADSP BF533 to initialize SD card.I want to make it work in SPI mode.First,I send CMD0,then I can get the right response:0x01. Next,I send CMD8. My codes(only a part ) are as follows:

void main()

{

int i;

i=SD_Initialize();

}

 

functions:

uint8 SD_Initialize(void)

{

    uint8 recbuf[4],ret,i;

 

    SPI_INIT();                            

 

    SPI_CS_Assert();                           

    SD_SPIDelay(30);                          

    SPI_CS_Deassert();                         

 

    ret = SD_ResetSD();                           

    while(ret){ ret = SD_ResetSD();}

 

    ret=SD_Type();

    if (ret != SD_NO_ERR)

        return ret;   

 

    return SD_NO_ERR;   

}

uint8 SD_ResetSD(void)  

{


uint8 param[4] = {0,0,0,0},resp,check;

int i=0;

do

{

i++;

check=SD_SendCmd(CMD0, param, CMD0_R, &resp);

}while((check)&&(i<SD_RESET_TIMEOUT));

 


if(i>=SD_RESET_TIMEOUT)

{

if(check)

check=SD_ERR_TIMEOUT_WAITIDLE;

else

check=SD_NO_ERR;

}

else

check=SD_NO_ERR;

return check;

}

void  SPI_INIT(void)

{

    unsigned short  *pSPI_CTL=SPI_CTL;

    unsigned short  *pSPI_FLG=SPI_FLG;

    unsigned short  *pSPI_BAUD=SPI_BAUD;

    *pSPI_CTL&=0x0111;

    *pSPI_FLG=0xFF40;

    SPI_CS_Deassert();

    *pSPI_BAUD=0x0141;

    *pSPI_CTL|=0x1001;   

    *pSPI_CTL|=0x4000;   

}

 

void SPI_CS_Assert(void)

{

    unsigned short  *pSPI_FLG=SPI_FLG;

    *pSPI_FLG&=0xBFFF;

 

}

void SD_SPIDelay(uint8 value)

{

    uint8 i;

 

    for (i = 0; i < value; i++)

    SPI_SendByte(0xFF);                             /* 发送0xFF clock out 0xFF */

}

void SPI_CS_Deassert(void)

{

    unsigned short  *pSPI_FLG=SPI_FLG;

    *pSPI_FLG|=0x4000;

 

}

 

uint8 SD_SendCmd(uint8 cmd, uint8 *param, uint8 resptype, uint8 *resp)

{

    int i,rlen;                                     //所有SD卡命令都是6字节长

    uint8 tmp;

 

    SPI_CS_Assert();                                 //片选SPI从机

 

    SPI_SendByte((cmd & 0x3F)|0x40);                 /* 发送命令头和命令字 send command header and word */

    //起始位为0(bit47),传输位为1(bit46)

    for (i = 3; i >= 0; i--)                                                                                                                                                  

    SPI_SendByte(param[i]);                         /* 发送参数 send parameters */

 

//#if SD_CRC_EN

//    tmp = SD_GetCmdByte6((cmd & 0x3F) | 0x40, param);

//    SPI_SendByte(tmp);

//#else

//    SPI_SendByte(0x95);                                  /* CRC校验码,只用于第1个命令 CRC,only used for the first command */

//#endif

    if(cmd==0)SPI_SendByte(0x95);

    else if(cmd==8) SPI_SendByte(0x87);

    else SPI_SendByte(0xFF);

    rlen = 0;

    switch (resptype)                                 /* 根据不同的命令,得到不同的响应长度 */

    {                                                 /* according various command,get the various response length */

    case R1:

    case R1B: rlen = 1;  break;

 

    case R2:  rlen = 2;     break;

 

    case R3:  rlen = 5;     break;

 

    default:  SPI_SendByte(0xFF);   

          SPI_CS_Deassert();                        

          return SD_ERR_CMD_RESPTYPE;         /* 返回命令响应类型错误 return error of command response type */

          break;

    }

 

    i = 0;               

    do                                                  /* 等待响应,响应的开始位为0 */

    {                                                 /* Wait for a response,a response is a start bit(zero) */

    tmp = SPI_RecByte();

    i++;

    }while (((tmp & 0x80) != 0) && (i < SD_CMD_TIMEOUT));

 

 

    if (i >= 10)

    {                                                

    SPI_CS_Deassert();

    return SD_ERR_CMD_TIMEOUT;                     /* 返回命令超时 return response timeout of command */

    }

 

    for (i = rlen - 1; i >= 0; i--)

    {

    resp[i] = tmp;

    tmp = SPI_RecByte();                          /* 循环的最后发送8clock  at the last recycle,clock out 8 clock */

    }

 

    SPI_CS_Deassert();

    return SD_NO_ERR;                                 /* 返回执行成功 return perform sucessfully */

}

 

void SPI_SendByte(uint8 byte)

{

    uint8 temp;

    unsigned short  *pSPI_TDBR=SPI_TDBR;

    unsigned short  *pSPI_RDBR=SPI_RDBR;

    unsigned short  *pSPI_STAT=SPI_STAT;

    *pSPI_TDBR= byte;

    while(*pSPI_STAT&0x0008);

    while((*pSPI_STAT&0x0001)!=1);

    temp =*pSPI_RDBR;

}

 

uint8 SPI_RecByte(void)

{

    uint8 temp;

    unsigned short  *pSPI_TDBR=SPI_TDBR;

    unsigned short  *pSPI_RDBR=SPI_RDBR;

    unsigned short  *pSPI_STAT=SPI_STAT;

    *pSPI_TDBR=0xff;

 

    while(*pSPI_STAT&0x0008);

    while((*pSPI_STAT&0x0001)!=1);

    temp =*pSPI_RDBR;

    return(temp);                 /* 读取收到的字节 read the byte received */

 

}

 

uint8 SD_Type(void)  

{


uint8 param[4] = {0xAA,0x01,0,0},resp;

 


return (SD_SendCmd(CMD8, param, CMD8_R, &resp));

}

 

 


      Now,I come across a problem that when  the program run to the last line"return SD_NO_ERR" in the function SD_Initialize(),it'll get into a loop:EMUEXCPT ---IDLE ---CSYNC---JUMP.S __unknown_exception_occurred ---EMUEXCPT-------

      In the "Output window" prints "Target halted due to software breakpoint but no breakpoint found at address: 0xffa01a40".

      If I delete "ret=SD_Type();if (ret != SD_NO_ERR);return ret;",the problem is gone. If I add these lines,the problem appears.  

      I can't solve the problem,please help me.

      Enclosed is my project.

      Thanks.

Attachments

Outcomes