startet canbus implementation
This commit is contained in:
1
software/test_canbus/.gitignore
vendored
Normal file
1
software/test_canbus/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build
|
||||
16
software/test_canbus/.vscode/c_cpp_properties.json
vendored
Normal file
16
software/test_canbus/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE"
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
14
software/test_canbus/CMakeLists.txt
Normal file
14
software/test_canbus/CMakeLists.txt
Normal 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
|
||||
)
|
||||
9
software/test_canbus/boards/nucleo_f103rb.overlay
Normal file
9
software/test_canbus/boards/nucleo_f103rb.overlay
Normal 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 */
|
||||
};
|
||||
};
|
||||
@@ -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
|
||||
26
software/test_canbus/src/main.c
Normal file
26
software/test_canbus/src/main.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user