<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5 Stamp C3 -&gt; Asign hardware pins for SPI]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I would appreciate if someone could help me set up the SPI on the hardware pins of the Stamp C3 to connect to a display with the ST7789 driver.</p>
<p dir="auto">According to the documentation: page 169 [<a href="https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf#spi" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf#spi</a>], the pins that can be assigned with the MUX IO directly are these, integrated into my initialization code.</p>
<p dir="auto">#include &lt;Adafruit_GFX.h&gt;    // Core graphics library by Adafruit<br />
#include "Arduino_ST7789.h" // Hardware-specific library for ST7789 (with or without CS pin)</p>
<p dir="auto">#define TFT_MISO -1<br />
#define TFT_MOSI GPIO_NUM_7 //FSPID en pin fisico 13 de CPU ESP32-C3<br />
#define TFT_SCLK GPIO_NUM_6 //FSPICLK en pin fisico 12 de de CPU ESP32-C3<br />
#define TFT_CS   GPIO_NUM_5  // Chip select control pin //FSPIWP en pin 10 de CPU ESP32-C3<br />
#define TFT_DC   GPIO_NUM_4  // Data Command control pin (8 Bits TFT 1.54 Soldable) //FSPIHD en pin fisico 9 de CPU ESP32-C3<br />
//#define TFT_DC   -1  // 9 bits TFT 1.54 Display con cable<br />
#define TFT_RST  GPIO_NUM_0  // Reset pin (could connect to RST pin) //en pin fisico 4 de CPU ESP32-C3</p>
<p dir="auto">//You can use different type of hardware initialization<br />
//using hardware SPI (11, 13 on UNO; 51, 52 on MEGA; ICSP-4, ICSP-3 on DUE and etc)<br />
//Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST); //for display without CS pin<br />
Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_CS); //for display with CS pin<br />
//or you can use software SPI on all available pins (slow)<br />
//Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK); //for display without CS pin<br />
//Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_CS); //for display with CS pin<br />
// Arduino_ST7789 tft = Arduino_ST7789(-1, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_CS); //for display with CS pin and DC via 9bit SPI</p>
<p dir="auto">void setup(void)<br />
{<br />
Serial.begin(9600);<br />
Serial.println();<br />
Serial.print("ST7789 TFT Test...");</p>
<pre><code>tft.init(240, 320);   //initialize a ST7789 chip, 240x240 pixels cambiar a (#define ST7789_240x240_YSTART 80) en Arduino_ST7789.h
tft.setRotation(0);   //Posicion con cinta o cable por arriba.
tft.setTextWrap(false);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.setCursor(27,16);
tft.print("1");
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void  loop()<br />
{<br />
....<br />
}</p>
<p dir="auto">Thank you,</p>
]]></description><link>https://community.m5stack.com/topic/6206/m5-stamp-c3-asign-hardware-pins-for-spi</link><generator>RSS for Node</generator><lastBuildDate>Tue, 17 Mar 2026 09:14:04 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6206.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Mar 2024 06:51:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5 Stamp C3 -&gt; Asign hardware pins for SPI on Tue, 02 Apr 2024 08:24:16 GMT]]></title><description><![CDATA[<p dir="auto">Hello Felix,</p>
<p dir="auto">After reviewing everything, I have discovered that the issue lies in the initialization performed in the Arduino_ST7789 library. In the Arduino_ST7789.cpp file, SPI.begin(); is used when to utilize hardware SPI, it should be initialized with SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, TFT_CS);</p>
<p dir="auto">"// Constructor when using hardware SPI.  Faster, but must use SPI pins<br />
// specific to each board type (e.g. 11,13 for Uno, 51,52 for Mega, etc.)<br />
// Parece que solo vale para 4-wire. Adaptar a 3-wire.<br />
Arduino_ST7789::Arduino_ST7789(int8_t dc, int8_t rst, int8_t cs)<br />
: Adafruit_GFX(ST7789_TFTWIDTH, ST7789_TFTHEIGHT) {<br />
_cs   = cs;<br />
_dc   = dc;<br />
_rst  = rst;<br />
_hwSPI = true; <strong>//THIS LINE APPLY HARDWARE SPI</strong><br />
_SPI9bit = false;<br />
_sid  = _sclk = -1;<br />
}"</p>
<p dir="auto">After call<br />
"// Initialization code common to all ST7789 displays<br />
void Arduino_ST7789::commonInit(const uint8_t *cmdList) {......."<br />
in this part into<br />
"if(_hwSPI)<br />
{ // Using hardware SPI<br />
#if defined (SPI_HAS_TRANSACTION)<br />
<a href="//SPI.begin" target="_blank" rel="noopener noreferrer nofollow ugc">//SPI.begin</a>(); <strong>//THIS LINE IS BAD FOR HARDWARE INIT</strong><br />
SPI.begin(TFT_SCLK, TFT_MISO, TFT_MOSI, TFT_CS);  <strong>// BY ME</strong><br />
mySPISettings = SPISettings(48000000, MSBFIRST, SPI_MODE2); <strong>// BY ME</strong>"</p>
<p dir="auto">Always in the file.ino define pins:<br />
"<br />
#define TFT_MISO -1<br />
#define TFT_MOSI 7<br />
#define TFT_SCLK 6<br />
#define TFT_CS   5<br />
#define TFT_DC   4<br />
#define TFT_RST  0<br />
"<br />
call with:<br />
"Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_CS); <strong>//for display with CS pin // &lt;--- MODO SPI HARDARE (4-wire)</strong>"</p>
<p dir="auto">In summary... I think that It wasn't working because the SPI was not initialized with the pin parameters and Mode 2 (function 2 of the IO_MUX) that activates pins 4, 5, 6, 7 (see page 169 of the ESP32-C3 datasheet). In the schematic, it can be seen that M5stack associates the SPI with pins 19, 20, 21, 22, 23, 24 in Mode 0 (function 0 of the IO_MUX), which needs to be initialized correctly...</p>
<p dir="auto">For drawing text or lines, etc., using Software SPI isn't a problem. However, if images, fillscreen();, or other graphical elements are displayed, then Hardware SPI is necessary (not necesary 48Mhz, i put in the code), or else everything will be very slow on the screen.</p>
<p dir="auto">datasheet:<br />
<a href="https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf</a></p>
<p dir="auto">Schematic M5Stack Stamp C3:<br />
<a href="https://docs.m5stack.com/en/core/stamp_c3" target="_blank" rel="noopener noreferrer nofollow ugc">https://docs.m5stack.com/en/core/stamp_c3</a></p>
<p dir="auto">I am happy!! It works now!!.</p>
<p dir="auto">Thank you for your time and attention.<br />
Best regards,</p>
]]></description><link>https://community.m5stack.com/post/24648</link><guid isPermaLink="true">https://community.m5stack.com/post/24648</guid><dc:creator><![CDATA[ferqtek]]></dc:creator><pubDate>Tue, 02 Apr 2024 08:24:16 GMT</pubDate></item><item><title><![CDATA[Reply to M5 Stamp C3 -&gt; Asign hardware pins for SPI on Wed, 20 Mar 2024 06:11:56 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/94364">@ferqtek</a></p>
<p dir="auto">"by the speed I have", e.g. 600 kHz. Is that what you measure?</p>
<p dir="auto">What exactly is giving you errors? Building the spi master example or running it on an ESP32C3?</p>
<p dir="auto">What do you mean M5Stack left the default pins unconnected to the outside? Do you mean the SPI default pins? As far as I can tell, GPIOs 4, 5, 6, 7 and 10 are the default SPI pins for ESP32C3 and they are all available on the M5StampC3. (MISO - GPIO2 is not available, but also not needed for driving an LCD.)</p>
<p dir="auto">BTW: I think you might make your life to hard. If a clock frequency of 6 MHz is what your looking for it doesn't matter whether you are using hardware or software SPI.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/24453</link><guid isPermaLink="true">https://community.m5stack.com/post/24453</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Wed, 20 Mar 2024 06:11:56 GMT</pubDate></item><item><title><![CDATA[Reply to M5 Stamp C3 -&gt; Asign hardware pins for SPI on Tue, 19 Mar 2024 11:27:43 GMT]]></title><description><![CDATA[<p dir="auto">Hello.</p>
<p dir="auto">The truth is, I don't know if it's working for only one line to be routed by the IOMUX. But the speed I have is 600KHz, and for drawing on a display properly, it should be higher (6MHz). I found something on Espressif's website but give me various errors...<br />
It seems like the best option I've found. If you could indicate why it's giving errors and if it could be a good path, I would appreciate it. Thank you.</p>
<p dir="auto"><a href="https://github.com/espressif/esp-idf/blob/f8bda324ecde58214aaa00ab5e0da5eea9942aaf/examples/peripherals/spi_master/main/spi_master_example_main.c" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/espressif/esp-idf/blob/f8bda324ecde58214aaa00ab5e0da5eea9942aaf/examples/peripherals/spi_master/main/spi_master_example_main.c</a></p>
<p dir="auto">NOTE: I can't find any example on the web for this ESP32_C3 that works, and it's disappointing that M5Stack doesn't have examples for it when they've left the default pins unconnected to the outside.</p>
<p dir="auto">Best regards,</p>
]]></description><link>https://community.m5stack.com/post/24435</link><guid isPermaLink="true">https://community.m5stack.com/post/24435</guid><dc:creator><![CDATA[ferqtek]]></dc:creator><pubDate>Tue, 19 Mar 2024 11:27:43 GMT</pubDate></item><item><title><![CDATA[Reply to M5 Stamp C3 -&gt; Asign hardware pins for SPI on Mon, 18 Mar 2024 10:25:50 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/94364">@ferqtek</a></p>
<p dir="auto">ok, I see. However it is stated <a href="https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/api-reference/peripherals/spi_master.html#gpio-matrix-and-io-mux" target="_blank" rel="noopener noreferrer nofollow ugc">here</a>:</p>
<p dir="auto"><em>When an SPI Host is set to 80 MHz or lower frequencies, routing SPI pins via the GPIO matrix will behave the same compared to routing them via IOMUX.</em></p>
<p dir="auto">What SPI bus frequency are you planning to use?</p>
<p dir="auto">It also states:</p>
<p dir="auto"><em>If at least one signal is routed through the GPIO matrix, then all signals will be routed through it.</em></p>
<p dir="auto">which I read as: if no signal is routed through the GPIO matrix then it is using IOMUX (but I could be wrong about that).</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/24427</link><guid isPermaLink="true">https://community.m5stack.com/post/24427</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Mon, 18 Mar 2024 10:25:50 GMT</pubDate></item><item><title><![CDATA[Reply to M5 Stamp C3 -&gt; Asign hardware pins for SPI on Mon, 18 Mar 2024 09:47:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/4037">@felmue</a> You can see that "//or you can use software SPI on all available pins (slow)". You example use this initialization  "Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_CS); //for display with CS pin".<br />
But I prefer to use hardware pins for faster performance, so you must use this initialization "Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST, TFT_CS); //for display with CS pin".<br />
and it doesn't work.</p>
<p dir="auto">I will now the steps for initialization at this link "<a href="https://github.com/m5stack/M5GFX/blob/5342c2b4528260beddc62d5656717e80b8375554/src/M5GFX.cpp#L1221" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/m5stack/M5GFX/blob/5342c2b4528260beddc62d5656717e80b8375554/src/M5GFX.cpp#L1221</a>"</p>
<p dir="auto">Thank you,</p>
]]></description><link>https://community.m5stack.com/post/24425</link><guid isPermaLink="true">https://community.m5stack.com/post/24425</guid><dc:creator><![CDATA[ferqtek]]></dc:creator><pubDate>Mon, 18 Mar 2024 09:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to M5 Stamp C3 -&gt; Asign hardware pins for SPI on Fri, 15 Mar 2024 08:49:05 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="mention plugin-mentions-user plugin-mentions-a" href="https://community.m5stack.com/uid/94364">@ferqtek</a></p>
<p dir="auto">please have a look at this <a href="https://embedded-things.blogspot.com/2021/11/esp32-c3arduino-esp32-to-display-on.html" target="_blank" rel="noopener noreferrer nofollow ugc">example</a> I found. It works for me using your GPIO defines like below:</p>
<pre><code>#define TFT_MISO -1
#define TFT_MOSI GPIO_NUM_7
#define TFT_SCLK GPIO_NUM_6
#define TFT_CS   GPIO_NUM_5
#define TFT_DC   GPIO_NUM_4
#define TFT_RST  GPIO_NUM_0

Adafruit_ST7789 tft_ST7789 = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
</code></pre>
<p dir="auto">Please note:</p>
<ul>
<li>the example uses the original <a href="https://github.com/adafruit/Adafruit-ST7735-Library" target="_blank" rel="noopener noreferrer nofollow ugc">Adafruit ST7855 library</a> (which also supports ST7789)</li>
<li>I used a 135x240 display for my test</li>
</ul>
<p dir="auto">BTW: if I do not define <code>sclk</code> and <code>mosi</code>, the default GPIOs seem to be incorrect for ESP32C3 as I get this error in the debug console:</p>
<pre><code>ST7789 TFT Test...[   112][E][esp32-hal-gpio.c:102] __pinMode(): Invalid pin selected
E (272) gpio: gpio_set_level(226): GPIO output gpio_num error
</code></pre>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/24395</link><guid isPermaLink="true">https://community.m5stack.com/post/24395</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Fri, 15 Mar 2024 08:49:05 GMT</pubDate></item></channel></rss>