How to use SPI2

Post here first, or if you can't find a relevant section!
mrguen
Posts: 12
Joined: Tue Mar 03, 2020 1:21 pm
Answers: 1

Re: How to use SPI2

Post by mrguen »

I a m sorry but I can't make SPI work with alternate pins to drive a TFT. It works with default pins (PA5,PA7) but not when using

Code: Select all

  
  SPI.setMOSI(PB_5);
  SPI.setSCLK(PB_3);
  SPI.begin(); 
  // even when adding this in any case 
  __HAL_RCC_I2C1_CLK_DISABLE();
  
ON STM32F401RCT6

other pins are defined as

Code: Select all

  
  #define TFT_CS PB0  // tried PA4, PB4: same
  #define TFT_RST PB9
  #define TFT_DC PB8
  

User avatar
fpiSTM
Posts: 792
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 30
Location: Le Mans
Contact:

Re: How to use SPI2

Post by fpiSTM »

For core Board, PB5 and PB3 used by default the SPI3 instance and as you keep the PA6 for MISO which use SPI1 then this could not work as SPI instance are not the same.
Try to uncomment PB_5 and PB_3 in the peripheralPins.c or better define your own PinMap_SPI_MOSI and PinMap_SPI_SCLK at sketch level.

Why this:

Code: Select all

  // even when adding this in any case 
  __HAL_RCC_I2C1_CLK_DISABLE();
I think I knwo where you get this but this is not related to STM32F4xx...

mrguen
Posts: 12
Joined: Tue Mar 03, 2020 1:21 pm
Answers: 1

Re: How to use SPI2

Post by mrguen »

@fpiSTM
About __HAL_RCC_I2C1_CLK_DISABLE(); I saw that there was an incompatibility on some boards with I2C1 so I tried in case it would solve the problem.

Yes, uncommenting PB_3 and PB_5 affectation to SPI1 worked.

So the question might be: why it was commented?

Thanks

User avatar
fpiSTM
Posts: 792
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 30
Location: Le Mans
Contact:

Re: How to use SPI2

Post by fpiSTM »

mrguen wrote:
Mon Aug 17, 2020 3:36 pm
@fpiSTM
About __HAL_RCC_I2C1_CLK_DISABLE(); I saw that there was an incompatibility on some boards with I2C1 so I tried in case it would solve the problem.
Yes for STM32F103Cx as I've explained in the related issue.
mrguen wrote:
Mon Aug 17, 2020 3:36 pm
Yes, uncommenting PB_3 and PB_5 affectation to SPI1 worked.
Fine.
mrguen wrote:
Mon Aug 17, 2020 3:36 pm
So the question might be: why it was commented?
Only the first pin found in the array are used so it was commented to be able to use SPI3 instance. This also allows to save some space. Anyway, I'm currently working to remove this limitations which can currently be solved using the redefinition at sketch level. See above.
mrguen wrote:
Mon Aug 17, 2020 3:36 pm
Also could you point me to the resource on how to define it at sketch level?
https://github.com/stm32duino/wiki/wiki ... nmap-array

rikysuhendra
Posts: 2
Joined: Sun Sep 13, 2020 4:26 am

Re: How to use SPI2

Post by rikysuhendra »

[ENGLISH]
Hello,

I want to share what I experienced in making the system
who implemented STM32F103C [STM32F103C8T6] stm32duino

in 2019,
Initially, I used the Arduino IDE v.1.5.x software
and using EThernet_STM.h
but because of the design needs that require A0-A9 as a digital input
10-bit absolute rotary sensor, then SPI must be moved from SPI-1 to SPI-2
in this condition I modify the W550.cpp to be like this
C: \ Users \ [your PC] \ AppData \ Local \ Arduino15 \ packages \ stm32duino \ hardware \ STM32F1 \ 2019.12.31 \ libraries \ Ethernet_STM \ src \ utility
-------------------------------------------------- -------------
#include <stdio.h>
#include <string.h>
#include <SPI.h> // add by riky

#include "utility / w5100.h"
#if defined (W5500_ETHERNET_SHIELD)

