Feather M0 Adalogger - 2xSPI?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bastler59
 
Posts: 18
Joined: Sun Nov 28, 2021 3:37 pm

Feather M0 Adalogger - 2xSPI?

Post by bastler59 »

Hi,

during the last 2 years I tried out several ESP32-boards. I used Visual Code with PlatformIO and ESP-IDF (instead of Arduino). This is an advantage and a curse together. Because the ESP32 has more input/output lines, sensors, ADC/DACs, interfaces (I2C, I2S, SPI, serial) than physical pins, you have to define GPIOs for a device - for example MOSI, MISO, CLK and CS, if you want to attach a display or a card reader. By default ESP32 has 2 SPI channels called HSPI and VSPI with 2times MOSI, MISO, CLK and CS.


Now I want to try M0 Adalogger board to read sensor values and store them on a SD card. Showing data on a display would be also nice.

I know pin out https://learn.adafruit.com/assets/46243 - MOSI = 24, MISO = 22, CLK = 24, CS = 4 for SD card. BTW: I can use Pin7 (CD) to detect, if a card is inside slot or not? Low level without a card?

A look into ATSAMD21G18 datasheet tells me:
There are up to six instances of the serial communication interface (SERCOM) peripheral.
A SERCOM can be configured to support a number of modes: I2C, SPI, and USART.
And:
Master with multiple slaves in parallel is only available when Master Slave Select Enable (CTRLB.MSSEN) is set to zero and hardware SS control is disabled. If the bus consists of several SPI slaves, an SPI master can use general purpose I/O pins to control the SS line to each of the slaves on the bus, as shown in Multiple Slaves in Parallel. In this configuration, the single selected SPI slave will drive the tri-state MISO line.
So how is the best way to connect a display to M0 Adalogger and how a sketch should control both SD card and display together?

I take a look at https://learn.adafruit.com/adafruit-2-4 ... ng/pinouts, which describes a TFT display with SD card. For SAMD21 M0 this TFT-board uses TFT_CS is pin #9, TFT_DC is pin #10.

So MOSI, MISO and CLK are shared?
What effect has this for the sketch?
For accessing a SD card you define a variable sd of class SdFat and call the sd.begin(..)-method. One parameter is number of select pin. I can't remember to see an example sketch using sd.end()-method.

Let's assume, that at the beginning I want to check, if a SD card is present and place a "SD card ok" on the display.

Do I have to begin communication with SD card, end communication, open communication to display by something like tft.begin() and end this before I can write date to SD card? So all the time a permanent begin/end for both devices?

Bye
Jürgen

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather M0 Adalogger - 2xSPI?

Post by adafruit_support_carter »

So MOSI, MISO and CLK are shared?
Yes. That is how SPI is designed to work. Each device shares those pins. But - each device needs a dedicated chip select (CS) pin.

User avatar
bastler59
 
Posts: 18
Joined: Sun Nov 28, 2021 3:37 pm

Re: Feather M0 Adalogger - 2xSPI?

Post by bastler59 »

Hi,

not really.

At the moment I have a RTC and a Sharp monochrome LCD connected to my Adafruit Feather M0 Adalogger.
Getting date and time from RTC and display it on LCD works.

Problems occur when I access cardslot by SdFAT-library. I' using that typical sd.begin() and myFile.open() to write something on microSD card. But after myFile.close() and even sd.end() I can access display only after a new display.begin().

I'm not sure, if SdFAT makes an exclusive connection to SPI?
I found this in SdFatConfig.h:

Code: Select all

/**
 * Set ENABLE_DEDICATED_SPI non-zero to enable dedicated use of the SPI bus.
 * Selecting dedicated SPI in SdSpiConfig() will produce better
 * performance by using very large multi-block transfers to and
 * from the SD card.
 *
 * Enabling dedicated SPI will cost extra flash and RAM.
 */
#ifndef ENABLE_DEDICATED_SPI
#if defined(__AVR__) && FLASHEND < 0X8000
// 32K AVR boards.
#define ENABLE_DEDICATED_SPI 1
#else  // defined(__AVR__) && FLASHEND < 0X8000
// All other boards.
#define ENABLE_DEDICATED_SPI 1
#endif  // defined(__AVR__) && FLASHEND < 0X8000
#endif  // ENABLE_DEDICATED_SPI
Do I have to place a #define ENABLE_DEDICATED_SPI 0 in my code (before include for SdFAT)?
And what do Adafruit makes different in their fork of SdFAT?

Jürgen

User avatar
bastler59
 
Posts: 18
Joined: Sun Nov 28, 2021 3:37 pm

Re: Feather M0 Adalogger - 2xSPI?

Post by bastler59 »

Looks like I can't edit a post several minutes after posting ...
bastler59 wrote: Do I have to place a #define ENABLE_DEDICATED_SPI 0 in my code (before include for SdFAT)?
With such a #define I get a compile error, but no information, what is wrong (verbose is on).
Without I can compile and upload and sketch works.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”