adafruit / Adafruit_nRF52_Arduino

Adafruit code for the Nordic nRF52 BLE SoC on Arduino
Other
606 stars 492 forks source link

Doesn`t work SPIM3 on nRF52840 #700

Closed Fantonrko closed 2 years ago

Fantonrko commented 2 years ago

Operating System

Windows 10

IDE version

1.8.16

Board

Feather nRF52840 Express

BSP version

1.0.1

Sketch

#define SPI_INTERFACES_COUNT 2
#define SPI_32MHZ_INTERFACE 1
#define PIN_SPI_MISO (30)
#define PIN_SPI_MOSI (39)
#define PIN_SPI_SCK (37)

#ifndef SPI_32MHZ_INTERFACE 1
#define SPI_32MHZ_INTERFACE 1
#endif
#if SPI_32MHZ_INTERFACE == 0
  #define _SPI_DEV    NRF_SPIM3 // 32 Mhz
  #define _SPI1_DEV   NRF_SPIM2
#elif SPI_32MHZ_INTERFACE == 1
  #define _SPI_DEV    NRF_SPIM2
  #define _SPI1_DEV   NRF_SPIM3 // 32 Mhz
#else
  #error "not supported yet"
#endif
#if SPI_INTERFACES_COUNT >= 1
SPIClass SPI(_SPI_DEV,  PIN_SPI_MISO,  PIN_SPI_SCK,  PIN_SPI_MOSI);
#endif
#if SPI_INTERFACES_COUNT >= 2
SPIClass SPI1(_SPI1_DEV, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI);
#endif

What happened ?

Have enable SPIM3 like sketch, But SPI speed still 8MHz on my oscilloscope. What`s i can do to use max 32MHz ?

I already reported this issue on the Adafruit forum, but no one there was able to help in the correct SPIM3 setup and use. I have tried changing various parameters in the libraries that refer to changing the speed, but never got the desired result

How to reproduce ?

-

Debug Log

No response

Screenshots

No response

dhalbert commented 2 years ago

Could you show the whole sketch, or attach it as a .txt file? This does not include PIN_SPI1_MISO, or any use of SPI1.

Fantonrko commented 2 years ago

Could you show the whole sketch, or attach it as a .txt file? This does not include PIN_SPI1_MISO, or any use of SPI1.

I use Adafruit_nRF52_Arduino version 1.0.0 with default setting, just try communicate with tft display. Use TFT_ESPI and Arduino_GFX and have the same result, SPI = 8 MHz, so i think that Adafruit_nRF have wrong options

dhalbert commented 2 years ago

Please show your whole sketch. That is only part of your Arduino sketch.

Fantonrko commented 2 years ago

Please show your whole sketch. That is only part of your Arduino sketch.

U mean configuration files ( variant.h, spi.h, spi.cpp and etc.) or only arduino sketch with tft example ?

dhalbert commented 2 years ago

The sketch only, but the whole sketch. We have variant.h, spi.cpp etc.,assuming they are what is in the released board support package. 1.1.0 is actually available, and you are using 1.0.0, but I don't think there are changes that affect this.

dhalbert commented 2 years ago

You can upload it as a file (zip it or change the extension), instead of pasting it in.

Fantonrko commented 2 years ago

The sketch only, but the whole sketch. We have variant.h, spi.cpp etc.,assuming they are what is in the released board support package. 1.1.0 is actually available, and you are using 1.0.0, but I don't think there are changes that affect this.

oh, sorry, i use 1.0.1 version. I use 2 library for graphic, Arduino_GFX and TFT_eSPI (prefer second). If u need user_Setup from TFT_eSPI i can upload it. So i use Hardware SPI ping, which I wrote in variant.h. TFT_Test.zip

hathach commented 2 years ago

@Fantonrko for a bug report, you need upload all needed codes so that we could open it and reproduce the issue. Any out of code configure like variant modification or hardware setup need to be stated clearly. The codes should be as minimal as possible to reduce the scope of analysis. I just check your uploaded example, it is too complicated for a bug report. Please remove all the code that is not needed to reproduce the issue and try again.

Fantonrko commented 2 years ago

@hathach, @dhalbert I hope this will be enough :) First_Test.zip

Fantonrko commented 2 years ago

@hathach @dhalbert Okey, All fine. I get 32MHz. How to use SPIM3 in Adafruit nRF52840: In file "SPI.CPP" on line 38 i change spim.p_reg = p_spi; to _spim.p_reg = NRF_SPIM3; on line 200 i change nrf_spim_frequency_set(_spim.p_reg, clockFreq); to nrf_spim_frequency_set(_spim.p_reg, NRF_SPIM_FREQ_32M);

I dont know why SPIClass::SPIClass(NRF_SPIM_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI) get wrong value of *p_spi. I hope that someone will tell me about this

dhalbert commented 2 years ago

It appears you are using https://github.com/moononournation/Arduino_GFX, not the standard SPI support. Looking at that library briefly, it appears to have no provision for 32MHz SPI on nRF52840.

Fantonrko commented 2 years ago

It appears you are using https://github.com/moononournation/Arduino_GFX, not the standard SPI support. Looking at that library briefly, it appears to have no provision for 32MHz SPI on nRF52840.

But i tested it on previous message. Its work fine!

dhalbert commented 2 years ago

I'm confused. You had to make some modifications to get it to do 32MHz. Try a simpler example that doesn't use https://github.com/moononournation/Arduino_GFX. Just create a regular Arduino SPI object, send something on it, and look at the clock rate. Don't use any libraries.

Fantonrko commented 2 years ago

I'm confused. You had to make some modifications to get it to do 32MHz. Try a simpler example that doesn't use https://github.com/moononournation/Arduino_GFX. Just create a regular Arduino SPI object, send something on it, and look at the clock rate. Don't use any libraries.

I transfer one byte without unnecessary libraries, at a speed of 32MHz on my oscilloscope. It works :)

lyusupov commented 2 years ago

@Fantonrko

Your sketch is using 8 MHz SPIM2 (SPI instance associated with _ArduinoHWSPI call by default) :

Arduino_DataBus *bus = new Arduino_HWSPI(38, 40); // DC and SS pin

To utilize 32 MHz SPIM3 you need to specify SPI1 instance explicitly:

Arduino_DataBus *bus = new Arduino_HWSPI(38, 40, SPI1);

See this ticket https://github.com/moononournation/Arduino_GFX/issues/73 for details.

hathach commented 2 years ago

I dont know why SPIClass::SPIClass(NRF_SPIM_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, uint8_t uc_pinMOSI) get wrong value of *p_spi. I hope that someone will tell me about this

Because you assign the SPIM3 to SPI1 when modifying the variant.h

#define SPI_INTERFACES_COUNT 2
#define SPI_32MHZ_INTERFACE  1

revert the change in the variant. feather nrf52840 as stock assign SPM3 to SPI or change the SPI_32MHZ_INTERFACE = 0. And as @lyusupov pointed out, this is just a matter of mis-matched variant configure. This issue can be now closed since it isn't SPI lib bug.