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

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
jenspogo
Posts: 30
Joined: Mon Feb 24, 2020 10:42 am

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

Post 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
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: SD.h or SDfat.h with SPI2

Post 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...
jenspogo
Posts: 30
Joined: Mon Feb 24, 2020 10:42 am

Re: SD.h or SDfat.h with SPI2

Post by jenspogo »

oh :D
It works.
my fault ;)
FerroFerido
Posts: 12
Joined: Tue Nov 17, 2020 11:10 pm

Re: SD.h or SDfat.h with SPI2

Post 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)
mlundin
Posts: 94
Joined: Wed Nov 04, 2020 1:20 pm
Answers: 6
Location: Sweden

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

Post 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.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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.
FerroFerido
Posts: 12
Joined: Tue Nov 17, 2020 11:10 pm

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

Post 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.
FerroFerido
Posts: 12
Joined: Tue Nov 17, 2020 11:10 pm

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

Post 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?
FerroFerido
Posts: 12
Joined: Tue Nov 17, 2020 11:10 pm

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

Post 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?
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post 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.
Post Reply

Return to “General discussion”