Coder Social home page Coder Social logo

Comments (6)

greiman avatar greiman commented on July 25, 2024

I can't help you write apps, too many people ask.

If you find a bug, isolate the bug in your app and post a simple example that demonstrates the bug.

from sdfat-beta.

Sebastiangka avatar Sebastiangka commented on July 25, 2024

In the picture bellow you can see what it comes out after running the example program bench with some modifications.
image
here is the code i added to represent in a simple way my case.

.
.
.
struct sample{
  float x; float y;
  };
sample lino[BUF_SIZE];
sample* pl = lino;
.
.
.
  // fill buf with known data
  if (BUF_SIZE > 1) {
    for (size_t i = 0; i < (BUF_SIZE - 2); i++) {
      buf[i] = 'A' + (i % 26);
      pl[i].x = esp_random();
      Serial.print(pl[i].x);
      Serial.print('\t');
      pl[i].y = esp_random();
      Serial.println(pl[i].y);
    }
    buf[BUF_SIZE-2] = '\r';
    pl[BUF_SIZE-2].x = 0.0;
    pl[BUF_SIZE-2].y = 0.0;
  }
  buf[BUF_SIZE-1] = '\n';
  pl[BUF_SIZE-1].x = 0.0;
  pl[BUF_SIZE-1].y = 0.0;
.
.
.
      if (file.write(pl, BUF_SIZE) != BUF_SIZE) {
        error("write failed");
      }
.
.
.

The size from the bench file is correct:
image

I would like to know if there is a special reason why you define buf as a uint_8 pointer and cast buffer32 into an uint8_t? And which would be the consecuences in the spi performance if i defined as an struct

from sdfat-beta.

Sebastiangka avatar Sebastiangka commented on July 25, 2024

I toked a look at the FatFile write function, then I had to inform my self about "reinterpret_cast conversion" and so far as I understand it works only for integers and pointers. As you defined in write-function, buf is void* pointer type and it will be casted direct at the beginning.

const uint8_t* src = reinterpret_cast<const uint8_t*>(buf);

I would like to know how to work with different variables types like float and struct, in order to write them in the Sd-Card. Or if its actually possible to work with them.
Thanks for your time

from sdfat-beta.

greiman avatar greiman commented on July 25, 2024
if (file.write(pl, BUF_SIZE) != BUF_SIZE) {
        error("write failed");
      }

The size of pl is not BUF_SIZE bytes. It is sizeof(pl) so you are only writing a portion of the array.

Casting a variable will not result in a text file.

I cast a uint32_t to uint8_t in the bench example since some processors require DMA writes to be aligned on 4-byte boundaries for maximum speed. The Teensy 4 board can write at 22 MB/sec with it's fast 4-bit wide SDHC controller.

Since my µC only has 600µs to write

This rate can't be achieved with a simple program. SD cards can have write latency times of many milliseconds so you must acquire and buffer data to write at this speed. This may require data acquisition in an interrupt routine or a RTOS.

It may not be possible with your board since it is slow for SPI writes.

from sdfat-beta.

Sebastiangka avatar Sebastiangka commented on July 25, 2024

This may require data acquisition in an interrupt routine or a RTOS.>

That´s my plan. I use a time interrupt to check the values from my sensor, this happen every 1ms and it´s needs ~350µs to read the values. So every 1ms it will be a new sample to my array, is the array full then should be copied in the Sd.

I would be satisfied if I get at least the right values in the Sd, then i would work on the timing problem.

from sdfat-beta.

greiman avatar greiman commented on July 25, 2024

You must fix your bugs. You are not writing the correct amount of data to the SD. The data is written as binary, not text.

I am closing this since I don't have time to tutor C++ programming.

from sdfat-beta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.