Page 1 of 1

[Solved] SD.h or SDfat.h with SPI2

Posted: Wed Jun 10, 2020 8:05 am
by jenspogo
Hey guys :)
I'm trying to use the SD.h or the SDfat.h lib with the second SPI on an STM32F103 - but I'm failing.
My Idea was to remap the Pins:

Code: Select all

#include <SPI.h>

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
while(!Serial)
{
}

SPI.setMISO(PB14);
SPI.setMOSI(PB15);
SPI.setSCLK(PB13);
SPI.setSSEL(PB12);

Serial.print("MISO is: ");
Serial.print(MISO);
Serial.print(" but should be: ");
Serial.println(PB14);

Serial.print("MOSI is: ");
Serial.print(MOSI);
Serial.print(" but should be: ");
Serial.println(PB15);

Serial.print("SCK is: ");
Serial.print(SCK);
Serial.print(" but should be: ");
Serial.println(PB13);

Serial.print("CSS is: ");
Serial.print(SS);
Serial.print(" but should be: ");
Serial.println(PB12);
}

void loop() {
  // put your main code here, to run repeatedly:

}
But it seems, not to work:

Code: Select all

MISO is: 26 but should be: 14
MOSI is: 27 but should be: 13
SCK is: 25 but should be: 15
CSS is: 24 but should be: 16
Or is there another way to do what I want?

Greetings, Jens

Re: SD.h or SDfat.h with SPI2

Posted: Wed Jun 10, 2020 8:56 am
by fpiSTM
Well, this is normal you got this as the SCK, MOSI and other are a define. using the SPI.setxxx will not change those define.
But the setxxx will change the used one for the SPI instance...

Re: SD.h or SDfat.h with SPI2

Posted: Thu Jun 11, 2020 11:04 am
by jenspogo
oh :D
It works.
my fault ;)

Re: SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 12:08 am
by FerroFerido
fpiSTM wrote: Wed Jun 10, 2020 8:56 am Well, this is normal you got this as the SCK, MOSI and other are a define. using the SPI.setxxx will not change those define.
But the setxxx will change the used one for the SPI instance...
I want save datas in a SD Card, You have any exemplos for help me? Please, i really need there. (I'm sorry my horrible english, i'm lerning now)

Re: [Solved] SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 10:15 am
by mlundin
@FerroFerido There is a SD library https://github.com/stm32duino/STM32SD. The library can be installed from the Arduino library manager. There are example projects distributed with the library.

Nobody can give more help without information about what board you have, the SD card reader and the type and amount of data you have to save.

Re: [Solved] SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 10:45 am
by fpiSTM
STM32SD library is for SD card slot connected to SDIO or SDMMC IP of the MCU.
If you use an SPI SD card slot then simply use the Arduino SD library.
For both several example are provided.

Re: [Solved] SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 2:20 pm
by FerroFerido
mlundin wrote: Wed Nov 18, 2020 10:15 am @FerroFerido There is a SD library https://github.com/stm32duino/STM32SD. The library can be installed from the Arduino library manager. There are example projects distributed with the library.

Nobody can give more help without information about what board you have, the SD card reader and the type and amount of data you have to save.
The Module who i'm using has a SPI conecction and my board is a Bluepill.

Re: [Solved] SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 2:34 pm
by FerroFerido
fpiSTM wrote: Wed Nov 18, 2020 10:45 am STM32SD library is for SD card slot connected to SDIO or SDMMC IP of the MCU.
If you use an SPI SD card slot then simply use the Arduino SD library.
For both several example are provided.
my doubt about this case is: my board it's a BluePIll, it has more than two SPIO pins, who i can use this library in this case? Does It the same thing?

Re: [Solved] SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 2:36 pm
by FerroFerido
FerroFerido wrote: Wed Nov 18, 2020 2:20 pm
mlundin wrote: Wed Nov 18, 2020 10:15 am @FerroFerido There is a SD library https://github.com/stm32duino/STM32SD. The library can be installed from the Arduino library manager. There are example projects distributed with the library.

Nobody can give more help without information about what board you have, the SD card reader and the type and amount of data you have to save.
The Module who i'm using has a SPI conecction and my board is a Bluepill.
I want save temperature in TXT format. Its possible?

Re: [Solved] SD.h or SDfat.h with SPI2

Posted: Wed Nov 18, 2020 4:35 pm
by fpiSTM
Please refers to:
https://www.arduino.cc/en/reference/SD

Note SPIO does not exists AFAIK. F103 does not have SDIO/SDMMC IP so forgot this.