From 321e65cc8e83fe12aef0f31f77f95ffeb2e60ce9 Mon Sep 17 00:00:00 2001 From: Sabramz Date: Thu, 29 Feb 2024 20:46:56 -0500 Subject: [PATCH] send CAN on can1 recieve --- Core/Inc/can_handler.h | 3 ++- Core/Inc/compute.h | 4 ++++ Core/Src/can_handler.c | 16 ++++++++++++++++ Core/Src/main.c | 4 ++-- Drivers/Embedded-Base | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Core/Inc/can_handler.h b/Core/Inc/can_handler.h index 559ea8e..f5dc446 100644 --- a/Core/Inc/can_handler.h +++ b/Core/Inc/can_handler.h @@ -1,9 +1,10 @@ #ifndef CAN_HANDLER_H #define CAN_HANDLER_H -#include "can.h" #include "stm32f4xx_hal.h" #include +#include "can.h" +#include "compute.h" #define NUM_INBOUND_CAN1_IDS 1 diff --git a/Core/Inc/compute.h b/Core/Inc/compute.h index a9eaf25..08e1b78 100644 --- a/Core/Inc/compute.h +++ b/Core/Inc/compute.h @@ -4,6 +4,7 @@ #include "datastructs.h" #include "stateMachine.h" #include "ringbuffer.h" +#include "can.h" #define CURRENT_SENSOR_PIN_L A1 #define CURRENT_SENSOR_PIN_H A0 @@ -15,6 +16,9 @@ #define MC_BAUD 1000000U #define MAX_ADC_RESOLUTION 1023 // 13 bit ADC +extern can_t can1; // main can bus, used by most peripherals +extern can_t can2; // p2p can bus with charger + /** * @brief inits the compute interface */ diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 0651343..69a4575 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -1,6 +1,7 @@ #include "analyzer.h" #include "ringbuffer.h" #include "can_handler.h" +#include ringbuffer_t* can1_rx_queue = NULL; ringbuffer_t* can2_rx_queue = NULL; @@ -16,6 +17,21 @@ void can_receive_callback(CAN_HandleTypeDef* hcan) return; } + struct __attribute__((packed)) { + uint16_t maxDischarge; + uint16_t maxCharge; + } data; + + data.maxCharge = 1; + data.maxDischarge = 8; + + can_msg_t msg; + msg.id = 0x19; + msg.len = sizeof(data); + memcpy(msg.data, &data, sizeof(data)); + + can_send_msg(&can1, &msg); + new_msg.len = rx_header.DLC; new_msg.id = rx_header.StdId; if (hcan == &hcan1) { diff --git a/Core/Src/main.c b/Core/Src/main.c index cd9f828..1c10976 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -213,8 +213,8 @@ int main(void) MX_USB_OTG_FS_PCD_Init(); MX_I2C1_Init(); /* USER CODE BEGIN 2 */ - - segment_init(); + compute_init(); + segment_init(); /* USER CODE END 2 */ /* Infinite loop */ diff --git a/Drivers/Embedded-Base b/Drivers/Embedded-Base index c9b2d70..002619a 160000 --- a/Drivers/Embedded-Base +++ b/Drivers/Embedded-Base @@ -1 +1 @@ -Subproject commit c9b2d70b3e3838af107783ae654a986ffe79f6f6 +Subproject commit 002619a1c5c14210060e405b3ef528c457721fd9