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

How to use the library for SPI2 and SPI3 or SPI_2 and SPI_3 #31

Open
brightproject opened this issue May 28, 2023 · 1 comment
Open

Comments

@brightproject
Copy link

How to use this library for black pill STM32F401CCU6?
The files SPIFlash.cpp and SPIFlash.h, as I understand it, are an "add-on" over the main SPI library from Arduino?
I am using an arduino IDE and two cores to work with a microcontroller STM32F401CCU6.
Each kernel folder has its own files with examples for working with SPI.
Accordingly, I have three folders on the PC with the same file names in them:

  1. Arduino(C:\Users\Admin\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.5\libraries\SPI) SPI.cpp and SPI.h
  2. STM core for Arduino IDE(C:\Users\Admin\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.5.0\libraries\SPI) SPI.cpp and SPI.h
  3. Rogerclark core for Arduino IDE(C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI) SPI.cpp and SPI.h
    And I don't understand which of these three files to "load" from file SPIFlash.h
    #include <SPI.h>
    Or rather, as far as I understand - depending on the selected kernel through the plan menu, such a file will be loaded during compilation.
    But these questions do not remove questions about how to work with external flash memory through the SPI2 and SPI3 interfaces, but rather add questions and confuse even more.
@brightproject
Copy link
Author

brightproject commented May 28, 2023

I added in SPIFlash.cpp into function SPIFlash::initialize() code:

  SPI.setMOSI(PB5);
  SPI.setMISO(PB4);
  SPI.setSCLK(PB3);

and got the following

boolean SPIFlash::initialize()
{
#if defined (SPCR) && defined (SPSR)
  _SPCR = SPCR;
  _SPSR = SPSR;
#endif
//reMAP pins from SPI to SPI3
  SPI.setMOSI(PB5);
  SPI.setMISO(PB4);
  SPI.setSCLK(PB3);
  pinMode(_slaveSelectPin, OUTPUT);
  //divider not work
  //SPI.setClockDivider(SPI_CLOCK_DIV4);
  SPI.begin();
#ifdef SPI_HAS_TRANSACTION
  _settings = SPISettings(10000000L, MSBFIRST, SPI_MODE0);// set 10 MHz(10000000 Hz), real 8 MHz
#endif

  unselect();
  wakeup();
  
  if (_jedecID == 0 || readDeviceId() == _jedecID) {
    command(SPIFLASH_STATUSWRITE, true); // Write Status Register
    SPI.transfer(0);                     // Global Unprotect
    unselect();
    return true;
  }
  return false;
}

SPI frequency not work by DIVIDER.
Worked during transaction only

Code from example worked with core stm32duino - https://github.com/stm32duino/Arduino_Core_STM32
Logic analizer image
SPI_Flash
Max CLK frequency - 8 Mhz for SPI_3, then :
_settings = SPISettings(10000000L, MSBFIRST, SPI_MODE0);// set 10 MHz(10000000 Hz), real 8 MHz

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

1 participant