Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Storage / Sd card reading once then stops on: July 20, 2011, 04:04:57 pm
Hi everyone. I'm having a problem reading from my sd card. I bought a breakout board from cutedigi for the sd card

http://www.cutedigi.com/product_info.php?products_id=4435

and i also bought the vs1053 breakout board from sparkfun for mp3 decoding

http://www.sparkfun.com/products/9943

I set up my arduino to have the same configuration as the mp3 shield that sparkfun has

http://www.sparkfun.com/products/10628

Escept for the sd card breakout board. That uses all 5v input so i did not pass the sd wires through the voltage regulator. I also used the code from the shield... basically what i am trying to do is take what i can do with the mp3 shield and integrate it into a smaller project.

Code:

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Dev/Arduino/Shields/MP3_Player_Example.pde

The problem with that is that i can read from the sd card for the first bit of info that i need, after that the DREQ pin on the VS1053 goes high but it seems that i cannot read from the sd card again. Also when i try to reset it it doesn't let me initialize the card or the volume and the root doesn't open. I have to take the sd card out manually and put it back in while i reset the arduino, only then does it allow me to read more data, but it's still just the first part of the song. I've tried multiple sd cards and it doesn't work.

Do i have to cycle the power to the sd card? or am i missing the 10k pull-up resistors? whats the problem? can anyone please help?
Thanks
2  Development / Other Software Development / Re: DuinOS: Small and Simple OS based on FreeRTOS on: July 04, 2011, 02:58:14 am
Hey, i just started toying around with DuinOS. And i want to implement it into one of my projects...

I have an atmega328 with the optiboot boot loader (arduino uno) on a breadboard. I have that hooked up to an lcd and some buttons, ultimatley i want to hook it up to an mp3 decoder. I have a whole gui and a couple games built into one of the task loops, the other one is going to take care of talking to an sd card and sending the data to an mp3 decoder... The problem is when i try to load up the gui it doesn't come up.

Nothing happens... i think im getting a stack overflow but i am not sure... is there anyway to detect this? Or am i doing it wrong? I am leaving the loop empty and declaring a task loop that i start in the setup, should i start it with a stack and how big? thanks in advanced for the help.
3  Using Arduino / Networking, Protocols, and Devices / Re: SDfat and SPI library on: April 12, 2011, 02:45:25 pm
well i did it because i don't know how long the song would be and it's just a test run... i just want the song to play and i couldn't think of a better way to have the data stored without still having access to the sd card via spi. unless the file class doesn't keep the spi port open. but i wasn't to sure on it.
4  Using Arduino / Networking, Protocols, and Devices / SDfat and SPI library on: April 12, 2011, 07:56:00 am
I'm trying to use the sdfat library with the arduino spi library. I'm using the arduino uno and trying to use both as slaves. They both work seperatley, but when i try to combine them it doesn't work. Neither one of the spi slaves interacts and the whole thing just goes wrong, it doesn't even write anything to the slave.

heres the code:


Code:
#include <SPI.h>
#include <SdFat.h>

int CS_pin = 8;
int DCS_pin = 9;
int DREQ_pin = 7;
int XRST_pin = 6;
int MP3_CS_pin = 10;


SdFat sd;
SdFile myFile;
byte dat[10000];
int index = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(MP3_CS_pin, OUTPUT);
  pinMode(CS_pin, OUTPUT);
  pinMode(DREQ_pin, INPUT);
  pinMode(DCS_pin, OUTPUT);
  pinMode(XRST_pin, OUTPUT);
 
 

}

void playSong(){
  for(int i = 0; i < index; i++){
    SPI.transfer(dat[i]);
  }
}

