1

An application of ATtiny with SD card is complicated due to missing of hardware SPI in attiny. The "ATmega" code for creating of a "SD file" is:

#include <SPI.h>                                
#include <SD.h>

File file;                                     
int const pinCS = 2;

void setup()
 
{
SD.begin(pinCS);                               
file = SD.open("Test.txt", FILE_WRITE);        
file.println("anything");                     
file.close();}                                

void loop()                                     
{}  

This code creates on SD card a file "Test.txt" and to this file records text "anathing". Is it possible to rewrite this code for "ATtiny85"?

1

The ATtiny85 has no dedicated SPI port. It has, however, an “USI” port (Universal Serial Interface) that should be able to do the job. The lack of SPI should not be a problem, but the lack of memory will be a problem.

Files on an SD card are written one sector (512 bytes) at a time. For this reason, the SD library uses a 512 bytes buffer in RAM. That cannot work on an ATtiny85, as the buffer would consume the whole RAM.

You may be able to do something using the Petit FAT library, provided you can work around the severe limitations of its write interface:

The write function has some restrictions listed below:

  • Cannot create file. Only existing file can be written.
  • Cannot expand file size.
  • Cannot update time stamp of the file.
  • Write operation can start/stop on the sector boundary only.
  • Read-only attribute of the file cannot block write operation.

The first two points imply that you would have to create the file and allocate the sectors for it in your computer.

This blog post mentions a port of the library to the Arduino environment, and its use on an ATtiny84, which has similar capabilities to the ATtiny85 (only with more pins).

1
  • Thank you of this relevant response. No problem, ATmega operates good in this connection, but ....attiny is smaller and sympatric. It is pity, the limitations of the "Petit.." is problem. Thank You. – Josef Dec 8 '20 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.