Pages: [1] 2   Go Down
Author Topic: sd with serial communication, how do?  (Read 1441 times)
0 Members and 1 Guest are viewing this topic.
piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
I have find this (bottom) Sd card reader but it work with serial communication, I try it but don't work, someone can help me

regards
stefano

* SD_UserManual.pdf (799.28 KB - downloaded 21 times.)
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I try it but don't work, someone can help me
Not likely. You haven't posted any code. You haven't described how that reader is connected. You haven't said what expect the code you have to do, or what it actually does. You haven't described what is on the card, and whether you are trying to read from it or write to it.

There is so much missing from your post that it is impossible to help you.
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok
in the arduino's playground/storage I read SD reader examples with spi communication only and library about this, with serial communication can I use the statements's file (bottom)

thanks
stefano
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46240
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
with serial communication can I use the statements's file (bottom)
I'm not sure that I understand the question. You won't be able to use the SD library to communicate with your reader, since the SD library expects to use SPI to talk to the SD reader, and yours will not respond to SPI pin wiggling.

There are commands in the pdf file that you linked that let you communicate with the device. Presuming that the device is connected to the same pins that the Serial instance is talking to.
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
this SD work with RX TX not SPI, then I am not sure I can use statements's file (bottom)

thanks
stefano
Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
can I use the statements's file (bottom)
Quote
I am not sure I can use statements's file (bottom)

What 'statements's file (bottom)'? What does that mean?
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
this is the sketch and file attachments

Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

void setup()  
{
  Serial.begin(9600);
  Serial.println("Goodnight moon!");

   mySerial.println("mode /m \r\n");
    if (mySerial.available())
    Serial.println((char)mySerial.read());
    
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
}

void loop() // run over and over
{    
 mySerial.println("init \r\n");
 if (mySerial.available())
    Serial.println((char)mySerial.read());
    
  mySerial.println("fcreate test.txt \r\n");
  if (mySerial.available())
    Serial.println((char)mySerial.read());
 
}

thanks
stefano

* SD_UserManual.pdf (799.28 KB - downloaded 10 times.)
« Last Edit: August 23, 2012, 01:08:53 pm by stefa24 » Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You start by trying read and write to/from mySerial before the mySerial.begin().

Code:
   mySerial.println("mode /m \r\n");
    if (mySerial.available())
    Serial.println((char)mySerial.read());
   
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

Then you repeatedly initialise the card and open a new zero byte file.

Code:
void loop() // run over and over
{   
 mySerial.println("init \r\n");
 if (mySerial.available())
    Serial.println((char)mySerial.read());
   
  mySerial.println("fcreate test.txt \r\n");
  if (mySerial.available())
    Serial.println((char)mySerial.read());
 
}

I'll assume you have the card reader connected correctly to pins 2 and 3, and that the 5v and ground connections are correct. What are you getting back, if anything, in the serial monitor?

You do have the card formatted as fat16?
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
You start by trying read and write to/from mySerial before the mySerial.begin().
ops

Code:
I'll assume you have the card reader connected correctly to pins 2 and 3, and that the 5v and ground connections are correct. What are you getting back, if anything, in the serial monitor?

yes card reader connected correctly this is the new sketch
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2,3);

void setup() 
{
  Serial.begin(9600);  // set the data rate for the Serial port
    mySerial.begin(9600);  // set the data rate for the SoftwareSerial port
  delay(50);
  Serial.println("Goodnight moon!");

   mySerial.println("mode /m \r\n");
   delay(50);
    if (mySerial.available())
    {
    Serial.println(mySerial.read());
    }
}

void loop()
{   
 mySerial.println("init\r\n");
 delay(50);
 
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  } 
 
  mySerial.println("fcreate test3.txt\r\n");
  delay(50);
 
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }
 
  while(true){}
}

test3.txt is created and this is the output

Code:
Goodnight moon!
53
189
145
149
233
129
106
26
170
133
52
171
11
139
171
11
82
171
107
215
87
214
86
86
82
72
248
49
69
50
48

have you any idea?

thanks
stefano
Logged


Leeds, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
while(mySerial.available())
  {
    Serial.println(mySerial.read());
  } 
 
  mySerial.println("fcreate test3.txt\r\n");
  delay(50);

With this code you are sending "fcreate test3.txt" for every character recieved over mySerial. Is this really what you want to do?

Code:
while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }
 

