adafruit / adafruit/Adafruit_nRF52_Arduino
SPIM3 draws extra current when disabled
- Dominant language
- C
- Stars
- 699
- Forks
- 570
- PR merge metrics
- No merged PRs in 30d
Description
### Operating System
Windows 11
### IDE version
Arduino 2.3.4
### Board
Feather nRF52840 Express
### BSP version
1.6.1
### Sketch
SD/listfiles
I'm using the Adafruit ADAlogger FeatherWing - SD and RTC
The card select needs to be set to 10.
### What happened ?
My project is using the nRF52840 Express and a Adafruit lipo battery (500mAHr) and attempting to reduce current to extend the battery between charges. Discovered about 1mA increase of current from before SD.begin() and after its complete. Using the Nordic PPK2. Here is the current before the SD.begin (see the windowed area).

And the current after SD.begin is complete

I've determind this problem to be Nordics hardware errata: #[195 ](https://docs.nordicsemi.com/bundle/errata_nRF52840_Rev3/page/ERR/nRF52840/Rev3/latest/anomaly_840_195.html) but the suggested errata fix is buried into code found in 1.6.1\cores\nRF5\nordic\nrfx\drivers\src\nrfx_spim.c as shown below
void nrfx_spim_uninit(nrfx_spim_t const * p_instance) {
...
#ifdef USE_WORKAROUND_FOR_ANOMALY_195
if (p_spim == NRF_SPIM3)
{
*(volatile uint32_t *)0x4002F004 = 1;
}
#endif
...
}
but apparently the #define is not defined when this library function is compiled. If I manually add this code at some time after the file listing is complete, current reduces to the before SD.begin value. nrfx_spim_uninit() is called in the spi_transaction_end() function as each individual SPI transaction occurs, hence allowing me to use multiple SPI devices. Can the USE_WORKAROUND_FOR_ANOMALY_195 be defined when this library is compiled?
I see from Adafruit design guides that use of SPIM3 on battery powered projects is not recommended. Section ["Using nRF52840 SPI on Battery Power"](https://cdn-learn.adafruit.com/downloads/pdf/introducing-the-adafruit-nrf52840-feather.pdf). Can the guide suggest solutions other than circuitpython solutions.
For a temporary fix, I've followed the solution of switching to SPIM2 by defining [#define SPI_32MHZ_INTERFACE 1 ](https://github.com/adafruit/Adafruit_nRF52_Arduino/issues/773#issuecomment-1583626383 ) in my .ino file.
### How to reproduce ?
1. Run the example listfiles while monitoring with PPK2.
### Debug Log
_No response_
### Screenshots
_No response_
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in 1.6.1/cores/nRF5/nordic/rfx/drivers/src/nrfx_spim.c, especially nrfx_spim_uninit(), and trace how USE_WORKAROUND_FOR_ANOMALY_195 is defined during the library build. Reproduce with the SD/listfiles example on an nRF52840 Express while monitoring current with the Nordic PPK2. Done means the workaround is enabled for the relevant build and the post-SD.begin current returns to the pre-initialization level without requiring a sketch-only workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100