void loop()
{
  digitalWrite(MP3_CS_pin, HIGH);
  digitalWrite(CS_pin, HIGH);
  digitalWrite(DCS_pin, HIGH);
 
  delay(100);
 
  if (!sd.init(SPI_HALF_SPEED, MP3_CS_pin)) sd.initErrorHalt();
 
  // re-open the file for reading:
  if (!myFile.open("song1.mp3", O_READ)) {
    sd.errorHalt("error opening song1.mp3 for read");
  }
  Serial.println("song1.mp3:");
   
  int data;
  while ((data = myFile.read()) >= 0){
    Serial.write(data);
    dat[index++] = data;
  }
 
  myFile.close();
  digitalWrite(MP3_CS_pin, HIGH);
 
 SPI.begin();
 
 SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE1);
 //max SDI clock freq = CLKI/7 and (datasheet) CLKI = 36.864, hence max clock = 5MHz
 //SPI clock arduino = 16MHz. 16/ 4 = 4MHz -- ok!
 SPI.setClockDivider(SPI_CLOCK_DIV4);
 
 digitalWrite(XRST_pin, LOW);
 delay(100);
 
 digitalWrite(CS_pin, HIGH);
 digitalWrite(DCS_pin, HIGH);
 digitalWrite(XRST_pin, HIGH);
 delay(5);

 // CHIP Write
 // sets sci_mode register, SM_SDINEW, SM_TESTS, SM_STREAM.  pg 25, 26
 byte aux;
 digitalWrite(CS_pin, LOW);
 delay(1);
 SPI.transfer(0x02);  //write command
 SPI.transfer(0x00); //SDI_MODE register
 //extract and send higher byte of data
 //0x0400
 aux = 0x08A0 >> 8;
 SPI.transfer(aux);
 //extract and send lower byte of data
 aux = 0x08A0 & 0b11111111;
 SPI.transfer(aux);
 //wait for the chip to finish executing command
 while (!DREQ_pin){};
 digitalWrite(CS_pin, HIGH);
 delay(1);

 // Start SINE test
 digitalWrite(CS_pin, HIGH);
 digitalWrite(DCS_pin, LOW);
 delay(1);
 
 playSong();

 delay(200);
 digitalWrite(DCS_pin, HIGH);
}

i've been at this for like 2 weeks now and im super frustrated >.<
please help.
5  Using Arduino / Storage / Re: An eaiser to use SD library on: April 11, 2011, 08:47:40 pm
no this is on the arduino uno. i think i might do the same thing u did.
6  Using Arduino / Storage / Re: An eaiser to use SD library on: April 11, 2011, 08:10:55 pm
I'm trying to use your library with the arduino spi library. sorry to bother you again but can you please help me out with the code?

Code:
#include <SPI.h>
#include <SdFat.h>

int CS_pin = 8;
int DCS_pin = 9;
int DREQ_pin = 7;
int XRST_pin = 6;
int MP3_CS_pin = 10;


SdFat sd;
SdFile myFile;
byte dat[10000];
int index = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(MP3_CS_pin, OUTPUT);
  pinMode(CS_pin, OUTPUT);
  pinMode(DREQ_pin, INPUT);
  pinMode(DCS_pin, OUTPUT);
  pinMode(XRST_pin, OUTPUT);
 
 

}

void playSong(){
  for(int i = 0; i < index; i++){
    SPI.transfer(dat[i]);
  }
}

void loop()
{
  digitalWrite(MP3_CS_pin, HIGH);
  digitalWrite(CS_pin, HIGH);
  digitalWrite(DCS_pin, HIGH);
 
  delay(100);
 
  if (!sd.init(SPI_HALF_SPEED, MP3_CS_pin)) sd.initErrorHalt();
 
  // re-open the file for reading:
  if (!myFile.open("song1.mp3", O_READ)) {
    sd.errorHalt("error opening song1.mp3 for read");
  }
  Serial.println("song1.mp3:");
   
  int data;
  while ((data = myFile.read()) >= 0){
    Serial.write(data);
    dat[index++] = data;
  }
 
  myFile.close();
  digitalWrite(MP3_CS_pin, HIGH);
 
 SPI.begin();
 
 SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE1);
 //max SDI clock freq = CLKI/7 and (datasheet) CLKI = 36.864, hence max clock = 5MHz
 //SPI clock arduino = 16MHz. 16/ 4 = 4MHz -- ok!
 SPI.setClockDivider(SPI_CLOCK_DIV4);
 
 digitalWrite(XRST_pin, LOW);
 delay(100);
 
 digitalWrite(CS_pin, HIGH);
 digitalWrite(DCS_pin, HIGH);
 digitalWrite(XRST_pin, HIGH);
 delay(5);

 // CHIP Write
 // sets sci_mode register, SM_SDINEW, SM_TESTS, SM_STREAM.  pg 25, 26
 byte aux;
 digitalWrite(CS_pin, LOW);
 delay(1);
 SPI.transfer(0x02);  //write command
 SPI.transfer(0x00); //SDI_MODE register
 //extract and send higher byte of data
 //0x0400
 aux = 0x08A0 >> 8;
 SPI.transfer(aux);
 //extract and send lower byte of data
 aux = 0x08A0 & 0b11111111;
 SPI.transfer(aux);
 //wait for the chip to finish executing command
 while (!DREQ_pin){};
 digitalWrite(CS_pin, HIGH);
 delay(1);

 // Start SINE test
 digitalWrite(CS_pin, HIGH);
 digitalWrite(DCS_pin, LOW);
 delay(1);
 
 playSong();

 delay(200);
 digitalWrite(DCS_pin, HIGH);
}

