I am running a SD card (level shifters and 5v-3.3v PSU adapted) and a RFID device.
Both work independently in their own sketches.
If I join them the only way the SD works is to add a 330ohm resistor in line with the MISO pin but then the RFID wont initialise.
I've read similar posts with the issue and the help varies alot. Any new advice would be great!!
#include <SPI.h>
#include <PN532_SPI.h>
#include <SD.h>
#include "PN532.h"
PN532_SPI pn532spi(SPI, 10);
PN532 nfc(pn532spi);
boolean success;
int powerPin = A5;
int powerpinRead;
int prevpowerpinRead = LOW;
int powerpinState = LOW;
int prevpowerpinState = HIGH;
long time = 0;
long debounce = 200;
void setup(void) {
Serial.begin(9600);
pinMode (65, OUTPUT);//sd card CS
pinMode(powerPin, OUTPUT);
uint16_t time = millis();
time = millis() - time;
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
nfc.setPassiveActivationRetries(0x01);
nfc.SAMConfig();
//SD test
File myFile;
Serial.print("Initializing SD card...");
if (!SD.begin(65)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
//SD test
}
void loop()
{
readRfid();
powerpinRead = (success);
}
void readRfid()
{
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.println("Found a card!");
for (uint8_t i = 0; i < uidLength; i++)
{
// Serial.print(" 0x");Serial.print(uid[i], HEX);
}
}
if (powerpinRead == HIGH && prevpowerpinRead == LOW && millis() - time > debounce)
{
if (powerpinState == HIGH)
powerpinState = LOW;
else
powerpinState = HIGH;
time = millis();
}
digitalWrite(powerPin, powerpinState);
}

