Mam problem z działaniem układu. Posiadam płytkę MEGA2560 r3 przez którą programuje ATMEGE328. Programy się ładnie wgrywają i działają. Problem polega na tym że ATMEGA nie chce działać z czytnikiem microSD (który na MEGA2560 działa).
Zmodyfikowałem trochę przykład "CardInfo" z biblioteki SD aby móc sprawdzić czy karta działa
Oto kod:
Kod: Zaznacz cały
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
/*
SD card test
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 4 used here for consistency with other Arduino examples
created 28 Mar 2011
by Limor Fried
modified 9 Apr 2012
by Tom Igoe
*/
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;
void setup()
{
// Open serial communications and wait for port to open:
lcd.begin(16,2);
lcd.home();
lcd.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(chipSelect, OUTPUT); // change this to 53 on a mega
digitalWrite(chipSelect, HIGH);
pinMode(SS, OUTPUT);
digitalWrite(SS,HIGH);
SD.begin(chipSelect);
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
lcd.setCursor(0,1);
lcd.print("failed");
return;
} else {
lcd.clear();
lcd.home(); //****************
Serial.print("Wiring is correct");
}
// print the type of card
lcd.setCursor(0,1);
lcd.print("Card type: ");
switch(card.type()) {
case SD_CARD_TYPE_SD1:
lcd.println("SD1");
break;
case SD_CARD_TYPE_SD2:
lcd.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
lcd.println("SDHC");
break;
default:
lcd.println("Unknown");
}
}
void loop(void) {
}
Proszę o pomoc :(
Pozdrawiam
Adam