sorry to bother you so much but i've been at this for like 2 weeks now and im super frustrated >.<
7  Using Arduino / Storage / Re: Sd and SPI library? on: April 11, 2011, 07:44:41 pm
yeah it is, they haven't updated... so what i started doing was using the alternate cores:

http://www.avr-developers.com/corefiles/index.html

the libraries work with that but apparently the pins are a little off.
8  Using Arduino / Storage / Re: Sd and SPI library? on: April 11, 2011, 07:02:40 pm
what do you mean all the mods for a sanguino? i have the sanguino stuff on my arduino ide aswell but the libraries don't work with it! =/
9  Using Arduino / Storage / Re: Sd and SPI library? on: April 11, 2011, 05:45:27 pm
it doesn't work!... now that i notice... with the different arduino cores none of the pins work above thirteen on the atmega644p and miso mosi and sck still dont output a thing
10  Using Arduino / Storage / Re: Sd and SPI library? on: April 11, 2011, 09:32:58 am
okay, i get it. that seems simple enough... also i would like to ask if you know how i could change the output pins of the spi library for the arduino, because i'm using an atmega644p from the arduino alternate core software. the pins are:

ss            pin 4
mosi        pin 5
miso        pin 6
sck          pin 7

could you please help me try to figure this out? i know the sd libray works, but not the spi library.
11  Using Arduino / Storage / Re: Sd and SPI library? on: April 11, 2011, 08:25:02 am
that's awsome... i've used your sdfat library but i haven'y had time to figure all of it out. and so could i use your sdfat library with the spi library on the arduino ide with no problem?
12  Using Arduino / Networking, Protocols, and Devices / Re: atmega644p with spi on: April 11, 2011, 08:21:06 am
lol yeah i really have... nothing seems to be working =/ but i tried changing them and it doesn't change anything... should i do it in my program or in the actual spi.h or spi.cpp files?
13  Using Arduino / Networking, Protocols, and Devices / atmega644p with spi on: April 10, 2011, 10:20:39 pm
how would i go in and change the code from the spi.h or spi.cpp to have the pins set up for the atmega644p from the alternate core files for the arduino:

http://www.avr-developers.com/corefiles/index.html

i've hooked up leds to monitor all three mosi miso and sck pins and none of them light up, i even hooked up pin 11 12 and 13 like on the regular arduino and none of those light up either. is there an easier way to do this? or how would i go in a change the code?
14  Using Arduino / Storage / Sd and SPI library? on: April 10, 2011, 09:15:41 pm
Hie everyone, i am trying to make an mp3 player through an sd card and a vs1003 breakout board. i got the sine test to work on the board and i also am able to read the mp3 file from the sd card. using the sd library and the spi library. But on separate programs. as soon as i try to combine them to play the song neither one works. I'm not sure that it's how the sd library is set up or how it works.

anyways heres the code:
Code:
#include <SPI.h>
#include <SD.h>

File myFile;

int CS_pin = 9;
int DCS_pin = 8;
int DREQ_pin = 7;
int XRST_pin = 6;
byte received;

