SDIO and SPI peripheral on AVR?

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

Guys,

Can I use the same SDcard for SDIO and SPI ?
Does anyone know which AVR can support SDIO ?

Any ideas or experiences will be appreciated,

Thanks

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

Quote:

Does anyone know which AVR can support SDIO ?

No AVR8 (tiny, mega, xmega) has SDIO so for SD/MMC you must always use SPI(*). I think some of the 32bit AVR32 chips have SDIO.

(*) 99 out of 100 people using SD/MMC on AVR8 use FatFs:

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

The mmc.c file has the necessary code to use SPI with SD/MMC.

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

Do I need a different SDcard, and module ?
SDIO/SPI
http://www.aliexpress.com/item/Free-Shipping-1pc-Micro-SD-and-TF-Card-Module-SPI-SDIO-Dual-mode-driver-3-3V/1262085850.html

I have one module but it's SPI, is it possible for me using it as SDIO ?

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

Whether it is spi or sdio is up to you. The pcb does very little apart from put the connector out to pins. You can program the avr to do sdio, but with the avr hardware, spi is faster.

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

Referring again to FatFs, read this:

http://elm-chan.org/docs/mmc/mmc...

In the second picture down it shows how the pins connect to SPI. So in your module ignore the pins labelled D1 and D2.

You would connected 3.3V to your AVR Vcc (hope it's is 3.3V!). Gnd to your AVR Gnd. D0 to the MISO pin on your AVR's SPI interface. CMD to the MOSI pin of your AVR's SPI. CLK to the SCK pin of your AVR's SPI. D3 to the _SS pin of your AVR's SPI.

Quote:

is it possible for me using it as SDIO ?

Are you ignoring the answers you are being given? I already told you that if you use an AVR8 (and I believe you have mega128?) then you cannot use SDIO mode. You can only connect the card in MMC mode using the SPI interface of the m128.

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

Quote:

can I use this module for SDIO ?

No, no, no.

You own an AVR8. It cannot do SDIO. But, yes, that module can be connected to the SPI of the mega128 to use the SD/MMC card in MMC(SPI) mode.

BTW I just noticed that ebay page even has this picture:

That actually shows you the AVR pins to use in the right most column of silk screen printing.

Personally I use this one:

http://www.futurlec.com/Mini_SC....

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

bianchi77 wrote:
Does anyone know which AVR can support SDIO ?
In AVR32 as UC3A3 and UC3A4.
Also a lot of SAM3 and SAM4 ...
by Atmel, Microcontrollers Selector.

"Dare to be naïve." - Buckminster Fuller

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

I sort of wonder why you have the insistence on using SDIO when most of using SD/MMC get along quite nicely with MMC. Do you think the read/write data rate will not be high enough using the single bit interface? If that's true then, yes, you probably need to think about moving to a higher spec CPU because not only will it deliver the SDIO you crave but will have a higher bandwidth to be able to keep the pipe full.

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

Both your Ebay module and Cliff's ETT module require 3.3V CPU. You will destroy MMC cards if you use 5V.

As far as I can see, the resistors and 3.3V regulator on the Ebay module are pants.

David.

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

SDIO pin out :
I'll connect the same pins only different name, won't I ?

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

Different name and function.

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

but I connect to the same pins on SD card ?

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

Did you read my post:

Quote:

You would connected 3.3V to your AVR Vcc (hope it's is 3.3V!). Gnd to your AVR Gnd. D0 to the MISO pin on your AVR's SPI interface. CMD to the MOSI pin of your AVR's SPI. CLK to the SCK pin of your AVR's SPI. D3 to the _SS pin of your AVR's SPI.

Which bit of that did you not understand?

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

I got it...thanks

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

But SDIO means "using something else than memory card on SD card slot", like wireless or camera modules are SDIO devices. You can still talk to SDIO devices with either SPI bus or the native SD bus.

Anyway, with an 8-bit AVR, whether you talk to SD memory card or SDIO wireless device, you really are limited to use the SPI bus as 8-bit AVRs do not have 4-bit or 1-bit SD bus controller.

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

Ok,

I have these init in one application :
inside msd.c

/*******************************************************************************
* Function Name  : SPI_Config
* Description    : Initializes the SPI1 and CS pins.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_Config(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
  SPI_InitTypeDef   SPI_InitStructure;

  /* GPIOA and GPIOC Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
  /* SPI1 Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

  /* Configure SPI1 pins: SCK, MISO and MOSI */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure PC12 pin: CS pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* SPI1 Config */
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI_InitStructure);

  /* SPI1 enable */
  SPI_Cmd(SPI1, ENABLE);
}

inside sdcard.c

/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configures the SDIO Corresponding GPIO Ports
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void GPIO_Configuration(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /* GPIOC and GPIOD Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);

  /* Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* Configure PD.02 CMD line */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
}

Does it mean I can use both interface (SPI and SDIO) with this application ?

Thanks

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

What exactly do you want to do? We're confused.

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

What exactly do you want to do? We're confused

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

What exactly do you want to do? We're confused

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

I want to use either SPI or SDIO, and confused because I see two initialization in one application....

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

What exactly do you want to do? We're confused

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

It doesn't look like AVR. Do you want us to guess?

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

it's not avr but may be you guys have a knowledge on SDIO and SPI ? and if it's possible I want to put it in AVR too...

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

