loboris / ESP32_TFT_library

Full featured TFT library for ESP32 with demo application
564 stars 219 forks source link

Connect MAX6675 and "spi_dma_chan" failed #86

Open GermanSheepDog opened 4 years ago

GermanSheepDog commented 4 years ago

Hello, I like to connect a MAX6675 at my M5Stack to read my temperature of my BBQ. I small demo with a Arduino library worked fine but only without the display of the M5Stack.

I create a new init procedure:

#define MAX6675_MISO 19
#define MAX6675_SCK  18
#define MAX6675_CS   2
#define MAX6675_MOSI -1

static spi_lobo_device_handle_t max_spi;//max_spi; // SPI handle.

void MAX_PinsInit()
{
    // Route all used pins to GPIO control
    gpio_pad_select_gpio(MAX6675_CS);
//    gpio_pad_select_gpio(MAX6675_MISO);
//    gpio_pad_select_gpio(MAX6675_SCK);

//    gpio_set_direction(MAX6675_MISO, GPIO_MODE_INPUT);
//    gpio_set_pull_mode(MAX6675_MISO, GPIO_PULLUP_ONLY);
    gpio_set_direction(MAX6675_CS, GPIO_MODE_OUTPUT);
//    gpio_set_direction(MAX6675_SCK, GPIO_MODE_OUTPUT);
}

bool init_Max6675() {
  MAX_PinsInit();
  // ====  CONFIGURE SPI DEVICES(s)  ====================================
  spi_lobo_device_handle_t spi;
  spi_lobo_bus_config_t buscfg={
      .miso_io_num=MAX6675_MISO,                // set SPI MISO pin
      .mosi_io_num=MAX6675_MOSI,              // set SPI MOSI pin
      .sclk_io_num=MAX6675_SCK,               // set SPI CLK pin
      .quadwp_io_num=-1,
      .quadhd_io_num=-1,
      //.max_transfer_sz = 6*1024,
  };
  spi_lobo_device_interface_config_t devcfg={
      .clock_speed_hz=10000, //8000000,                // Initial clock
      .mode=0,                                // SPI mode 0
      .spics_io_num=-1,                       // we will use external CS pin
      .spics_ext_io_num=MAX6675_CS,           // external CS pin
      .flags=0,//LB_SPI_DEVICE_HALFDUPLEX,        
  };

  printf("Pins used: miso=%d, mosi=%d, sck=%d, cs=%d\r\n", MAX6675_MISO, MAX6675_MOSI, MAX6675_SCK, MAX6675_CS);

  // ==================================================================
  // ==== Initialize the SPI bus and attach the MAX6675 to the SPI bus ====
  esp_err_t ret=spi_lobo_bus_add_device(HSPI_HOST, &buscfg, &devcfg, &spi);
  assert(ret==ESP_OK);
  printf("SPI: MAX6675 device added to spi bus (%d)\r\n", HSPI_HOST);
  max_spi = spi;

  // ==== Test select/deselect ====
  ret = spi_lobo_device_select(spi, 1);
  assert(ret==ESP_OK);
  ret = spi_lobo_device_deselect(spi);
  assert(ret==ESP_OK);

  printf("SPI: attached MAX6675 device, speed=%u\r\n", spi_lobo_get_speed(spi));
  printf("SPI: bus uses native pins: %s\r\n", spi_lobo_uses_native_pins(spi) ? "true" : "false");
  return ret;
}

The pins MAX6675_MISO and MAX6675_SCK are shared with display of M5Stack. Only the MAX6675_CS is an individual pin for MAX6675.

If I call init_Max6675() I got this error:

assertion "spi_dma_chan_enabled & DMA_CHANNEL_ENABLED(dma_chan)" failed: file "/Users/<username>/esp/M5Stack_70_Sonos/components/pg_display/spi_master_lobo.c", line 338, function: spi_lobo_dma_chan_free

abort() was called at PC 0x400d70a3 on core 0
0x400d70a3: __assert_func at /builds/idf/crosstool-NG/.build/HOST-x86_64-apple-darwin12/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:62 (discriminator 8)

Have anyone an idea what I can do? Was the init of new device outside of spi_master_lobo.c correct?