Microcontroller examples for VS1063, VS1053, VS1003, VS1011

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi,

I had done the chip reset, I can get the great sine wave now. The problems that I found is a conflicting between SD card and the VS chip when sharing one SPI bus. the SD card as well as the VS code worked fine. But when I used both of them, it didn't work at all.

Any recommendation on this issues, please advice!

Thank you very much
User avatar
Henrik
VLSI Staff
Posts: 1294
Joined: Tue 2010-06-22 14:10

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by Henrik »

xuanvn wrote:Hi,

I had done the chip reset, I can get the great sine wave now. The problems that I found is a conflicting between SD card and the VS chip when sharing one SPI bus. the SD card as well as the VS code worked fine. But when I used both of them, it didn't work at all.
Ok, let's see. For us to be able to better help you, please answer these questions:
1) Which VS10xx chip are you using for testing?
2) Have you connected XDCS / XCS to the microcontroller? Or only XCS?
3) Are you running the SD card in SD Mode or SPI Mode?

Kind regards,
- Henrik
Good signatures never die. They just fade away.
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi Henrik,

I've just gone back to my project. Here is the information:
1. I used VS1053 and Microchip PIC18F87J50 for the testing
2. I used both XDCS and XCS (both of them are connected to microcontroller pins) - Don't use SM_SHARED
3. I used the library from microchip to run SD card, let I check which mode are used. But can you tell me what is the difference between SD mode and SPI mode in this case?

Thank you very much.
Xuanvn
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi Henrik,

I checked. I used SPI mode for the SD card.

Xuanvn
User avatar
Henrik
VLSI Staff
Posts: 1294
Joined: Tue 2010-06-22 14:10

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by Henrik »

All right.

What you need to do is to check with an oscilloscope to make sure that both chip selects of the VS1053 are high when you access the SD card, and similarly that the SD card chip select is high when you access VS1053.

To maintain sufficient speed, you need to read at least one disk block (512 bytes) at the time from the SD card, then transfer that to VS1053 in 32-byte chunks (or smaller), following the DREQ signal of VS1053. That should be enough for MP3 files.

First try with very low-bitrate files. For instance, you can create an 8 kHz mono 8 kbit/s file for yourself (with e.g. the free and good program Audacity, use Export), that way 512 bytes will last for half a second. When you get that working, you can try with "real" MP3 files.

If you need higher speeds, like 16-bit stereo PCM at 44.1 kHz, you need bigger buffers, and you need to use the MULTIPLE_BLOCK_READ command for the SD card. For some more info, have a look at viewtopic.php?f=10&t=983&start=10#p5038.

Kind regards,
- Henrik
Good signatures never die. They just fade away.
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi Henrik,

I know what you mean, but the situation is really strange to me. I remove all VS code and test the SD card again. It worked! But when I add the VS library (not call any function from this library yet) the SD card code stop work. It really make me mad.

I also attach the VS library. Could you please take a look on it. This library worked without SD card also.

Thank you
Attachments
VS1053Test.h
(20.93 KiB) Downloaded 767 times
VS1053Test.C
(14.88 KiB) Downloaded 995 times
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi Henrik,

I've just solved the problem. It is the difference from SPI speed between SD card and VS device. I made it similar and it worked. Now I am trying to play mp3 song. Thank you very much for your help.

xuanvn
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi Henrik,

I based on your library to build a simple mp3 playing function. It's just like that:

Code: Select all

void testMp3Play(const char *fileName)
{

    u_int32 bytesInBuffer;
    u_int32 pos=0;                // File position
    int endFillByte = 0;          // What byte value to send after file
    int endFillBytes = SDI_END_FILL_BYTES;
    int playMode = ReadVS10xxMem(PAR_PLAY_MODE);
    unsigned short oldMode;

    int i;
    
    FSFILE *readFp = FSfopen(fileName, "r");
    WriteSci(SCI_DECODE_TIME, 0);         // Reset DECODE_TIME
    while ((bytesInBuffer = FSfread(playBuf, FILE_BUFFER_SIZE, 1, readFp)) > 0)
    {
        u_int8 *bufP = playBuf;
        while (bytesInBuffer)
        {
            if (!(playMode & PAR_PLAY_MODE_PAUSE_ENA))
            {
                int t = min(SDI_MAX_TRANSFER_SIZE, bytesInBuffer);

                // This is the heart of the algorithm: on the following line
                // actual audio data gets sent to VS10xx.
                WriteSdi(bufP, t);

                bufP += t;
                bytesInBuffer -= t;
                pos += t;
            }
        }
    }
}
But it not working. The SD card is ok, I also can run the sine test for the VS and hear the 'beep' sound. I use Audacity to create a 8kb/s mp3 file for the testing.

Please take a look on my code and help me to play mp3 file.
Another question is that can we read mp3 file directly from SD card and transfer it to VS device like that

Thank you very much.
User avatar
Panu
VSDSP Expert
Posts: 2829
Joined: Tue 2010-06-22 13:43

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by Panu »

Hello, Xuanvn,

Yes, you should be able to send an MP3 file to VS10xx like that. Hopefully your WriteSDI function checks DREQ.

Please check the "MCU Howto" link below for common problems.

-Panu
xuanvn
User
Posts: 17
Joined: Wed 2013-12-25 6:02

Re: Microcontroller examples for VS1063, VS1053, VS1003, VS1

Post by xuanvn »

Hi Panu,

Here is my code of WriteSdi() function, I think it doesn't work, but I don't know why.
I also checked 4 situations of SPI Polarity, but nothing happened

Code: Select all

int WriteSdi(const u_int8 *data, u_int8 bytes)
{
    int j;
    u_int8 i;
    if (bytes > 32)
    return -1; // Error: Too many bytes to transfer!
    
    SPICON1bits.CKP = 0; // change SPI polarity for testing
    SPISTATbits.CKE = 0;

    while (!VS_DREQ); // Wait until DREQ is high
    VS_XDCS=0; // Activate xDCS
    for( j=0; j<cVS1053_CS_DELAY; j++);

    for (i=0; i<bytes; i++)
    {
        WriteSPIM(*data++);
    }

    for( j=0; j<cVS1053_CS_DELAY; j++);
    VS_XDCS=1; // Dectivate xDCS
    SPICON1bits.CKP = 0; // Return the polarity to communicate with SD card
    SPISTATbits.CKE = 1;
    return 0; // Ok
}
Post Reply