Page 1 of 2

SD-Card Reader problem

Posted: Mon Jan 18, 2021 12:37 pm
by mannitb303
Hi all,

i got a Mable Mini Clone and want to build a MIDI-Controller. This is my first use of a 32F103 and anything works perfect, multiplexing encoders and potentiometers i connected a LCD Display but i can not get the SD-Card reader board with SPI Interface to work.
I used the Arduino SD-Example as written in the Arduino forum and also here but it dont work.
I tried SPI1, SPI2, and SPI3 but nothing works i also mapped the Pins with SPI.setMOSI(Pin) but it dont work as i read in the Forum. Is there another way to get it work? I think it is a Chip Select problem but how i can fix it?

Arduino IDE 1.8.13 installed, latest STM32duino core and roger clarks arduino STM32 for Maple Mini


Thanks

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 1:37 pm
by fpiSTM
well hard to tell.
You should use the default SPI pins as described in the variant.

Code: Select all

#define PIN_SPI_MOSI            PA7
#define PIN_SPI_MISO            PA6
#define PIN_SPI_SCK             PA5
and by default the CS pin is defined by the example.

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 2:49 pm
by mannitb303
Wow,

Thank you very much. It is so easy.......
Why i didnt found that?
Can i use another SPI Port also? How i configure SPI2 Port?

It now works also with the SDFat Example......

Thanks

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 3:49 pm
by fpiSTM

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 4:56 pm
by mannitb303
Thank you,
this is also what i found but i dont understand it. If i map the Pins with SPI.setMOSI(PC2); i got a error message from the Compiler:

SPI does not name a type

I also tried to use:

Code: Select all

#define PIN_SPI_MOSI            PB15  //SPI2
#define PIN_SPI_MISO            PB14  //SPI2
#define PIN_SPI_SCK             PB13  //SPI2
Dont work. Why i can not only change the Pins, need it to initalize the second SPI?
In the SD Example CardInfo they never call SPI.begin(), so where i can find it?

Thanks


Ok. I got it.

I used

Code: Select all

SPI.setModule(2);
to remap the SPI Pins. It remaps automaticly SPI1 to SPI2. You only have to define the CS Pin in the Sketch.

Thanks

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 5:22 pm
by fpiSTM
SPI.begin() is hidden in the library.
There is no PC2 defined for maple that's why you get error... compiler has alwaysthe right answers :mrgreen:
On Maple, SPI2 peripheral can be found on PB13(SCLK), PB14(MISO) and PB15(MOSI).

So you can use setXXX() before the call of SPI.begin() or define a new instance but several thied party libraries hardcode the default 'SPI' instance.

Code: Select all

SPIClass SPI_2(PB15, PB14, PB13);

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 5:32 pm
by mannitb303
Sorry,
i dont change the PC2 Pin in the SPI.setMOSI. But if i change it to PB15 i got the same error from my Compiler. SPI does not name a type.

If i try

Code: Select all

SPIClass SPI_2(PB15, PB14, PB13);
i got also a error from my Compiler.
  • CardInfo:37:32: error: no matching function for call to 'SPIClass::SPIClass(<anonymous enum>, <anonymous enum>, <anonymous enum>)'
    SPIClass SPI_2(PB15, PB14, PB13);
    ^
    C:\Users\smanh\AppData\Local\Temp\arduino_modified_sketch_958854\CardInfo.ino:37:32: note: candidates are:
    In file included from C:\Users\smanh\AppData\Local\Temp\arduino_modified_sketch_958854\CardInfo.ino:23:0:
    C:\Users\smanh\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.12.26\libraries\SPI\src/SPI.h:176:5: note: SPIClass::SPIClass(uint32)
    SPIClass(uint32 spiPortNumber);
    ^
    C:\Users\smanh\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.12.26\libraries\SPI\src/SPI.h:176:5: note: candidate expects 1 argument, 3 provided
    C:\Users\smanh\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.12.26\libraries\SPI\src/SPI.h:170:7: note: constexpr SPIClass::SPIClass(const SPIClass&)
    class SPIClass {
    ^
    C:\Users\smanh\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.12.26\libraries\SPI\src/SPI.h:170:7: note: candidate expects 1 argument, 3 provided
    C:\Users\smanh\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.12.26\libraries\SPI\src/SPI.h:170:7: note: constexpr SPIClass::SPIClass(SPIClass&&)
    C:\Users\smanh\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2020.12.26\libraries\SPI\src/SPI.h:170:7: note: candidate expects 1 argument, 3 provided
    exit status 1
    no matching function for call to 'SPIClass::SPIClass(<anonymous enum>, <anonymous enum>, <anonymous enum>)'
But now with

Code: Select all

SPI.setModule(2)
it works.

Thank you.

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 5:57 pm
by fpiSTM
So you use Rogers (libmaple) core not STM32 core....

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 9:20 pm
by mannitb303
I installed both... Can this be the problem?

Re: SD-Card Reader problem

Posted: Mon Jan 18, 2021 10:11 pm
by fpiSTM
No. You can use both. They are independent. But they do not have the same API. So be precise next time. My previous post are valid for STM32 core not maple one.