Skip to content

Commit

Permalink
send CAN on can1 recieve
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Mar 1, 2024
1 parent c43c3ac commit 321e65c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Core/Inc/can_handler.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef CAN_HANDLER_H
#define CAN_HANDLER_H

#include "can.h"
#include "stm32f4xx_hal.h"
#include <stdint.h>
#include "can.h"
#include "compute.h"


#define NUM_INBOUND_CAN1_IDS 1
Expand Down
4 changes: 4 additions & 0 deletions Core/Inc/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down
16 changes: 16 additions & 0 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "analyzer.h"
#include "ringbuffer.h"
#include "can_handler.h"
#include <string.h>

ringbuffer_t* can1_rx_queue = NULL;
ringbuffer_t* can2_rx_queue = NULL;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 321e65c

Please sign in to comment.