// ATmega8 data logger with FAT32

This post describes very simple SDcard data logger I've made recently. It can be used to log NMEA datagrams from GPS receiver, or any other serial half-duplex streams. With TTL serial input it can also be used to intercept transmission between any devices with UART.

One of preliminary guidelines was to make use of remaining parts after previous projects. That was the reason to use 8KB flash ATmega8. Now I know it was a bad choice, because it's very hard to fit FAT read/write filesystem without using assembler and keep space for the rest of logic. Due to limited amount of flash memory functionality was truncated to creating and writing files on SD card. Nevertheless, the key features are:

  • SD/SDHC flash support,
  • FAT32 support,
  • autoincremented file names,
  • interrupt driven data receiving,
  • double data buffering, to ensure reliable data acquisition during SD writes and to avoid wearing out SD card,
  • autoincrementing file names (LOG00000.TXT, LOG00001.TXT, …).


Major guidelines were:

  • low power,
  • easy connection to Holux GPSlim 236 receiver - parasite power supply from receiver's battery,
  • supply from GPS receiver or from USB charger, ability to charge receiver during logging,
  • microSD socket for memory.

Device uses ATmega8A and a few passive and electromechanical components. MicroSD socket is chosen to ensure possibility to read files from card using a smartphone, when away from home. According to the user manual of my GPS receiver, it provides 3.6V/100mA output on USB connector, so data logger is able to be powered from receiver. When PCB has been finished and assembled, it turned out, that there is no power supply on USB. It seems that either user manual lies or my device is broken. I had to use separate wire to steal power.

 Data logger connected go GPS Receiver Holux GPSlim 236

 Circuit diagram



It was one-weekend project, so I've been considering using ready-made tiny stacks like Elm's Petit FAT, Dharmani's FAT32 implementation and Elm's FatFs.

The latter two exceeded 8KB. So I've rejected it in first pass.

Petit FAT looked promising, but had a serious limitation - can write only to allocated parts of existing files and doesn't support writing on end of file1), so it definitely doesn't meet requirements.

After few tries with mangling with #defines to fit binary into 8KB, it seems unavoidable to make some cuts on FatFs's code. Apart from disabling all of built-in #define controlled parts of code, I've removed FAT12 and long file names support, cut reading file, directory listing. There is no support for file permissions and attributes. Only one card and file can be opened. But growing of file during writing is fully supported, till 2GB - FAT32's limitation.



No. 1 @ 03-03-2014 14:19

Kombajn loguje „wszystko” co dostanie rs-em czy jakos parsuje dane? Innymi słowy - czy jak mu podam np odczyty z termometru, alkomatu, górnopłuka, to czy stabelaryzuje mi je czy poupychac je w jakis gpsopodobny format? Albo inny model gps- jakie szanse ze zabangla?

No. 2 @ 03-03-2014 14:52

@bujnos: Wszystko jak leci, zapisuje do pliku tekstowego. Mogą też być dane binarne. Gdyby danych było bardzo dużo non-stop potencjalnie istnieje ryzyko, że bufory się przepełnią, ale NMEA w gpsach loguje z dużymi przerwami i nigdy się mi tak nie zdarzyło.

Leave a comment…

ESI If you can't read the letters on the image, download this .wav file to get them read to you.
  • E-Mail address will not be published.
  • Formatting:
    //italic//  __underlined__
    **bold**  ''preformatted''
  • Links:
    [[http://example.com|Link Text]]
  • Quotation:
    > This is a quote. Don't forget the space in front of the text: "> "
  • Code:
    <code>This is unspecific source code</code>
    <code [lang]>This is specifc [lang] code</code>
    <code php><?php echo 'example'; ?></code>
    Available: html, css, javascript, bash, cpp, …
  • Lists:
    Indent your text by two spaces and use a * for
    each unordered list item or a - for ordered ones.
Hello World!

Tomasz Głuch
Hi! I'm Tomasz Głuch, sysadmin - IT specialist and electronics enthusiast from Kraków, PL . You'll find here articles about electronics, Linux. Welcome to my site.

QR Code: URL of current page