Announcement

Collapse
No announcement yet.

IoD SD card access issues

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • IoD SD card access issues

    Hi.. I'm just trying to write/read this binary array to/from the SD card. It does create the file but it is always 00s.. ?

    any ideas?

    long ZoneInfo[32][6];

    void readSD(void)
    {
    gfx.TWprintln("SD Setup");

    myFile = SD.open("ZONEINFO.ADI", FILE_READ);
    if (myFile.available())
    {
    gfx.TWprintln("SD Open");
    myFile.read((uint8_t *)&ZoneInfo, sizeof(ZoneInfo));
    gfx.TWprintln("SD Read");
    myFile.close();
    gfx.TWprintln("SD Closed");
    }else
    {
    gfx.println("File open error"); //test

    }
    delay(2000);
    }

    void writeSD(void)
    {
    gfx.TWprintln("SD Open");
    myFile = SD.open("ZONEINFO.ADI", FILE_WRITE);
    if(myFile)
    {
    gfx.TWprintln("SD Write");
    myFile.write((byte *)&ZoneInfo, sizeof(ZoneInfo));
    myFile.close();
    gfx.TWprintln("SD Closed");
    }else
    {
    gfx.TWprintln("Close error");

    }
    delay(2000);
    }


  • #2
    Hi,

    I think this is due to the way the data is being written the SD card.

    I am not familiar with this method of casting of a long value into a byte.

    I have modified your code to the way I do it.

    void readSD(void)
    {
    gfx.TWprintln("SD Setup");

    myFile = SD.open("ZONEINFO.ADI", FILE_READ);
    if (myFile.available())
    {
    gfx.TWprintln("SD Open");
    for(int x = 0; x < 32; x ++){
    for(int y = 0; y < 6; y++){
    ZoneInfo[x][y] = myFile.read() << 24;
    ZoneInfo[x][y] = ZoneInfo[x][y] | myFile.read() << 16;
    ZoneInfo[x][y] = ZoneInfo[x][y] | myFile.read() << 8;
    ZoneInfo[x][y] = ZoneInfo[x][y] | myFile.read();
    }
    }

    gfx.TWprintln("SD Read");
    myFile.close();
    gfx.TWprintln("SD Closed");
    }else
    {
    gfx.println("File open error"); //test

    }
    delay(2000);
    }

    void writeSD(void)
    {
    gfx.TWprintln("SD Open");
    if(SD.exists("ZONEINFO.ADI")) SD.remove("ZONEINFO.ADI");
    myFile = SD.open("ZONEINFO.ADI", FILE_WRITE);
    if(myFile)
    {
    gfx.TWprintln("SD Write");
    for(int x = 0; x < 32; x ++){
    for(int y = 0; y < 6; y++){
    myFile.write((ZoneInfo[x][y] >> 24) & 0xFF);
    myFile.write((ZoneInfo[x][y] >> 16) & 0xFF);
    myFile.write((ZoneInfo[x][y] >> 8) & 0xFF);
    myFile.write(ZoneInfo[x][y] & 0xFF);
    }
    }
    myFile.close();
    gfx.TWprintln("SD Closed");
    }else
    {
    gfx.TWprintln("Close error");

    }
    delay(2000);
    }

    There are other ways of doing this with less code but I have left it like this for clarity.

    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      That worked..thanks Paul.

      Comment

      Working...
      X