void setup()
{
 pinMode(CS_pin, OUTPUT);
 pinMode(DREQ_pin, INPUT);
 pinMode(DCS_pin, OUTPUT);
 pinMode(XRST_pin, OUTPUT);
 pinMode(10, OUTPUT);
 
 Serial.begin(9600);
  Serial.print("Initializing SD card...");
 
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
  myFile = SD.open("song1.mp3");
  if (myFile) {
    Serial.println("song1.mp3 succesfully opened!");
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
 SPI.begin();
 SPI.setBitOrder(MSBFIRST);
 //CPOL = 0, CPHA = 1
 //see en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_Numbers
 //and decoder chip datasheet
 SPI.setDataMode(SPI_MODE1);
 //max SDI clock freq = CLKI/7 and (datasheet) CLKI = 36.864, hence max clock = 5MHz
 //SPI clock arduino = 16MHz. 16/ 4 = 4MHz -- ok!
 SPI.setClockDivider(SPI_CLOCK_DIV4);

}

void loop()
{
 digitalWrite(XRST_pin, LOW);
 delay(100);
 
 digitalWrite(CS_pin, HIGH);
 digitalWrite(DCS_pin, HIGH);
 digitalWrite(XRST_pin, HIGH);
 delay(5);

 // CHIP Write
 // sets sci_mode register, SM_SDINEW, SM_TESTS.  pg 25, 26
 byte aux;
 digitalWrite(CS_pin, LOW);
 delay(1);
 SPI.transfer(0x02);  //write command
 SPI.transfer(0x00); //SDI_MODE register
 //extract and send higher byte of data
 //0x0400
 aux = 0x0820 >> 8;
 SPI.transfer(aux);
 //extract and send lower byte of data
 aux = 0x0820 & 0b11111111;
 SPI.transfer(aux);
 //wait for the chip to finish executing command
 while (!DREQ_pin){};
 digitalWrite(CS_pin, HIGH);
 delay(1);
 
 digitalWrite(DCS_pin, LOW);
     
 // read from the file until there's nothing else in it:
 while (myFile.available()) {
    Serial.write(myFile.read());
 }
 // close the file:
 myFile.close();
 
 digitalWrite(DCS_pin, HIGH);
}

i also have the sdfat library, idk if that would be a little easier to use or if i have to learn the adi protocol for the sd card. please help.
15  Using Arduino / Networking, Protocols, and Devices / SPI and SD libraries? on: April 10, 2011, 08:24:18 pm
Hie everyone, i am trying to make an mp3 player through an sd card and a vs1003 breakout board. i got the sine test to work on the board and i also am able to read the mp3 file from the sd card. using the sd library and the spi library. But on separate programs. as soon as i try to combine them to play the song neither one works. I'm not sure that it's how the sd library is set up or how it works.

anyways heres the code:
Code:
#include <SPI.h>
#include <SD.h>

File myFile;

int CS_pin = 9;
int DCS_pin = 8;
int DREQ_pin = 7;
int XRST_pin = 6;
byte received;

void setup()
{
 pinMode(CS_pin, OUTPUT);
 pinMode(DREQ_pin, INPUT);
 pinMode(DCS_pin, OUTPUT);
 pinMode(XRST_pin, OUTPUT);
 pinMode(10, OUTPUT);
 
 Serial.begin(9600);
  Serial.print("Initializing SD card...");
  
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  
  myFile = SD.open("song1.mp3");
  if (myFile) {
    Serial.println("song1.mp3 succesfully opened!");
  } else {
   // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
 SPI.begin();
 SPI.setBitOrder(MSBFIRST);
 //CPOL = 0, CPHA = 1
 //see en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Mode_Numbers
 //and decoder chip datasheet
 SPI.setDataMode(SPI_MODE1);
 //max SDI clock freq = CLKI/7 and (datasheet) CLKI = 36.864, hence max clock = 5MHz
 //SPI clock arduino = 16MHz. 16/ 4 = 4MHz -- ok!
 SPI.setClockDivider(SPI_CLOCK_DIV4);

}

void loop()
{
 digitalWrite(XRST_pin, LOW);
 delay(100);
 
 digitalWrite(CS_pin, HIGH);
 digitalWrite(DCS_pin, HIGH);
 digitalWrite(XRST_pin, HIGH);
 delay(5);

 // CHIP Write
 // sets sci_mode register, SM_SDINEW, SM_TESTS.  pg 25, 26
 byte aux;
 digitalWrite(CS_pin, LOW);
 delay(1);
 SPI.transfer(0x02);  //write command
 SPI.transfer(0x00); //SDI_MODE register
 //extract and send higher byte of data
 //0x0400
 aux = 0x0820 >> 8;
 SPI.transfer(aux);
 //extract and send lower byte of data
 aux = 0x0820 & 0b11111111;
 SPI.transfer(aux);
 //wait for the chip to finish executing command
 while (!DREQ_pin){};
 digitalWrite(CS_pin, HIGH);
 delay(1);
 
 digitalWrite(DCS_pin, LOW);
    
 // read from the file until there's nothing else in it:
 while (myFile.available()) {
    Serial.write(myFile.read());
 }
 // close the file:
 myFile.close();
 
 digitalWrite(DCS_pin, HIGH);
}

i also have the sdfat library, idk if that would be a little easier to use or if i have to learn the adi protocol for the sd card. please help.
Pages: [1] 2 3 ... 7