Squashed commit of the following:
commitc6fd825e39Author: AlexanderHD27 <alexander@hal> Date: Wed Nov 6 23:14:14 2024 +0100 Moved CAN Interface code to comment libary folder with symlink commite7a0035041Author: AlexanderHD27 <alexander@hal> Date: Wed Nov 6 22:01:28 2024 +0100 Got MCP2521 to work commit4bfb1f533eAuthor: AlexanderHD27 <alexander@hal> Date: Wed Oct 16 21:29:35 2024 +0200 Did something to YGantryMount. It works. trust me commit5683168a47Author: AlexanderHD27 <alexander@hal> Date: Wed Oct 16 21:28:36 2024 +0200 Implemented Command-Level Interaction with CAN Interface commit9c0c676be8Author: AlexanderHD27 <alexander@hal> Date: Mon Oct 14 09:20:37 2024 +0200 Added Vscode Profile file commitb150a905a3Author: AlexanderHD27 <alexander@hal> Date: Mon Oct 14 09:19:00 2024 +0200 Implemented Low Level Compunications commit7eebf619aeAuthor: AlexanderHD27 <alexander@hal> Date: Mon Oct 7 14:46:15 2024 +0200 Created Head Pipe Mount commit93c40e1805Author: AlexanderHD27 <alexander@hal> Date: Mon Oct 7 14:44:11 2024 +0200 First Revision of YGantryMount commit91c2125458Author: AlexanderHD27 <alexander@hal> Date: Thu Oct 3 19:52:37 2024 +0200 Added Kicad Backups 2 gitignore commit096a6c18d6Author: AlexanderHD27 <alexander@hal> Date: Thu Oct 3 19:49:21 2024 +0200 Created ESP-IDF for can-interface commit48fded7981Author: AlexanderHD27 <alexander@hal> Date: Sat Sep 28 19:54:29 2024 +0200 Added files from Pico sdk to gitignore commitec5e5cbf13Author: AlexanderHD27 <alexander@hal> Date: Sat Sep 14 21:09:50 2024 +0200 Create Marker for position Calibration commit58d31964b2Author: AlexanderHD27 <alexander@hal> Date: Wed Sep 11 23:32:55 2024 +0200 Upgrade to pico SDK 2.0.0
This commit is contained in:
6
can-interface/main/CMakeLists.txt
Executable file
6
can-interface/main/CMakeLists.txt
Executable file
@@ -0,0 +1,6 @@
|
||||
idf_component_register(SRCS "hello_world_main.cpp"
|
||||
REQUIRES driver
|
||||
REQUIRES mcp2521
|
||||
REQUIRES mcp2521_hardware_interface
|
||||
REQUIRES spi_flash
|
||||
INCLUDE_DIRS "")
|
||||
7
can-interface/main/can-interface.code-workspace
Normal file
7
can-interface/main/can-interface.code-workspace
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": ".."
|
||||
}
|
||||
]
|
||||
}
|
||||
105
can-interface/main/hello_world_main.cpp
Executable file
105
can-interface/main/hello_world_main.cpp
Executable file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: CC0-1.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#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"
|
||||
|
||||
#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
|
||||
|
||||
void onRX(void *arg) {
|
||||
MCP2521 *mcp2521 = (MCP2521 *)arg;
|
||||
|
||||
rx_info info = mcp2521->get_rx_id(MCP2521_RX_BUFFER::RXB0);
|
||||
uint8_t data[8];
|
||||
|
||||
mcp2521->read_rx_buf(MCP2521_RX_BUFFER::RXB0, MCP2521_BUFFER_TYPE::DATA, data, info.length);
|
||||
|
||||
printf("RX: (%x) ", info.id);
|
||||
for (int i = 0; i < info.length; i++) {
|
||||
printf("%x ", data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
extern "C" 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);
|
||||
|
||||
|
||||
spi_bus_config_t spi_bus;
|
||||
|
||||
MCP2521_Hardware_Handle_ESP hardware_mcp2521(
|
||||
VSPI_HOST,
|
||||
&spi_bus,
|
||||
SPI_PIN_MOSI,
|
||||
SPI_PIN_MISO,
|
||||
SPI_PIN_SCLK,
|
||||
SPI_PIN_CS0,
|
||||
CAN_INT_PIN
|
||||
);
|
||||
|
||||
MCP2521 mcp2521(&hardware_mcp2521);
|
||||
|
||||
uint8_t data[4] = {0xf0, 0x42, 0x13, 0x37};
|
||||
|
||||
gpio_set_level(EXTERNAL_TRIGGER, false);
|
||||
mcp2521.reset();
|
||||
mcp2521.enable_interrupts(true, true, true, true, true, true, true, true);
|
||||
|
||||
mcp2521.register_rx0_handler(onRX, &mcp2521);
|
||||
mcp2521.register_rx1_handler(onRX, &mcp2521);
|
||||
mcp2521.set_mode_of_operation(MCP2521_OPERATION_MODE::LOOPBACK, true);
|
||||
|
||||
vTaskDelay(3 / portTICK_PERIOD_MS);
|
||||
|
||||
mcp2521.prepare_tx(
|
||||
MCP2521_TX_BUFFER::TXB0, 0x042, data, 4, false, false);
|
||||
|
||||
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
|
||||
mcp2521.set_tx_id(MCP2521_TX_BUFFER::TXB0, 0x041, false);
|
||||
mcp2521.request_to_send(MCP2521_TX_BUFFER::TXB0);
|
||||
|
||||
|
||||
vTaskDelay(20 / portTICK_PERIOD_MS);
|
||||
|
||||
bool flag = true;
|
||||
while (true) {
|
||||
gpio_set_level(LED_PIN, flag);
|
||||
flag = !flag;
|
||||
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user