I've made this function, please correct me if I'm wrong, I can't hear the sound, but it can finish correctly...
That code shows some promise, but why are there two loops? You only need one loop to read the file and send it to VS1053. The 2048 zeros; forget about them at this time. You just send them after listening to the whole song.
The loop to play a file should be very simple, something like this:
Code: Select all
while (file_size > BUFFER_SIZE) {
//Read BUFFER_SIZE bytes from file to buffer
FAT32_Read(fileHandle, mp3_buffer, BUFFER_SIZE);
// Send BUFFER_SIZE bytes from the buffer to the VS1053
for (i=0; i<BUFFER_SIZE/32; i++) {
MP3_SDI_Write_32(mp3_buffer + i*32);
}
file_size -= BUFFER_SIZE;
}
Your code has a lot of extra stuff, throw that away. MP3_SDI_Write_32() seems to handle XDCS (BSYNC) so don't handle it a second time in your code.
PS. Here's MP3_SDI_Write_32() rewritten to follow VLSI coding guidelines a little bit more, so it's more understandable:
Code: Select all
void MP3_SDI_Write_32(char *data_) {
char i;
MP3_CS = 1; //Make sure XCS (SCI chip select) is high
while (DREQ == 0) {
//Do nothing, wait for DREQ to become high.
}
BSYNC = 0; //Pull XDCS (SDI chip select) low
for (i=0; i<32; i++) { //For 32 bytes,
SPI_Write(data_[i]); //Send a byte.
}
BSYNC = 1; //Pull XDCS (SDI chip select) high
}