![]() In this application the I2C SD-Card Module is the Client, and the microcontroller that's accessing it via I2C is the Host. However, the Host registers still have an "M" prefix, and the Client registers have an "S" prefix, so you need to keep both terminologies in mind! While reading Microchip's latest datasheets I noticed that they've changed their terminology to Host (rather than Master), and Client (rather than Slave), so I'll adopt the new terminology. Implementing this project was an interesting exercise in getting to understand the TWI peripheral in the new AVR processors. Arduino Wire uses a 32-byte buffer, so you have to divide up what you're writing into sections of not more than 32 bytes: Serial.println("Writing.") įor (int i=0 i<32 i++) Serial.print((char)Wire.read()) įor (int i=0 ican use the I2C SD-Card Module with the Arduino Wire library, but it works best with my TinyI2C library see Tiny I2C Routines for all AVR Microcontrollers. There is no need to explicitly close the file when you're finished it is closed automatically after the last transmission. The Size command can be called before reading a file if you don't know its size. Writes data to the file, overwriting if necessary.Īppends data to the end of the file, if it already exists. To make it easy to remember them I made each command a single letter representing its action: Command ![]() CommandsÄ®ach I2C transaction is prefixed by a command byte, to indicate what function is being performed. The I2C address is 0x55, but if this clashes with anything else you're using you can easily change it in the program. It's a useful module to have lying around, so I plan to design a PCB for it if I do I'll publish it here. To use it just connect it to your 3.3V or 5V microcontroller via the following pins: The whole circuit fitted on a mini breadboard. You could connect this to a spare I/O line defined with INPUT_PULLUP to allow you to detect when a card is present. The SD card module includes a CD pin which is connected to GND when a card is not inserted. Alternatively you could use two separate LEDs. I connected a bicolour red/green LED to two spare I/O lines, PB2 and PB3, to allow me to show errors (red) and when the SD card is being read or written (green). I mounted the chip on a SOIC-14 breakout board to make it breadboard friendly. I'm pretty sure an ATtiny1624 should work, but I haven't tried it. I also tried an ATtiny1604, but that didn't work, presumably because the 1 Kbytes of RAM doesn't leave enough room for the stack. The SD library uses a lot of RAM so you need about 830 bytes, and the ATtiny804 or ATtiny814 aren't suitable as they only have 512 bytes. ![]() The circuitĬircuit of the I2C SD-Card Module, based on an ATtiny1614.įor the SD card interface I used the Adafruit MicroSD board as it's easy to use on a breadboard, and it includes a logic-level shifter so you can use it with 3.3V or 5V.įor the controller I used an ATtiny1614. I therefore switched to the 1âseries ATtiny1614 which provides 2 Kbytes. I initially thought of basing the circuit on the ATtiny841, like my earlier I2C GPS Module, but I underestimated the amount of RAM needed by the SD library, and the ATtiny814 only provides 512 bytes. The ideal solution seemed to be an SD module with an I2C interface, but despite much searching on the web I couldn't find one, so I decided to build one myself. I've frequently had a project where I wanted to write data to an SD card, or read from an SD card, but didn't have enough I/O lines available to wire up the SPI SD card interface, or else the SPI lines were already in use, or else the processor I was using didn't have enough RAM to run the SD library. It's based on an ATtiny1614 and a few other components, and it's compact enough to fit on a mini-breadboard.įor a PCB version of this project see I2C SD-Card Module PCB. This is an SD-card module that allows you to write to and read from files on an SD card using a two-wire I2C interface:Īn I2C SD-Card Module that allows you to write to and read from SD cards via I2C.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |