ATmega328 and SD cards

Greetings,

I have an Arduino Deumilanove with the ATmega328. I picked up a SD card break out from spark fun and proceeded to follow the directions found at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649

The problems I’m having is with getting the code to compile.
I download the source from the link above. (SDcard.zip)

sd_raw_config.h doesn’t have a definition for AVR_ATmega328P

#elif defined(AVR_ATmega64) ||
defined(AVR_ATmega128) ||
defined(AVR_ATmega169)
#define configure_pin_mosi() DDRB |= (1 << DDB2)
#define configure_pin_sck() DDRB |= (1 << DDB1)
#define configure_pin_ss() DDRB |= (1 << DDB0)
#define configure_pin_miso() DDRB &= ~(1 << DDB3)

#define select_card() PORTB &= ~(1 << PB0)
#define unselect_card() PORTB |= (1 << PB0)

#else
#error “no sd/mmc pin mapping available!”
#endif

I added defined(AVR_ATmega328P) to the list.

#elif defined(AVR_ATmega64) ||
defined(AVR_ATmega128) ||
defined(AVR_ATmega328P) ||
defined(AVR_ATmega169)

Now I get a the following errors:

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp: In function ‘uint8_t sd_raw_init()’:

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp:172: error: ‘PB0’ was not declared in this scope

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp: In function ‘uint8_t sd_raw_read(uint32_t, uint8_t*, uint16_t)’:

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp:418: error: ‘PB0’ was not declared in this scope

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp: In function ‘uint8_t sd_raw_write(uint32_t, const uint8_t*, uint16_t)’:

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp:663: error: ‘PB0’ was not declared in this scope

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp: In function ‘uint8_t sd_raw_get_info(sd_raw_info*)’:

\arduino-0017\hardware\libraries\SDcard\sd_raw.cpp:809: error: ‘PB0’ was not declared in this scope

Anytime select_card(); or unselect_card(); is called, results in the errors above, that PB0 is not defined.

Could the fix be as easy as getting the correct vars/pins defined?

Thank for you the help

I am having the exact same problem. Can anyone point to a way how to compile the library with an ATmega328?

Thanks, Marcel

Having the same problem here. Has anyone found a solution?

(I had to write a post in order to contact other people in the forum. So I am sorry for not helping much.)

Ok, I found the solution in (this?) forum but I cannot find the post anymore.

So I worked for me doing the following:

In the Arduino program folder change an entry in the file hardware/tools/avr/avr/include/avr/iom328p.h:

Change (comment out)

/* #define PORTB _SFR_IO8(0x05) / / #define PORTB0 0 / / #define PORTB1 1 / / #define PORTB2 2 / / #define PORTB3 3 / / #define PORTB4 4 / / #define PORTB5 5 / / #define PORTB6 6 / / #define PORTB7 7 */

to:

define PORTB _SFR_IO8 (0x05)

/* PORTB */

define PB7 7

define PB6 6

define PB5 5

define PB4 4

define PB3 3

define PB2 2

define PB1 1

define PB0 0

HTH, Stefan