This is a modified code I tried, taking care of your hints and adding comments, but I also don´t get it to work with an Arduino Mega. However, because I am new to Arduino and microcontroller programming, this does not neccessarily have to mean anything... :).
//Connection vs1053b to Arduino mega
#define DATAOUT 51//MOSI
#define DATAIN 50//MISO -
#define SPICLOCK 52//sck
#define SLAVESELECT 53//ss
#define DREQ 49 //DREQ
#define VSRESET 48
byte clr;
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
void setup()
{
pinMode(VSRESET, OUTPUT);
digitalWrite(VSRESET, HIGH);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(SLAVESELECT,OUTPUT);
pinMode(DREQ, INPUT);
digitalWrite(SLAVESELECT,HIGH); //disable device
// SPCR = 01010000
//interrupt disabled,spi enabled,msb 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<<SPE)|(1<<MSTR) | (1<<SPR0) | (0<<CPOL) | (0<<CPHA) | (0<<DORD);
clr=SPSR;
clr=SPDR;
delay(1000);
digitalWrite(SLAVESELECT,LOW);
spi_transfer(0x02); // instruction byte set to "write"
spi_transfer(0x00); // address byte = 0
spi_transfer(0x0c); // bits 08-15 00001100 // SM_SDISHARE, SM_SDINEW (share SPI chip select, VS1002 native SPI modes)
spi_transfer(0x20); // bits 00-07 00100000 // SM_TESTS (allow SDI tests)
digitalWrite(SLAVESELECT,HIGH);
delay(1000);
//Once in Test mode SS should remain HIGH
digitalWrite(SLAVESELECT,HIGH);
spi_transfer(0x53); // this and the following two bytes are the command for sine test (p. 63)
spi_transfer(0xEF); // ^
spi_transfer(0x6E); // ^
//spi_transfer(0xAA); // 10101010 = Samplerate index (10?) + sine skip speed (10)
spi_transfer(0x7E); // for a sine wave test @ 5168 hz
spi_transfer(0x00); // needs to be 0x00
spi_transfer(0x00); // ^
spi_transfer(0x00); // ^
spi_transfer(0x00); // ^
digitalWrite(SLAVESELECT,LOW);
delay(1000);
digitalWrite(SLAVESELECT,HIGH);
spi_transfer(0x45); // exit sine test (p. 63)
spi_transfer(0x78); // ^
spi_transfer(0x69); // ^
spi_transfer(0x74); // ^
spi_transfer(0x00); // ^
spi_transfer(0x00); // ^
spi_transfer(0x00); // ^
spi_transfer(0x00); // ^
digitalWrite(SLAVESELECT,LOW);
}
void loop()
{
}
Any more hints what could be wrong? I also had connected the reset pin of the VS1053 board to the reset pin of Arduino, but still no success using iPod headphones.
This is a part of the example code available at http://www.sparkfun.com/datasheets/PCB/vs1002_Sine_Test_Tone.c:
int main (void) {
// configure SPI0 pins, master mode
PINSEL0 = 0x1500; // SPI pin connections
S0SPCCR = 32; // SCK = 1 MHz, counter > 8 and even
S0SPCR = 0x20; // Master, no interrupt enable
IODIR0 |= 0x00000080;
IOSET0 |= 0x80000080; // cs high to start
vs1002_SCI_write(0x00, 0x0c20); // sets sci_mode register, SM_SDINEW, SM_SDISHARE
// SM_TESTS. pg 25, 26
vs1002_sineTest(170); // test tone frequency (pg 35)
for (;;)
{
}
} //main
void vs1002_SCI_write(unsigned char address, unsigned short int data)
{
IOCLR0 |= 0x00000080; // cs low
S0SPDR = 0x02; // read command
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = address; // address here
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = data >> 8;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = data;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
IOSET0 |= 0x00000080;
}
// This is SDI write so cs is reversed (internally inverted), pg 21
// for a sine wave test @ 5168 hz, send sequence: 0x53, 0xEF, 0x6E, 126, 0, 0, 0, 0
void vs1002_sineTest(unsigned char pitch)
{
IOSET0 |= 0x00000080; // cs HIGH
S0SPDR = 0x53;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = 0xEF;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = 0x6E;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = pitch;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = 0;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = 0;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = 0;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
S0SPDR = 0;
while (!(S0SPSR & 0x80)) ; // wait for transfer completed
IOCLR0 |= 0x00000080; // cs LOW
}