dedalqq / esp32-mcp2515

MCP2515 CAN interface library for using on esp32/esp8266
MIT License
51 stars 16 forks source link

VSPI or HSPI #1

Open ale1800 opened 2 years ago

ale1800 commented 2 years ago

Hi, great work! How do I choose to use HSPI or VSPI on esp32? thanks in advance

GiovanniRaseraF commented 2 years ago

Yout need to configure the esp32 spi with this parameters: If you need to use ESP32 SIM800 i created a fork for that board: ESP32SIM800 MCP2515

#define MISO  19
#define MOSI  23
#define SCK   18
#define SS    5
 // ESP32SIM800 START
    esp_err_t ret;
    spi_bus_config_t buscfg={};
    buscfg.miso_io_num=MISO;
    buscfg.mosi_io_num=MOSI;
    buscfg.sclk_io_num=SCK;
    buscfg.quadwp_io_num=-1;
    buscfg.quadhd_io_num=-1;  

    spi_device_interface_config_t devcfg={};

    devcfg.clock_speed_hz=1*1000*1000,               //Clock out at 1 MHz
    devcfg.mode=0,                                   
    devcfg.spics_io_num=SS,                          //Chip select
    devcfg.queue_size=7,

    //Initialize the SPI bus
    ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1);
    assert(ret==ESP_OK);
    //Attach the MCP2515 to the SPI bus
    ret=spi_bus_add_device(HSPI_HOST, &devcfg, &*spi);
    assert(ret==ESP_OK);
    // ESP32SIM800 END 
Kunaalkk1 commented 1 year ago

Hi @GiovanniRaseraF, firstly, thanks for sharing this library. I have a PCB with ESP32 mounted on it, along with MCP2515 CAN Converter. My MISO, MOSI, CLK, SS are 12, 13, 14, 15 respectively, and I can't change that. Please tell me how to use this SPI Host for MCP2515.

P.S. I am using ESP-IDF with the above program in C++ with Arduino as component.

Code:

#include "mcp2515.h"
#include "esp_system.h"
#include "driver/spi_master.h"
#include "Arduino.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

spi_device_handle_t spi;

struct can_frame frame;

extern "C" void app_main(void)
{
    initArduino();
    MCP2515 spi_can(&spi);

    spi_can.setBitrate(CAN_500KBPS, MCP_8MHZ);
    spi_can.setNormalMode();

    printf("spi_can configured");

    while (true)
    {
        if (spi_can.readMessage(&frame) == MCP2515::ERROR_OK)
        {
            printf("Data received from ID: ");
            printf("%lx", frame.can_id);
        }

        vTaskDelay(10 / portTICK_PERIOD_MS);
    }
}

Regards, Kunaal

GiovanniRaseraF commented 1 year ago

I don't think i am able to help you, what i can tell you is that you in the code you did not configure the spi interface: for example my spi interface in configured in this way

[image: b6ac36cc-30f5-4f35-aa37-83247bc597fd.png]

if you are using my repo code your PINS will be changed to my configuration, so be careful.

This is all I know, if you somehow find the solution please let me know so we can learn together.

GR

Il giorno mer 5 apr 2023 alle ore 08:26 Kunaal Kiran Kumar < @.***> ha scritto:

Hi @GiovanniRaseraF https://github.com/GiovanniRaseraF, firstly, thanks for sharing this library. I have a PCB with ESP32 mounted on it, along with MCP2515 CAN Converter. My MISO, MOSI, CLK, SS are 12, 13, 14, 15 respectively, and I can't change that. Please tell me how to use this SPI Host for MCP2515.

P.S. I am using ESP-IDF with the above program in C++ with Arduino as component.

Code:

include "mcp2515.h"

include "esp_system.h"

include "driver/spi_master.h"

include "Arduino.h"

include "freertos/FreeRTOS.h"

include "freertos/task.h"

spi_device_handle_t spi;

struct can_frame frame;

extern "C" void app_main(void) { initArduino(); MCP2515 spi_can(&spi);

spi_can.setBitrate(CAN_500KBPS, MCP_8MHZ);
spi_can.setNormalMode();

printf("spi_can Configurated");

while (true)
{
    if (spi_can.readMessage(&frame) == MCP2515::ERROR_OK)
    {
        printf("Data received from ID: ");
        printf("%lx", frame.can_id);
    }

    vTaskDelay(10 / portTICK_PERIOD_MS);
}

}

Regards, Kunaal

— Reply to this email directly, view it on GitHub https://github.com/dedalqq/esp32-mcp2515/issues/1#issuecomment-1496981620, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKZI32NG7XKCOO34HZELNSTW7UF77ANCNFSM5WAXB3MQ . You are receiving this because you were mentioned.Message ID: @.***>

--

[image: facebook] https://www.facebook.com/HuracanMarine/

[image: twitter] https://twitter.com/huracanmarine

[image: linkedin] https://www.linkedin.com/company/93355120/admin/?feedType=following

[image: instagram] https://www.instagram.com/huracanmarine/

Giovanni Rasera

IT Engineer

Huracan Marine s.r.l.

[image: mobilePhone] (+39) 340 211 1337 <(+39)+340+211+1337> [image: emailAddress] @.*** [image: website] www.huracanmarine.com [image: address] Via I. Castellarin 2/A, 33050 Ronchis (UD), ITALY

Kunaalkk1 commented 1 year ago

I am sorry about that, @GiovanniRaseraF. I made a mistake, the SPI-CAN converter was not on VSPI, it was on HSPI instead. That is why it was not working. I checked our PCB's schematics and corrected the Configuration. My CAN Controller works perfectly well now.

Thanks.