Go Down

Topic: VS1053 not playing (Read 299 times) previous topic - next topic

Rukuta

Hello,
I am having difficulties getting the VS1053 to play. I am using the UNO (ATmega328p) with the SD-card Library. The VS is connected to the same hardware SPI with different CS, DCS and DREQ lines.
I looked at the Adafruit library but cant really see any mayor differences. But I must be missing something. I looked at the lines with a logic analyzer. The VS is responding with DREQ low pulses to commands. But when I stream the mp3 data, DREQ just stays high and no sound is playing. The very strange thing is, if I disconnect the VS and start the programm and then connect the VS when the stream is running, it starts to play the sound but with a lot if cracking and pauses. What am I missing? (the code is not finished yet with all the defies but should work anyhow).

Code: [Select]

#include <SPI.h>
#include <SD.h>

#define PPB0   8
#define PPB1   9
#define PPB2   10
#define PPB3   11
#define PPB4   12
#define PPB5   13

#define PPD0   0
#define PPD1   1
#define PPD2   2
#define PPD3   3
#define PPD4   4
#define PPD5   5
#define PPD6   6
#define PPD7   7
 
#define PPC0   14
#define PPC1   15
#define PPC2   16
#define PPC3   17
#define PPC4   18
#define PPC5   19

#define VS_REG_MODE   0x0
#define VS_REG_STATUS 0x1
#define VS_REG_BASS   0x2
#define VS_REG_CLOCKF 0x3
#define VS_REG_DECTIM 0x4
#define VS_REG_AUDATA 0x5
#define VS_REG_VOL    0xB

#define VS_MODE_SM_DIFF           0x0001
#define VS_MODE_SM_LAYER12        0x0002
#define VS_MODE_SM_RESET          0x0004
#define VS_MODE_SM_CANCEL         0x0008
#define VS_MODE_SM_EARSPKLO       0x0010
#define VS_MODE_SM_TESTS          0x0020
#define VS_MODE_SM_STREAM         0x0040
#define VS_MODE_SM EARSPEAKER HI  0x0080
#define VS_MODE_SM_DACT           0x0100
#define VS_MODE_SM_SDIORD         0x0200
#define VS_MODE_SM_SDISHARE       0x0400
#define VS_MODE_SM_SDINEW         0x0800
#define VS_MODE_SM_ADPCM          0x1000
#define VS_MODE_SM_LINE1          0x4000
#define VS_MODE_SM_CLKRANGE       0x8000

#define VS_READ   0b00000011
#define VS_WRITE  0b00000010

File fs;
uint8_t buffer[32];

#define VS_RST  PPC2
#define VS_DREQ PPC3
#define VS_CS   PPC4
#define VS_DCS  PPC5
#define SD_CS   PPB1
#define LED     PPB0

void setup()
{
  Serial.begin(115200);
  pinMode(LED, OUTPUT);

  pinMode(VS_RST, OUTPUT);
  digitalWrite(VS_RST, LOW);
  pinMode(VS_DREQ, INPUT);
  digitalWrite(VS_CS, HIGH);
  digitalWrite(VS_DCS, HIGH);
  pinMode(VS_CS, OUTPUT);
  pinMode(VS_DCS, OUTPUT);
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS))
  {
    Serial.println("initialization failed!");
    while(1);
  }else{
    Serial.println("initialization done.");
  } 
  digitalWrite(VS_RST, HIGH);
  while(!digitalRead(VS_DREQ));
  delay(10);
  vs_com(VS_WRITE, VS_REG_MODE, VS_MODE_SM_RESET|VS_MODE_SM_CANCEL|VS_MODE_SM_SDINEW|VS_MODE_SM_LINE1);
  vs_com(VS_WRITE, VS_REG_CLOCKF, 0x9800);
  vs_com(VS_WRITE, VS_REG_AUDATA, 44101);
  vs_com(VS_WRITE, VS_REG_VOL, 0x8080);
}

void vs_com(uint8_t rw, uint8_t adr, uint16_t dat)
{
  digitalWrite(VS_CS, LOW);
  SPI.transfer(rw);
  SPI.transfer(adr);
  SPI.transfer(dat);
  if(adr != VS_REG_VOL) delayMicroseconds(100);
  while(!digitalRead(VS_DREQ));
  digitalWrite(VS_CS, HIGH);
}

uint8_t vs_data()
{
  uint8_t cn;
  if(!fs) return 0;
  cn = fs.available();
  if(cn == 0) return 0;
  if(cn > 32) cn = 32;
  fs.read(buffer, cn);
  digitalWrite(VS_DCS, LOW);
  SPI.transfer(buffer, cn);
  digitalWrite(VS_DCS, HIGH);
 
/*  for(uint8_t i = 0; i < cn; i++)
  {
    digitalWrite(VS_DCS, LOW);   
    SPI.transfer(buffer[i]);
    digitalWrite(VS_DCS, HIGH);
  }*/
     
  return 1;
}

void loop()
{
  digitalWrite(LED, HIGH);
  fs = SD.open("FILE.MP3");

  uint8_t tmp;
  while(1)
  {
    if(digitalRead(VS_DREQ) == HIGH)
    {
      tmp = vs_data();
      if(tmp == 0) break;
    }
  }
 
  digitalWrite(LED, LOW);
 
  while(1);
}

Rukuta

I found the problem and it works now. Consider it closed.

Go Up