Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pinguino micro SD card not working
17-02-2014, 10:50 AM,
#1
Pinguino micro SD card not working
Hello,
I have a Pinguino micro and Pinguino x4 IDE
I have tried the SD card examples without success.
On my board the CS pin is RF0 pin 39?
What is RB13 pin 40 #SS?
I have tried SD.mount(39) and SD.mount(40) without success.
Which file defines the SPI clk and data pins?
Thank you for any help.
Regards
Anthony
Reply
17-02-2014, 12:59 PM, (This post was last modified: 17-02-2014, 01:01 PM by moreno.)
#2
RE: Pinguino micro SD card not working
Hi

Very strange, I use the same board in a lot of industrial applications and the uSD work always very well.

Can you indicate the sample code you use??

Some working routine I use are:

Code:
#define CS_SD_PIN   40

int ReadConfigBin(char * filename,void * Buf,u16 BufSize)
{
  SD_Error err;
  SD_File file;
  u16 LenR;
  
  char Buf1[100];
  
  if (! SD.mount(CS_SD_PIN))
   return (-1);
  if ( (err = SD.open(&file, filename, FA_OPEN_EXISTING | FA_READ)) != 0)
   {
    SD.unmount();
    return (-2);
   }
  if (file.fsize < BufSize)
   {
    SD.close(&file);
    SD.unmount();
    return (-3);
   }
  err = SD.read(&file,Buf, BufSize, &LenR);
  SD.close(&file);
  SD.unmount();
  if (LenR != BufSize)
   return -4;
  if (err != 0)
   return -5;
  return (0);
}

int WriteConfigBin(char * filename,void * Buf,u16 BufSize)
{
  SD_Error err;
  SD_File file;
  u16 LenW;
  
  char Buf1[100];
  
  if (! SD.mount(CS_SD_PIN))
   return (-1);
  if ( (err = SD.open(&file, filename, FA_OPEN_ALWAYS | FA_READ | FA_WRITE)) != 0)
   {
    SD.unmount();
    return (-2);
   }
  err = SD.write(&file,Buf, BufSize, &LenW);
  SD.close(&file);
  SD.unmount();
  if (LenW != BufSize)
   return -4;
  if (err != 0)
   return -5;
  return (0);
}


Bye Bye, Moreno
Reply
23-02-2014, 02:56 AM, (This post was last modified: 23-02-2014, 02:59 AM by santira.)
#3
RE: Pinguino micro SD card not working
Usando Pinguino Micro - Pinguino X4 // Windows 8 // SD 1GB
Me funcionó lo siguiente:

Code:
/*-----------------------------------------------------
Author:  --<SantiagoRA>
Date: Sat Feb 22 21:11:02 2014
Description:
Primer Prueba para Grabar SD, disculpen lo desprolijo del codigo.
-----------------------------------------------------*/


int ReadConfigBin(char * filename,void * Buf,u16 BufSize)
{
  SD_Error err;
  SD_File file;
  u16 LenR;
  
  char Buf1[100];
  
  //if (! SD.mount(CS_SD_PIN))
}


#define BUFFER_SIZE 32  // Size of read buffer - arbitrary length,
                        // try changing it to improve efficiency
#define CS_SD_PIN   40
#define SDCS_PIN 40// era 8 The pin for the SD Card select line

   u16      i, lines_total, bytes_to_write, bytes_written, bytes_read;
   u32      bytes_total;
   u8       filename[]    = "data.txt";    // should include full path to file
// char     filename[]    = "LEVEL_0/datalog.csv";

   FIL      fil;                            // File object
   FRESULT  res,    rc;
   DWORD    file_size;
   u8       read_buffer[BUFFER_SIZE];

void setup()
{
}

void loop()
{
   u8  buffer[40]  = "Hola funciono Bien";    // arbitary value of 40 for length of character array //Lo modifique para que escriba eso
                              // needs to be large enough for maximum line length
   u8  temp[13]    = "";    // temporary variable used for int to char conversions
                              // needs to be large enough for maximum string length
                              // generated by sprintf() statements below
  
   /* At this point buffer contains the comma separated data terminated by a
   new line (line feed) character (and of course a NULL)                      */

   bytes_to_write = strlen(buffer);         //    number of Bytes To be Written

   SD.mount(SDCS_PIN);           //    Allocate file structure
    
/* Open existing file or new file if file does not already exist */
   res = SD.open(&fil, filename, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
   if (!res){
      file_size = fil.fsize;     // Get existing file size
      SD.seek(&fil,file_size);   // Set R/W pointer to end of file

/*    Write data to file */
      rc = SD.write(&fil, buffer, bytes_to_write, &bytes_written);        // write new data to file
      SD.flush(&fil);                                       // flush any data in cache to file
                                 // to avoid data loss from loss of power etc
                                 // only required if not closing file
      SD.close(&fil);            //    Included for safety to ensure file properly closed
      SD.unmount();              //    in case user removes card instead of proceeding.
}                                                                
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)