Sm.r.Tadayoni
Junior Member level 1
Hi my friends.
I've written a code to play a song file for long time on repeat mode. Normally this code work correctly without any problem but for a short time. After for example 500 repeated, the sound goes to choppy mode, but when i change the player to other song, the other song will play correctly without any problem. I dont know why this is happening but as my research in code, i find out the uSDCard (High Capacitance) has delay to respond.
Normally the tokenCounter for other song is about 0x66, but for the corrupted song is more than 0xFFFF. I Confused that when i deleted the file and replaced the song again the song will play correctly but again after about 500 the song goes to choppy.
what was happening to the uSDCard or file...?
Thanks alot...
I've written a code to play a song file for long time on repeat mode. Normally this code work correctly without any problem but for a short time. After for example 500 repeated, the sound goes to choppy mode, but when i change the player to other song, the other song will play correctly without any problem. I dont know why this is happening but as my research in code, i find out the uSDCard (High Capacitance) has delay to respond.
Code:
/**
* @brief Receive a data block with specified length from SD/MMC.
*
* @param buf: Pointer to the data array to store the received data
* @param len: Specifies the length (in byte) to be received.
* The value should be a multiple of 4.
* @retval SD_TRUE or SD_FALSE
*/
SD_BOOL SD_RecvDataBlock (uint8_t *buf, uint32_t len)
{
uint8_t datatoken;
uint32_t i;
/* Read data token (0xFE) */
Timer1 = 10; /* Data Read Timerout: 100ms */
tokenCounter = 0;
do {
datatoken = SPIx_RecvByte ();
tokenCounter++;
if (datatoken == 0xFE)
break;
} while (Timer1);
if(datatoken != 0xFE)
return (SD_FALSE); /* data read timeout */
/* Read data block */
#ifdef USE_FIFO
SPIx_RecvBlock_FIFO (buf, len);
#else
for (i = 0; i < len; i++) {
buf[i] = SPIx_RecvByte ();
}
#endif
/* 2 bytes CRC will be discarded. */
SPIx_RecvByte ();
SPIx_RecvByte ();
return (SD_TRUE);
}
Normally the tokenCounter for other song is about 0x66, but for the corrupted song is more than 0xFFFF. I Confused that when i deleted the file and replaced the song again the song will play correctly but again after about 500 the song goes to choppy.
what was happening to the uSDCard or file...?
Thanks alot...