// W5500 controller instance
W5500Class W5100;

#define SPI_CS 10
// # define STM32_SPI_CS PA4 // edit by riky
#define STM32_SPI_CS PB12 // change by riky
// # define SPI2_NSS_PIN PB12 // add by riky
SPIClass SPI_2 (2); // add by riky

void W5500Class :: init (void)
....
..
etc
-------------------------------------------------- -------------

but after I upgraded the Arduino IDE 1.5.x to v.1.8.x
can no longer ... :(
so I have to do more, and pray to the Lord Jesus
... finally God showed me a directory and a file
and directs me to have to modify the variant.h file that's in
C: \ Users \ [yourPC] \ AppData \ Local \ Arduino15 \ packages \ STM32 \ hardware \ stm32 \ 1.8.0 \ variants \ PILL_F103XX

on the line: [the standard is SPI-1]

// SPI Definitions
#define PIN_SPI_SS PA4
#define PIN_SPI_MOSI PA7
#define PIN_SPI_MISO PA6
#define PIN_SPI_SCK PA5

change to: [SPI-2]

// SPI Definitions
#define PIN_SPI_SS PB12
#define PIN_SPI_MOSI PB15
#define PIN_SPI_MISO PB14
#define PIN_SPI_SCK PB13


and change from Ethernet_STM.h to Ethernet.h

Hallelujah ... Praise God
works ... :)

ok, hope it's useful
Lord Jesus bless you and your family so much - so much - so much
amen!

[INDONESIA]
Halo,

saya mau berbagi apa yang saya alami dalam membuat system
yang menerapkan STM32F103C [STM32F103C8T6] stm32duino

pada tahun 2019,
awalnya, saya mengunakan software Arduino IDE v.1.5.x
dan mengunakan EThernet_STM.h
namun karena kebutuhan design yang membutuhkan A0-A9 sebagai digital input
10-bit absolute rotary sensor, maka SPI harus dipindahkan dari SPI-1 ke SPI-2
pada kondisi ini saya memodifikasi W550.cpp menjadi seperti berikut
C:\Users\[your PC]\AppData\Local\Arduino15\packages\stm32duino\hardware\STM32F1\2019.12.31\libraries\Ethernet_STM\src\utility
---------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <SPI.h> //add by riky

#include "utility/w5100.h"
#if defined(W5500_ETHERNET_SHIELD)

// W5500 controller instance
W5500Class W5100;

#define SPI_CS 10
//#define STM32_SPI_CS PA4 //edit by riky
#define STM32_SPI_CS PB12 //change by riky
//#define SPI2_NSS_PIN PB12 //add by riky
SPIClass SPI_2(2); //add by riky

void W5500Class::init(void)
....
..
dan seterusnya
---------------------------------------------------------------

tetapi setelah saya upgrade Arduino IDE 1.5.x menjadi v.1.8.x
sudah tidak bisa lagi... :(
jadi saya harus ngoprek lagi, dan berdoa kepada Tuhan Yesus
...akhirnya Tuhan tunjukan ke saya suatu direktroy dan file
dan mengarahkan saya harus memodifikasi file variant.h yang ada di
C:\Users\[yourPC]\AppData\Local\Arduino15\packages\STM32\hardware\stm32\1.8.0\variants\PILL_F103XX

pada baris: [standard nya SPI-1]

// SPI Definitions
#define PIN_SPI_SS PA4
#define PIN_SPI_MOSI PA7
#define PIN_SPI_MISO PA6
#define PIN_SPI_SCK PA5

rubah menjadi : [SPI-2]

// SPI Definitions
#define PIN_SPI_SS PB12
#define PIN_SPI_MOSI PB15
#define PIN_SPI_MISO PB14
#define PIN_SPI_SCK PB13


dan mengganti dari Ethernet_STM.h menjadi Ethernet.h

Haleluya...Puji Tuhan
berhasil...:)

ok, semoga bermanfaat
Tuhan Yesus memberkati anda sekeluarga berlimpah-limpah-limpah
amin!

Post Reply

Return to “General discussion”