Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLVED : SD fat on Software SPI not compiling on MightyCore 1284p #55

Closed
SrikanthBala opened this issue Apr 22, 2017 · 6 comments
Closed

Comments

@SrikanthBala
Copy link

SrikanthBala commented Apr 22, 2017

At the outset thank you for providing SDFat. I am currently using a MightyCore for 1284P and have successfully tested a SD card using your library on the 1284P running at 3.3V on a external 8MHz crystal on a breadboard using hardware SPI.
However when I used the code provided by you for SoftwareSPI (provided actually for 2560) my code first does not compile at all. and gives an error as below :

In file included from F:\arduino-1.8.2\portable\sketchbook\libraries\SdFat\src/SdSpiCard/DigitalPin.h:45:0,
from F:\arduino-1.8.2\portable\sketchbook\libraries\SdFat\src/SdSpiCard/SoftSPI.h:31,

             from F:\arduino-1.8.2\portable\sketchbook\libraries\SdFat\src/SdSpiCard/SdSpi.h:235,

             from F:\arduino-1.8.2\portable\sketchbook\libraries\SdFat\src/SdSpiCard/SdSpiCard.h:29,

             from F:\arduino-1.8.2\portable\sketchbook\libraries\SdFat\src/SdFat.h:27,

             from F:\arduino-1.8.2\portable\sketchbook\Series2_Tx\DumpInfo\DumpInfo\SDSPI1284\SDSPI1284.ino:7:

F:\arduino-1.8.2\portable\sketchbook\libraries\SdFat\src/SdSpiCard/boards/GpioPinMap.h:40:2: error: #error Undefined variant 1284, 644, 324
#error Undefined variant 1284, 644, 324

I have not got this error when using other libraries on 1284P.

Finally I got the code to compile without errors by commenting out everything in GpioPinMap.h and adding the line #include "BobuinoGpioPinMap.h" as I am using the Bobuino pinout. After uploading, I realized my card is not recognized.

I need to use SoftwareSPI as my RC522 with the SD card if both are attached to the same SPI bus.

Kindly provide me with help as to why it does not compile in the first place without modifying Gpio header file and also why it doesnt recognize my card

I am using a SD fat library which says #define SD_FAT_VERSION 20160719
The Mighty Core is also recent I believe as I am using the IDE version 1.8.2 and downloaded it using Boards Manager. I am using Mighty Core MCUdude version 1.0.8

Please help. My code is the same as on this site with pins modified as below :

// An example of the SdFatSoftSpi template class.
// This example is for an Adafruit Data Logging Shield on a Mega.
// Software SPI is required on Mega since this shield connects to pins 10-13.
// This example will also run on an Uno and other boards using software SPI.
//

#include "SdFat.h"
#include <SPI.h>

#if SD_SPI_CONFIGURATION >= 3 // Must be set in SdFat/SdFatConfig.h
//
// Pin numbers in templates must be constants.
const uint8_t SOFT_MISO_PIN = 6;
const uint8_t SOFT_MOSI_PIN = 5;
const uint8_t SOFT_SCK_PIN = 7;
//
// Chip select may be constant or RAM variable.
const uint8_t SD_CHIP_SELECT_PIN = 10;

// SdFat software SPI template
SdFatSoftSpi<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> sd;

// Test file.
SdFile file;

void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}
Serial.println("Type any character to start");
while (!Serial.available()) {
SysCall::yield();
}

if (!sd.begin(SD_CHIP_SELECT_PIN)) {
sd.initErrorHalt();
}

if (!file.open("SoftSPI.txt", O_CREAT | O_RDWR)) {
sd.errorHalt(F("open failed"));
}
file.println(F("This line was printed using software SPI."));

file.rewind();

while (file.available()) {
Serial.write(file.read());
}

file.close();

Serial.println(F("Done."));
}
//------------------------------------------------------------------------------
void loop() {}
#else // SD_SPI_CONFIGURATION >= 3
#error SD_SPI_CONFIGURATION must be set to 3 in SdFat/SdFatConfig.h
#endif //SD_SPI_CONFIGURATION >= 3

