/* * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ #include #include #include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "freertos/queue.h" #include "esp_chip_info.h" #include "esp_flash.h" #include "esp_system.h" #include "driver/gpio.h" #include "driver/spi_master.h" #include "mcp2521.hpp" #include "reg.hpp" #define SPI_PIN_CS0 GPIO_NUM_5 #define SPI_PIN_SCLK GPIO_NUM_18 #define SPI_PIN_MISO GPIO_NUM_19 #define SPI_PIN_MOSI GPIO_NUM_23 #define CAN_INT_PIN GPIO_NUM_21 #define EXTERNAL_TRIGGER GPIO_NUM_26 #ifdef __cplusplus extern "C" { #endif void app_main() { printf("Hello world!\n"); const gpio_num_t LED_PIN = GPIO_NUM_2; gpio_set_direction(LED_PIN, GPIO_MODE_OUTPUT); gpio_set_direction(EXTERNAL_TRIGGER, GPIO_MODE_OUTPUT); gpio_set_level(EXTERNAL_TRIGGER, true); vTaskDelay(100 / portTICK_PERIOD_MS); gpio_set_level(EXTERNAL_TRIGGER, false); spi_bus_config_t spi_bus; MCP2521_SPI_Interface mcp2521_spi( VSPI_HOST, &spi_bus, SPI_PIN_MOSI, SPI_PIN_MISO, SPI_PIN_SCLK, SPI_PIN_CS0, CAN_INT_PIN ); mcp2521_spi.reset(); printf("%x\n", mcp2521_spi.read_reg(MCP2521_CANCTRL)); uint8_t data[16]; mcp2521_spi.read_reg(MCP2521_CANSTAT, data, 16); for(int i=0; i<0x10; i++) { printf("%x ", i); for(int j=0; j<8; j++) { printf("%u", (data[i] >> (7-j)) & 1); } printf("\n"); } gpio_set_level(EXTERNAL_TRIGGER, true); bool flag = true; while (true) { gpio_set_level(LED_PIN, flag); flag = dummy_function(flag); vTaskDelay(100 / portTICK_PERIOD_MS); } } #ifdef __cplusplus } #endif