micro sdcard spi with ATmega32

Go To Last Post
30 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want to communicate with a micro sdcard with an ATmega32 using SPI. i make a simple spi loopback and works fine. now, how can i communicate with micro sdcard to write and read simple bytes or strings?

how can i use fatfs?

Last Edited: Wed. Nov 29, 2017 - 11:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have a look here, at Elm Chan's FatFs software.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note also that the Fatfs that JC links to is used widely by a lot of us here and you will find a lot of previous threads about it. Start in the "Tutorial Forum" and read any threads that mention "FatFs". It's actually relatively painless and simple to set up and get working.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Note also that the Fatfs that JC links to is used widely by a lot of us here and you will find a lot of previous threads about it.

Not just here, and not just for AVRs!

 

FatFs is very widely used for just about all makes of microcontrollers - and there are myriad examples, tutorials, etc to be found all over the interwebs.

 

http://www.lmgtfy.com?q=SD+Card+Microcontroller

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Dec 16, 2014 - 12:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FATFS is very widely for me, i didnt using something like this before.

i want something light to begin.

i was looking a lot tutorials which using some commands, but i dont understant that commands.

like this

https://dcodelab.wordpress.com/2...

how can i perform a simple command?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i think that i didn't succed initialize cs pin.

it must be defined as output in DDRB? on atmega32?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm done with cs.

now... how can i send the commands to sdcard? what's the corresponding values?

for example what byte must be sends for cmd0?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want something light to begin.

Eh? Fatfs is pricipally ONE file (ff.c) you add to your code (and one SPI driver file) - how could it be "lighter" than that? The FatFs directory does have a number of files like uart.* and so on but most do not need to be part of an actual implementation - they are just there as part of a demo/test program and can be ignored.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

i want something light to begin.

Eh? Fatfs is pricipally ONE file (ff.c) you add to your code (and one SPI driver file) - how could it be "lighter" than that? The FatFs directory does have a number of files like uart.* and so on but most do not need to be part of an actual implementation - they are just there as part of a demo/test program and can be ignored.

sorry for my irrelevance. it's my first program with SDcard.

my SPI code, seems to works perfectly. only i've done it's a SPI loopback. I know how spi works and how spi code works.

I'm confused about SD card interface.What's way its simplest? with FATFS? or with CMD commands?

if i select FATFS only what i need it's a ff.c?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm trying to play with "avr_foolproof" Download: FatFs sample projects for various platforms 

from

http://elm-chan.org/fsw/ff/00ind...

but i think there's different spi pins from my atmega32

 

EDIT: It doesn't work with SPI, it use GPIO pins.

How can i add spi interface?

Last Edited: Wed. Dec 17, 2014 - 05:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can you help me to merge SPI and FATFS?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.avrfreaks.net/comment...

https://www.avrfreaks.net/forum/a...

https://www.avrfreaks.net/forum/a...

https://www.avrfreaks.net/forum/x...

 

Summary:  There is a bit of configuration work to integrate fatfs into a particular AVR8 app, including setting up the SPI properly, updating the SPI primitive calls in fatfs if needed, setting up the timer call, and handling disk present and write protect in >>your<< particular configuration. (Along with actually configuring which facilities you need in your app...)

 

Cliff's Tutorial thread should lead you through it.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

is there some "plug & play' library with FATFS and SPI like avr_foolproof? simply for use.

I am using Atmel Studio 6.2

Last Edited: Wed. Dec 17, 2014 - 08:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does kubark42, and follow-ons by Cliff and others, say in the tutorial?

 

After the section on getting files, there is discussion about the 10ms. timer tick.  >>You<< have to provide that tick.  >>You<< have to adapt for your clock speed, and toolchain, and timer used, and similar.

 

Then there is a discussion about SPI setup in mmc.c.  >>You<< have to adjust for the AVR model that >>you<< are using, and >>your<< SPI setup and speed and similar.

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you really need something with little new programming involved, perhaps you should live in the Arduino world?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have download the ffexample of clawson and i'm trying to get it work with my atmega32.

i want something quicly for now :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want something quicly for now :(

Did you go through the tutorial?

 

"ffexample of clawson" -- ??  I wasn't aware he posted files.  So, if you want to use that, connect to the same AVR model with the same connections and the same clock speed.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

iam using atmega32 in 14.7456mhz crystal and im using microsd card module from ebay.

my connections:

module - atmega32

cs - > cs

sck -> sck

mosi -> mosi

miso -> miso

Vcc -> 5v

GND -> GND

 

my card is sandisk 8gb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it doesnt work :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hope you have level translators between the ATmega32 and the SD card socket.  Even with that I had to reduce the SPI speed to get the card initialised.

 

In DSTATUS disk_initialize(BYTE drv)

I added

// set SPI speed lower until it works, F_CPU/32 = 115kHz with a 3.6864MHz xtal
   SPSR |= (1<<SPI2X);
   SPCR |= (1<<SPR1);

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my module has already built in level translator. and it gets 5v supply with 5v signal level of spi.

my crystal its 14.7456mhz.

i dont have any other crystal. Can i have something with this crystal?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just buy an Arduino UNO and any Shield that has a microSD card socket.

 

There are many examples and they should all work straight out of the box.

 

You could even connect your Ebay module to the Arduino.    However,  that would require you to read the pin numbers printed on the UNO and read the terminal names on your Ebay module.     I am not sure whether your attention span would last that long.

 

Ask for some help from a friend that lives locally.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Late to this but "foolproof" is partly foolproof in the sense "does not even require SPI" (because it bit-bangs SPI on IO pins). If you want the best performance you can get and use an AVR with SPI then do NOT use "foolproof".

 

(things were much simpler before that was added to the download so it seems to have failed to offer "foolproof"!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Im building a prototype in breadboard with atmega32. And I have to add sdcard. I think that module from ebay works with 5v. Theres built in level translator. I will try to setup the code in proteus.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my module has already built in level translator. and it gets 5v supply with 5v signal level of spi.

...

I think that module from ebay works with 5v.

So give us a link to this eBay module that gets power from SPI.  (That sounds strange.)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it takes 5V power supply and it can connect directly in SPI bus without translator.

http://www.ebay.com/itm/27149677...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can i setup the "cawson example" to work with 14.7456 mhz crystal?

my board has:

atmega32 with 14.7456mhz.

ftdi in uart lines.

i'm loading the project to my mcu via ISP (stk500) and it doesnt work.

ps: debuging(uart) doesnt work too

ftdi works perfectly in one other project which i build.

 

EDIT: also my board includes a module I2C to 8bit for a LCD 2x16 HD447800, from ebay, and works perfectly too.

my micro sdcard its a sandisk Ultra 8GB microsd HC1 class 10

 

Last Edited: Thu. Dec 18, 2014 - 05:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i use serial port with putty 115200bps

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how can i redefine F_CPU at my freq?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FFS do not cross post! I just answered about F_CPU on the end of the FatFs tutorial thread where you cross posted. 

Topic locked