Have you not read and understood what you have been told previously? Why the rabid interest in sdio when the AVR does not have the hardware to support the native 4 bit mode? Whilst you could have the AVR bitbash the 4 bit mode, there is no performance advantage.

Tell us your end goal rather than asking obscure questions clouded by your lack of knowlege. Only then can we understand what you want

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

bianchi77 wrote:
it's not avr but may be you guys have a knowledge on SDIO and SPI ? and if it's possible I want to put it in AVR too...

How about you drop this code/application which has two initializations and come up with your own code? Read this
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=66846
and this
http://www.frank-zhao.com/cache/fat_sd.php

The above mentioned links will help you interface SD card with avr in SPI mode. Normally everybody uses SPI to interact with the card.

p.s do read the last 5 pages of tutorial because the first post is outdated.

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

Quote:
Ok,

I have these init in one application

That is ARM code which you posted, and why do you bother with AVR if you have an ARM...or maybe you don't have 1 and post ARM code because... :roll: Why do people keep repeating to the OP that SDIO mode isn't possible with AVRs when he's just not listening ?! Once or twice I can see but uh...wow.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

We don't know if the ARM in question has SD bus controller or uses SPI bus controller to communicate. It is not clear from the init routines. Looks like Cortex-M3 code to me.

And still SDIO devices have nothing to do with bus!

You can still use the native SD bus or SPI bus to talk to either regular SD memory cards or special SDIO devices like cameras!

For the last time: an 8-bit AVR does not have SD bus controller, it only has SPI bus controller. You can talk to SD memory cards or to SDIO devices but you are limited to using SPI bus!

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

I've moved this thread to General Electronics as it's clear now that it has nothing to do with AVR but I'm still a little puzzled about how the word "AVR" made it's way in to the thread title in that case? Is there an AVR involved in this somewhere? And to be clear is it an AVR8 or an AVR32? If the latter (which can appear to be very ARM like in the code that you use) then I can move this on to an appropriate AVR32 forum.

Moderator.

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

Quote:
We don't know if the ARM in question has SD bus controller or uses SPI bus controller to communicate. It is not clear from the init routines.

The sdcard.c file is showing a partial setup for the ARM's 4 bit SD mode I/F, based on this:
/* Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; 

This indicates it has an SD I/F.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

and I saw :

/*******************************************************************************
* Function Name  : SPI_Config
* Description    : Initializes the SPI1 and CS pins.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void SPI_Config(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
  SPI_InitTypeDef   SPI_InitStructure;

  /* GPIOA and GPIOC Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC, ENABLE);
  /* SPI1 Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

  /* Configure SPI1 pins: SCK, MISO and MOSI */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure PC12 pin: CS pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* SPI1 Config */
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI1, &SPI_InitStructure);

  /* SPI1 enable */
  SPI_Cmd(SPI1, ENABLE);
}

which is SPI, my question is, does this application have an ability on both interfaces ?

Cheers

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

it's on msd.c and originally from :
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/23342/STM32F10xUSBLib_V2.2.1.zip

Thanks guys and have a good weekend....

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

Without looking deeply at the code, one could assume the following:

Maybe it does support sdcards via the native and spi interfaces?
It might have spi to support a serial flash device?

So how do these answers help you?
For the stm32, the sdio and spi are separate interfaces.

If you use a fat filesystem like FatFS, it really doesn't care what the interface to the storage device is. If you look at the sample code for the stm32f4, there is an example where the usb host is used to talk to a usb mem stick.

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

Thank you,

I used this config

void SD_LowLevel_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /*!< GPIOC and GPIOD Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);

  /*!< Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /*!< Configure PD.02 CMD line */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /*!< Configure SD_CD pin: SD Card detect pin */
  GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);
  
  /*!< Enable the SDIO AHB Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE);

  /*!< Enable the DMA2 Clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
}

Window 7 can detect the reader already but can't detect the card yet...
any ideas ?
thanks

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

is it because of the voltage on SDcard pin ? it's 3.8V there...
I'm using microSD that doesn't have pin 9, may be that's the cause ?
thanks

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

I have no idea of what you are talking about. Are we to assume you are using a stm32 part now instead of an avr?

As for exactly what you're trying to do -you really havent told us. You assume we have magical powers of deduction.

As for stm32, i had no trouble getting a micro sd working on a stm32f4 discovery board.

3.8V does not sound good - should be 3.3V

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

I'm trying to use
https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/23342/STM32F10xUSBLib_V2.2.1.zip

I got windows 7 detect my board already, but I haven't got any signal from sdcard, I test it from my logic analyzer, I can only see SCK and USB disconnect, but other signal is nothing....

Could it be a wrong connection on port ?
I fix 3.8V issue already, wrong pull up resistor position.

I followed this config :
Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK
I built myself my own SDcard module with all pins out on header and 3.3V PSU
STM32 --> SD card
PC8 ---> pin7
PC9 ---> pin8
PC10 ---> pin9
PC11 ---> pin5
PD2 ---> pin2

Any missing pins here ?

thanks

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

Where is CMD?

I've wasted enough time on this thread so i'm not going to bother doing the research you can easily do.

Next time, don't say AVR in the tiltle if you're not using an AVR. How are we supposed to know you are using a stm32 when you don't tell us apart from posting oscure snippets of code and zip files most of us will not bother to read ( my ipad wont). You've been pulled up a number of times by me and others here, so your actions are bordering on abusive.