Can't get it to work!
If I'm flashing a test sketch, then SPI works:
Code: Select all
#include <SPI.h>
#define SPI2_NSS_PIN PA15 //SPI_2 Chip Select pin is PB12. You can change it to the STM32 pin you want.
// mosi, miso, sclk, ssel
SPIClass SPI_2(PB5, PB4, PB3, SPI2_NSS_PIN); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port
byte data;
void setup() {
// Setup SPI 2
SPI_2.begin(); //Initialize the SPI_2 port.
SPI_2.setBitOrder(MSBFIRST); // Set the SPI_2 bit order
SPI_2.setDataMode(SPI_MODE0); //Set the SPI_2 data mode 0
SPI_2.setClockDivider(SPI_CLOCK_DIV16); // Use a different speed to SPI 1
pinMode(SPI2_NSS_PIN, OUTPUT);
}
void loop() {
sendSPI2();
delayMicroseconds(10); //Delay 10 micro seconds.
}
void sendSPI2()
{
digitalWrite(SPI2_NSS_PIN, LOW); // manually take CSN low for SPI_2 transmission
data = SPI_2.transfer(0x55); //Send the HEX data 0x55 over SPI-2 port and store the received byte to the <data> variable.
digitalWrite(SPI2_NSS_PIN, HIGH); // manually take CSN high between spi transmissions
}
I checked with an oscilloscope, the data is being transmitted.
But if I connect the nrf24l01 library, the SPI port stops working. I am using the RF24 library:
https://github.com/nRF24/RF24
Maybe you know a library that will work stably?