void VsSineTest(){
unsigned char *p;
unsigned int i;
//p = HelloMP3;
/* Reset MP3 chip */
/* Pull xRESET low -> hardware reset */
VS1003B_XRESET_L();
_delay_ms(100); /* 100 ms delay */
/* Send dummy SPI byte to initialize SPI bus of Atmel microcontroller */
VS1003B_WriteByte(0xFF);
/* Un-reset MP3 chip */
VS1003B_XCS_H();
/* Pull xCS high */
/* Pull xDCS high */
VS1003B_XDCS_H();
/* Pull xRESET high */
VS1003B_XRESET_H();
_delay_ms(100); /* 100 ms delay */
/* VS10xx Application Notes, chapter 4.8 ---------------------------------*/
/* As an example, let's write value 0x0820 to register 00 byte by byte */
VS1003B_XCS_L();
/* Pull XCS low, now SPI writes go to SCI port */
VS1003B_WriteCMD(00,0x0820);
VS1003B_WriteCMD(SCI_VOL,0x0000); //max volume
/* Send SPI Byte, then wait for byte to be sent. */
/* 0x02 was WRITE command, 0x00 is register number */
/* This byte goes to MSB */
/* ..and this is LSB. (0x20=Allow Test Mode) */
VS1003B_Delay();
/* Wait until Atmel MCU signals SPI write complete */
VS1003B_XCS_H();
usart_pstr("WAITING FOR DREQ ! \n");
/* Pull XCS high, now SPI writes don't go to SCI port. */
loop_until_bit_is_set(VS1003B_PIN,VS1003B_DREQ);
if (bit_is_set(VS1003B_PIN,VS1003B_DREQ))
{
usart_pstr("\n DREQ = 1 \n \n");
}else
{
usart_pstr("\n DREQ = 0 \n \n");
}
/* pull XDCS low, now SPI writes go to SDI port */
VS1003B_XDCS_L();
/* Send a Sine Test Header to Data port*/
/*
p=readFile(READ,"test.mp3");
while (p <= &p[sizeof(p)-1])
{
VS1003B_WriteByte(pgm_read_byte(p++));
}
*/
//read_sdcard();
//readFile(READ,"test.mp3");
//while (p <= &p[sizeof(p)-1])
//{
// VS1003B_WriteByte(p++);
//}
while (p <= &HelloMP3[sizeof(HelloMP3)-1])
{
VS1003B_WriteByte(pgm_read_byte(p++));
}
/*
VS1003B_WriteByte(0x53);
VS1003B_WriteByte(0xef);
VS1003B_WriteByte(0x6e);
VS1003B_WriteByte(0x44);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
*/
/* - This is a special VLSI Solution test header - */
/* - that starts a sine sound. It's good for - */
/* - testing your code and the chip. */
VS1003B_Delay();
VS1003B_XDCS_H();
_delay_ms(500); /* 500 ms delay */
/* Stop the sine test sound */
VS1003B_XDCS_L();
/*
VS1003B_WriteByte(0x45);
VS1003B_WriteByte(0x78);
VS1003B_WriteByte(0x69);
VS1003B_WriteByte(0x74);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
*/
//SPIWait();
VS1003B_Delay();
//Mp3DeselectData();
VS1003B_XDCS_H();
_delay_ms(500); /* 500 ms delay */
usart_pstr("Sine wave test 's stoped, change to SPI High! \n");
VS1003B_XDCS_L(); // Pull XDCS low
if (bit_is_set(VS1003B_PIN,VS1003B_DREQ))
{
usart_pstr("\n DREQ = 1 \n \n");
}else
{
usart_pstr("\n DREQ = 0 \n \n");
}
for (i=0; i<2048; i++)
{
//while (bit_is_clear(VS1003B_PIN,VS1003B_DREQ)); // wait here until DREQ is high again
VS1003B_WriteByte(0);
}
VS1003B_Delay(0xffff); // Wait until SPI transfer is completed
//VS1003B_XDCS_H(); // Pull XDCS high
_delay_ms(500);
usart_pstr("VS1003 AND ATMEGA128 SAYING HELLO! \n \n" );
}
void read_sdcard()
{
unsigned char option, error, data[512], FAT32_active,f;
unsigned int i;
unsigned char fileName[13];
unsigned char *p;
TX_NEWLINE;
TX_NEWLINE;
usart_pstr("*********************************************");
TX_NEWLINE;
usart_pstr(" Riko is doing card Testing.. ");
TX_NEWLINE;
usart_pstr("*********************************************");
TX_NEWLINE;
cardType = 0;
for (i=0; i<10; i++)
{
error = SD_init();
if(!error) break;
}
if(error)
{
if(error == 1) usart_pstr("SD card not detected..");
if(error == 2) usart_pstr("Card Initialization failed..");
while(1); //wait here forever if error in SD init
}
switch (cardType)
{
case 1:usart_pstr("Standard Capacity Card (Ver 1.x) Detected!");TX_NEWLINE;
break;
case 2:usart_pstr("High Capacity Card Detected!");TX_NEWLINE;
break;
case 3:usart_pstr("Standard Capacity Card (Ver 2.x) Detected!");TX_NEWLINE;
break;
default:usart_pstr("Unknown SD Card Detected!");
break;
}
//SPI_HIGH_SPEED; //SCK - 4 MHz
_delay_ms(1); //some delay
FAT32_active = 1;
error = getBootSectorData (); //read boot sector and keep necessary data in global variables
if(error)
{
TX_NEWLINE;
usart_pstr("FAT32 not found!"); //FAT32 incompatible drive
FAT32_active = 0;
}
else
{
TX_NEWLINE;
usart_pstr("FAT32 found!"); //FAT32 incompatible drive
_delay_ms(1000);
}
TX_NEWLINE;
//start to send the file to VS1003 begin
//readFile( READ, "test.mp3");
readFile( READ, "test.txt");
//f=readFile( READ, "test.txt");
TX_NEWLINE;
}