startet canbus implementation

This commit is contained in:
2025-06-13 09:57:34 +02:00
parent bd42d85783
commit ade514cbf3
13 changed files with 211 additions and 15 deletions

1
software/test_canbus/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build

View File

@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
]
}
],
"version": 4
}

View File

@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)
target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE ../lib/canbus.c)
target_include_directories(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../lib
)

View File

@@ -0,0 +1,9 @@
&usart1 {
status = "okay";
current-speed = <9600>;
modbus0 {
compatible = "zephyr,modbus-serial";
status = "okay";
// de-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */
};
};

View File

@@ -6,8 +6,5 @@ CONFIG_UART_CONSOLE=y # Console on USART1
#CONFIG_RTT_CONSOLE=y
#CONFIG_USE_SEGGER_RTT=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=n
CONFIG_MODBUS=y
CONFIG_MODBUS_ROLE_CLIENT=y
CONFIG_LOOPBACK_MODE=y
CONFIG_LOG_CAN_LEVEL=4

View File

@@ -0,0 +1,26 @@
/* Testing MODBUS functionality
This code initializes a Modbus client, sets the zero point and the 2m point for water level,
and reads the water level in both meters and millimeters.
It uses the Zephyr RTOS and its Modbus library to communicate with a Modbus server.
*/
#include <zephyr/logging/log.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include "canbus.h"
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
int main(void)
{
int rc;
rc = canbus_init();
if (rc != 0)
{
LOG_ERR("Failed to initialize CAN bus: %d", rc);
return rc;
}
LOG_INF("CAN bus initialized successfully");
return 0;
}