//Connection vs1053b to Arduino mega
#define DATAOUT 51//MOSI
#define DATAIN 50//MISO -
#define SPICLOCK 52//sck
#define SLAVESELECT 53//ss
byte clr;
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<
{
};
return SPDR; // return the received byte
}
void setup()
{
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
// SPCR = 01010000
//interrupt disabled,spi enabled,m*** 1st,master,clk low when idle,
//sample on leading edge of clk,system clock/16 (fastest)
//The VS1053 spec states that the max SPI clock frequency is 5MHz, the data order is MSB, and the data is valid on
//the rising edge of the clock, so the default settings of the SPI Shortcut (500kHz, MSB, rising edge) are applicable.
// SPR0 set to 1 means 16/16 =1 MHz
SPCR = (1<
clr=SPSR;
clr=SPDR;
delay(10);
digitalWrite(SLAVESELECT,LOW);
spi_transfer(0x02);
spi_transfer(0x00);
spi_transfer(0x0c); //bits 8-15
spi_transfer(0x20); // bits 0-7 00100000 //allow SDI TESTs
digitalWrite(SLAVESELECT,HIGH);
delay(10);
//Once in Test mode SS should remain HIGH
spi_transfer(0x53);
spi_transfer(0xEF);
spi_transfer(0x6E);
spi_transfer(0xAA);
spi_transfer(0x00);
spi_transfer(0x00);
spi_transfer(0x00);
spi_transfer(0x00);
}
void loop()
{
}