Add flag for CAN
This commit is contained in:
parent
a2f1c2557a
commit
b36103201c
1 changed files with 35 additions and 15 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "wiring_analog.h"
|
||||
#include "wiring_constants.h"
|
||||
// clang-format on
|
||||
|
||||
#include "reg_cah.h"
|
||||
#include "flash.h"
|
||||
|
||||
|
@ -33,6 +34,10 @@ volatile uint8_t msg_ch;
|
|||
volatile uint8_t crc_h;
|
||||
volatile uint8_t crc_l;
|
||||
|
||||
/* bool for test CAN */
|
||||
volatile bool CAN_GET = false;
|
||||
|
||||
|
||||
volatile float kt = 0.1; // Torque calculation constant
|
||||
|
||||
static FLASH_RECORD* flash_rec;
|
||||
|
@ -68,9 +73,7 @@ void doMotor(char *cmd) {
|
|||
delayMicroseconds(2);
|
||||
}
|
||||
|
||||
// Empty interrupt handler to prevent default handling
|
||||
void CAN2_RX0_IRQHandler() {
|
||||
}
|
||||
|
||||
|
||||
void setup_foc(MagneticSensorAS5045 *encoder, BLDCMotor *motor,
|
||||
DRV8313Driver *driver, LowsideCurrentSense *current_sense,
|
||||
|
@ -372,9 +375,10 @@ void foc_step(BLDCMotor *motor, Commander *commander) {
|
|||
commander->run();
|
||||
}
|
||||
|
||||
void setup(){
|
||||
|
||||
void setup(){
|
||||
// Vector table initialization (commented out)
|
||||
// __set_MSP(*(volatile uint32_t*)0x08008000);
|
||||
// __set_MSP(*(volatile uintф32_t*)0x08008000);
|
||||
// SCB->VTOR = (volatile uint32_t)0x08008000;
|
||||
|
||||
Serial.setRx(HARDWARE_SERIAL_RX_PIN);
|
||||
|
@ -384,10 +388,11 @@ void setup(){
|
|||
pinMode(PC11, OUTPUT);
|
||||
pinMode(PC10,OUTPUT);
|
||||
GPIOC->ODR &= ~GPIO_ODR_OD10;
|
||||
|
||||
// Can.enableMBInterrupts();
|
||||
Can.begin();
|
||||
Can.setBaudRate(1000000);
|
||||
|
||||
// Настройка прерываний CAN
|
||||
CAN2->IER |= CAN_IER_FMPIE0;
|
||||
// Load parameters from flash
|
||||
flash_rec = load_params();
|
||||
for(int i = 0;i < PARAM_COUNT;i++)
|
||||
|
@ -396,21 +401,36 @@ void setup(){
|
|||
// Initialize FOC system
|
||||
setup_foc(&encoder, &motor, &driver, ¤t_sense, &command, doMotor);
|
||||
|
||||
CAN2->IER |= CAN_IER_FMPIE0 | // Сообщение в FIFO0
|
||||
CAN_IER_FFIE0 | // FIFO0 full
|
||||
CAN_IER_FOVIE0; // FIFO0 overflow
|
||||
HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 1, 0);
|
||||
// HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);
|
||||
|
||||
// Default motor configuration
|
||||
GPIOC->ODR |= GPIO_ODR_OD11;
|
||||
motor.torque_controller = TorqueControlType::foc_current;
|
||||
motor.controller = MotionControlType::torque;
|
||||
__enable_irq();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
__enable_irq();
|
||||
foc_step(&motor, &command);
|
||||
CAN_message_t msg;
|
||||
GPIOC->ODR ^= GPIO_ODR_OD11; // Toggle status LED
|
||||
delay(500);
|
||||
|
||||
// Process incoming CAN messages
|
||||
// // Process incoming CAN messages
|
||||
while (Can.read(msg)) {
|
||||
CAN_GET = true;
|
||||
}
|
||||
/* If receive data from CAN */
|
||||
if(CAN_GET) {
|
||||
listen_can(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue