Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ItsyBitsy nRF52840 Express: Configure SPI CS pin?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by riverbend305 on Thu Jul 30, 2020 1:17 pm

Several questions:

(1) What is the default SPI CS pin of the hw SPI interface of the ItsyBitsy nRF52840 Express?

(2) How do I configure the default SPI CS pin to a different pin via a '*.ino' sketch?

(3) Some pins defined within the 'itsybitsy_nrf52840_express/variant.h' are
enclosed within parenthesis, others are not. Are the parens significant?

Examples:

******* WITHIN PAREN ********
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1

#define PIN_SPI_MISO (23)
#define PIN_SPI_MOSI (24)
#define PIN_SPI_SCK (25)

static const uint8_t SS = (5);
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK = PIN_SPI_SCK ;

******* WITHOUT PAREN ********

// QSPI Pins
#define PIN_QSPI_SCK 26
#define PIN_QSPI_CS 27
#define PIN_QSPI_IO0 28
#define PIN_QSPI_IO1 29
#define PIN_QSPI_IO2 30
#define PIN_QSPI_IO3 31

(4) The above examples suggest pin (5) is the default SPI CS pin ( referred to as 'SS' in the variant file ).
Is pin (5) referenced in the 'variant.h' file the same as pin 'A5' ( a digital GPIO that is also an analog input pin ) ?
or pin '5!' ( GPIO #5 which is a 5 volt output only pin that is not appropriate as a CS ) ?

(5) Where is the documentation that shows the mapping between how pins are labeled on the PCB and how they are identified in a '*.ino' sketch?

riverbend305
 
Posts: 3
Joined: Tue Jan 07, 2020 5:06 pm

Re: ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by adafruit_support_carter on Thu Jul 30, 2020 1:55 pm

(1) There is none. You can use any available GPIO pin.
(2) Change the #define
(3) It generally does not matter for simple defines. Beyond that, the details are a matter of discussion and relate to how the C preprocessor works. Also, you generally never need to worry about these low level files like variants.h unless you are doing development work.
(4) Pin 5 refers to digital pin 5. This pin would be labeled 5 on the board. A5 is different.
(5) Various files within the Board Support Package. Another low level detail that you generally do not need to worry about.

adafruit_support_carter
 
Posts: 16903
Joined: Tue Nov 29, 2016 2:45 pm

Re: ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by riverbend305 on Thu Jul 30, 2020 4:49 pm

Thanks for the reply.

Re #(2) 'Change the #define.'

Sorry, I should have been more specific.
# define (what string should I put here?) D2

riverbend305
 
Posts: 3
Joined: Tue Jan 07, 2020 5:06 pm

Re: ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by adafruit_support_carter on Thu Jul 30, 2020 4:57 pm

Can you provide more information on what you are trying to accomplish? What SPI device are you trying to use with the Itsy?

adafruit_support_carter
 
Posts: 16903
Joined: Tue Nov 29, 2016 2:45 pm

Re: ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by riverbend305 on Thu Jul 30, 2020 6:21 pm

I am trying access two devices, a TDK IMU and an AK compass. via SPI.

It looks to me that code in the ./adafruit/hardware/nrf52/0.20.5/variants/itsybitsy_nrf52840_express/variant.h
file hard codes the SPI CS or slave select (SS) pin to GPIO 5 via the following lines.

static const uint8_t SS = (5);
static const uint8_t MOSI = PIN_SPI_MOSI ;
static const uint8_t MISO = PIN_SPI_MISO ;
static const uint8_t SCK = PIN_SPI_SCK ;

GPIO pin 5 has a high output voltage (boosted to 5 volts by the design of the itsybitsy nRF52840 express ).
So pin 5 is not appropriate to drive an IMU powered at 3v.
And there doesn't seem anyway to change the variant.h pin assignment of SS via a define in an *.ino script.

The only way the above code can make sense to me is that SS is totally ignored by all other code in the SPI library
and the SPI library is not intended to control the SS (CS) output. That is, the decision to toggle a user defined SS GPIO pin
to select a given peripheral SPI device is the sole responsibility of the user's code.

Is this the way the itsybitsy nRF52840 express SPI library is intended to operate? or ..
Does one instantiate multiple SPI objects ( one for each peripheral SPI device ) each with a unique SS specified
and the SPI library then controls SS?

Oops! Just found the ./SPI/examples directory as I was composing this response and looking for files.
The examples therein show that the user's code is responsible for deciding when to change the state of SS ( slave select ).

Problem solved!

riverbend305
 
Posts: 3
Joined: Tue Jan 07, 2020 5:06 pm

Re: ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by adafruit_support_carter on Thu Jul 30, 2020 7:06 pm

The examples therein show that the user's code is responsible for deciding when to change the state of SS ( slave select ).

That is the correct general approach.

To make things easier, you can use something like this:
https://github.com/adafruit/Adafruit_BusIO
which will take care of negotiating access to the SPI bus as well as dealing with the chip select pin.

adafruit_support_carter
 
Posts: 16903
Joined: Tue Nov 29, 2016 2:45 pm

Re: ItsyBitsy nRF52840 Express: Configure SPI CS pin?

by Galeom12 on Wed Sep 16, 2020 9:48 am

The default SS GPIO pin it can be easly define to new one. I know that how spi works(https://911electronic.com/spi-communication-how-spi-works/) is the same as for any other defines.

Galeom12
 
Posts: 1
Joined: Wed Sep 16, 2020 9:45 am

Please be positive and constructive with your questions and comments.