Closed isuarezbel closed 2 years ago
Which version of the ttn-esp32 code are you using? It doesn't seem to be the latest master.
Thank you for the response. I am using the latest code (I downloaded it again just in case) with esp-idf 4.4. However, I think the problem may be that I am using an esp32-s2 which has some specific SPI particularities. I am not able to read the regversion at 0x42 with the ttn-esp32 readReg, but I can this way:
> // Initialize SPI bus
> spi_bus_config_t spi_bus_config = {
> .miso_io_num = 10,
> .mosi_io_num = 9,
> .sclk_io_num = 3,
> .quadwp_io_num = -1,
> .quadhd_io_num = -1,
> };
> esp_err_t err = spi_bus_initialize(SPI2_HOST, &spi_bus_config, SPI2_HOST);
> ESP_ERROR_CHECK(err);
>
> spi_device_interface_config_t devcfg = {
> .clock_speed_hz = 1 * 1000 * 1000, // Clock out at 10 MHz
> .mode = 3, // SPI mode 3
> // .address_bits = 8,
> .command_bits=8,
> .spics_io_num=20, //CS pin
> .queue_size=1,
> // .cs_ena_posttrans = 2 //Keep the CS low
> };
> ESP_ERROR_CHECK( spi_bus_add_device(SPI2_HOST, &devcfg, &adc_spi) );
>
> spi_transaction_t t;
> memset(&t, 0, sizeof(t));
> t.cmd = (0x42 & 0x7f);
> t.length = 8;
> t.flags = SPI_TRANS_USE_RXDATA;
> //t.flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA;
> ESP_ERROR_CHECK( spi_device_polling_transmit(adc_spi, &t) );
>
> ESP_LOGI(TAG, "LoRa chip version = 0x%02x\n", t.rx_data[0]);
>
>
> ESP_ERROR_CHECK(spi_bus_remove_device(adc_spi));
> ESP_ERROR_CHECK(spi_bus_free(SPI2_HOST));
>
>
I'm still confused regarding what code you are using since the error message "LMIC failed and stopped" is caused by an ASSERT statement. And at ../components/ttn-esp32/src/lmic/radio.c:1206, there is no ASSERT statement in the latest code (see https://github.com/manuelbl/ttn-esp32/blob/master/src/lmic/radio.c#L1206).
But the most likely cause is indeed that the SPI communication with the LoRa chip is not working. I haven't tested in an ESP32-S2 yet. I wasn't aware it is peculiar in that regard. Do you have any additional information?
I have probably made some debug comments and the lines have been modified. It corresponds to the ASSERT on line 1166 of the original code.
In the esp32-sw datasheet:
ESP32-S2 family features four SPI interfaces (SPI0, SPI1, SPI2 and SPI3). SPI0 and SPI1 can only be configured to operate in SPI memory mode; SPI2 can be configured to operate in SPI memory and general-purpose SPI modes; SPI3 can only be configured to operate in general-purpose SPI mode
Also from the spi master example here:
In the code they use SPI2_HOST to use FSPI on the ESP32-S2
De: Manuel Bl. @.> Enviado: jueves, 24 de marzo de 2022 21:09 Para: manuelbl/ttn-esp32 @.> Cc: Iñaki S @.>; Author @.> Asunto: Re: [manuelbl/ttn-esp32] ttn_hal error (Issue #49)
I'm still confused regarding what code you are using since the error message "LMIC failed and stopped" is caused by an ASSERT statement. And at ../components/ttn-esp32/src/lmic/radio.c:1206, there is no ASSERT statement in the latest code (see https://github.com/manuelbl/ttn-esp32/blob/master/src/lmic/radio.c#L1206).
But the most likely cause is indeed that the SPI communication with the LoRa chip is not working. I haven't tested in an ESP32-S2 yet. I wasn't aware it is peculiar in that regard. Do you have any additional information?
— Reply to this email directly, view it on GitHubhttps://github.com/manuelbl/ttn-esp32/issues/49#issuecomment-1078127632, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AUUWTWNBBTDQB4IZHJOVDKLVBTDYBANCNFSM5RNS7IWA. You are receiving this because you authored the thread.Message ID: @.***>
The master branch now contains a fix for the SPI communication. I've successfully verified it with an ESP32-S2.
The main problem was that the chip select (aka NSS) went low at the same time as the SPI clock started for the next transaction (instead of some 10 ns earlier). That's now fixed.
Additionally, I've changed some defaults in the examples so they are more likely to work both for the ESP32 and ESP32-S2.
I would appreciate it if you could try the latest code from the master branch.
It works great now on the ESP32-S2 with a RFM95. Thank you again for the library and for the great work!
I've been stuck at this point for a long time. Any idea why this might be happening? I am using a ESP32S2 with RFM95
Thank you very much for your great work. An esp-idf library for lorawan is really appreciated.