The error I get is :

Type any character to start
Can't access SD card. Do not reformat.
No card, wrong chip select pin, or SPI problem?
SD errorCode: 0X1,0X0

@greiman
Copy link
Owner

greiman commented Apr 22, 2017

I don't have a 8 MHz MightyCore so I can't help you.

I no longer test SdFat with 1284P boards.

@SrikanthBala
Copy link
Author

Thank you sir for your prompt response. I am designing a new device which requires more pins than a ATMega 328. Hence I chose the 1284P. The other option I have is a Maple Mini like STM32 board. It is fast, has the pins I need and is cost effective.
However I tried SdFat today on SPI1 using a LC MicroSd Shield bypassing the 5V regulator and using direct 3.3 V. However the level converter IC is not bypassed (its datasheet mentions it will work correctly for all voltages above 2.6v)

However the STM32 card returns failure to find the card using the SdInfo.ino. Pin connections made for SP1 and checked multiple times. No sketch works for SD card indicating a basic fault in my system. Does your SdFat support STM32 Core ?

@greiman
Copy link
Owner

greiman commented Apr 22, 2017

Arduino STM32 requires the old Arduino IDE 1.6.12.

SdFat no longer works reliably on STM32 and I don't want to fix it for 1.6.12.

@SrikanthBala
Copy link
Author

Ok

@stevstrong
Copy link

A short comment:
Arduino_STM32 code works with both SdFat and SdFat beta, with Arduino 1.6.9 or later.
But: it only works with SD card modules designed for 3.3V, without 5V->3.3V regulator, see:
http://www.stm32duino.com/viewtopic.php?f=13&t=20, section "Known problems".

@SrikanthBala SrikanthBala reopened this Apr 24, 2017
@SrikanthBala SrikanthBala changed the title SD fat on Software SPI not compiling on MightyCore 1284p SOLVED : SD fat on Software SPI not compiling on MightyCore 1284p Apr 24, 2017
@SrikanthBala
Copy link
Author

SrikanthBala commented Apr 24, 2017

Thank you stevstrong.
I closed this issue earlier thinking I should just give up on the 1284p and the Mighty Core for Software SPI. I just got back here to see your comment. I AM using a 3.3V modified microSD module (as my 1284p is also running at 3.3V). I'll definitely give it a go with my Black Pill STM32 board.

Meanwhile I reopened this because I finally found the problem with my code for the 1284P.

First to solve the compiling problem. I needed to modify the GpioPinMap.h file. The original GpioPinMap.h file in the SDfat library under "SdFat/SdFat/src/SdSpiCard/boards/GpioPinMap.h" has the following two lines which need to be changed to compile under the MCUDUDE MightyCore :

Near the end of the file :
#elif defined(ARDUINO_1284P_BOBUINO)
needs to be changed to #elif defined(BOBUINO_PINOUT)
and
#elif defined(ARDUINO_1284P_STANDARD)
needs to be changed to #elif defined(STANDARD_PINOUT)

After this the code compiled and uploaded but no luck. SD card could not be read.

After nearly 24 hrs of breaking my head on multiple SD card adapters and finally fixing one 'impossible to see' internally broken jumper wire, and trying a zillion other combinations, I found in a 2012 Arduino forum that SdFat SoftwareSpi assumes a Standard or Sanguino pinout and not Bobuino pinout. So I switched to Standard pinout names in the code and BINGO ! it worked !
In fact it does not matter whether I select Bobuino board or Standard board under the boards selection for the Mighty Core. It still works on the Standard Pin names only as if the Standard Pins were somehow hardcoded into the SDFat SoftwareSPI code ignoring the definitions in Gpio.h. I dont currently know how to modify SDFat to use the right pins so I'll leave it at that, as I know how to get the the code to work.

Thanks Greiman for the library once again. And incidentally I tried it at both 16MHz and 8Mhz too and it works GREAT !
I hope this helps someone else struggling on similar lines. Bye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants