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:
And: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.
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?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.
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