You then exit the first loop when mySerial.available() returns false and enter try and enter the second loop above expecting mySerial.available() to return something different.

Can you explain what you are tyring to achieve, then maybe someone will be able to give you more helpful advice?
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
I want read end write a SD card with serial communication, arduino use SPI only, see file attachment

this is the sketch
Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(5,4);// pin 5 RX pin 4 TX
#include <String.h>

void setup() 
{
  Serial.begin(9600);  // set the data rate for the Serial port
    mySerial.begin(9600);  // set the data rate for the SoftwareSerial port
  delay(50);
  Serial.println("Goodnight moon!");
/*
mySerial.print("baud 9600 \r\n");
   delay(50);
    if (mySerial.available())
    {
    Serial.println(mySerial.read());
    }
    */
   mySerial.println("mode /m");
   delay(50);
    while (mySerial.available())
    {
    Serial.println(mySerial.read());
    }
   mySerial.println("init");
 delay(50);
 
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  } 
}
 


void loop()

  mySerial.print("fcreate test.txt\r\n");
  delay(50);
 
 while(mySerial.available())
  {
    Serial.println(mySerial.read());
  }
 
  while(true){}
}

and this is the output

Code:
Goodnight moon!
62
77
111
100
101
58
32
77
67
85
40
115
105
109
112
108
101
32
109
101
115
115
97
103
101
41
13
10
79
79

test.txt file is created but the output not match output datasheet

stefano

* SD_UserManual.pdf (799.28 KB - downloaded 9 times.)
Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you convert the ascii output to characters, it looks quite reasonable:
Code:
62 >
 77 M
111 o
100 d
101 e
 58 :
 32 <space>
 77 M
 67 C
 85 U
 40 (
115 s
105 i
109 m
112 p
108 l
101 e
 32 <space>
109 m
101 e
115 s
115 s
 97 a
103 g
101 e
 41 )
 13 <carriage return>
 10 <line feed>
 79 O
 79 O

Quote
test.txt file is created but the output not match output datasheet

Not sure what you mean by that.
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
from datasheet
Code:
mode /m
>Mode: MCU(simple message)init

my output is
Code:
Goodnight moon!
>Mode: MCU(simple message)
OO
 

init output is missing?

stefano

Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A capital O indicates that a command was successful. A return of 'O' from your init and fcreate calls seems ok.
Logged

piacenza
Offline Offline
God Member
*****
Karma: 0
Posts: 589
prima della pazzia c'è la passione
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
Code:
A capital O indicates that a command was successful. A return of 'O' from your init and fcreate calls seems ok.

ok knew

this is the new sketch
Code:
#include <SoftwareSerial.h>
SoftwareSerial sdSerial(5,4);// pin 5 RX pin 4 TX
#include <String.h>
char incoming_char=0;
int dato;
String datostringa,scrivistringa;

void setup() 
{
  Serial.begin(9600);  // set the data rate for the Serial port
    sdSerial.begin(9600);  // set the data rate for the SoftwareSerial port
  delay(50);//pausa
  Serial.println("SD start operation");

  Serial.println("mode");  //set mode
   sdSerial.print("mode /m \r\n");
   delay(100);
    while (sdSerial.available())  //check response
    {
    Serial.print(char(sdSerial.read()));    //print response
       }
  Serial.println();  //empty line
 
  Serial.println("init");  //set init
   sdSerial.print("init \r\n");
   delay(100);
  while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    }
 Serial.println();  //empty line
 
 Serial.println("create file");
 sdSerial.print("fcreate test.txt\r\n");
 delay(100);
  while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    }
  Serial.println();  //empty line
 
 Serial.println("write file first time");
sdSerial.print("fputs test.txt /w temp \r\n");
  delay(100);
 while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    delay(50);
  }
Serial.println();  //empty line 
}
 
void loop()
{
 
  for(dato=1;dato<=10;dato++)
 {
   datostring=String(dato);
   
 sdSerial.print("fputs test.txt /a "+datostring+" \r\n");
 
 delay(100);
 while(sdSerial.available())  //check response
  {
    Serial.print(char(sdSerial.read()));  //print response
    delay(50);
  }
Serial.println();  //empty line 
 }
 Serial.println("end write");
 while(true){}
}

now it work, then I can to continue with my datalogger

tanks dxw00d

stefano
Logged


Pages: [1] 2   Go Up
Jump to: