Working version
This commit is contained in:
@ -11,12 +11,12 @@
|
||||
|
||||
#include "stm32g4xx_hal_fdcan.h"
|
||||
|
||||
|
||||
// 3 should be programmed with CAN id 2
|
||||
const uint16_t slave_CAN_id_to_slave_index[7] = {
|
||||
0, 1, 2, 3, 255, 5, 4}; // TODO: Make this pretty pls
|
||||
0, 1, 2, 3, 4, 5, 255}; // TODO: Make this pretty pls
|
||||
canFrame framebuffer[CANFRAMEBUFFERSIZE] = {0};
|
||||
uint8_t framebufferwritepointer;
|
||||
uint8_t framebufferreadpointer;
|
||||
uint32_t framebufferwritepointer;
|
||||
uint32_t framebufferreadpointer;
|
||||
|
||||
void CAN_Init(FDCAN_HandleTypeDef* hcan) {
|
||||
HAL_FDCAN_Stop(hcan);
|
||||
@ -27,8 +27,8 @@ void CAN_Init(FDCAN_HandleTypeDef* hcan) {
|
||||
FDCAN_FilterTypeDef fdfilter = {0};
|
||||
|
||||
fdfilter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
|
||||
fdfilter.FilterID1 = 0x000; // Range start
|
||||
fdfilter.FilterID2 = 0x000; // Range stop
|
||||
fdfilter.FilterID1 = 0x000; // ID
|
||||
fdfilter.FilterID2 = 0x000; // Mask
|
||||
fdfilter.FilterIndex = 0;
|
||||
|
||||
fdfilter.FilterType = FDCAN_FILTER_MASK;
|
||||
@ -38,6 +38,10 @@ void CAN_Init(FDCAN_HandleTypeDef* hcan) {
|
||||
|
||||
HAL_StatusTypeDef status = HAL_FDCAN_Start(hcan);
|
||||
|
||||
if (status) {
|
||||
return;
|
||||
}
|
||||
|
||||
status =
|
||||
HAL_FDCAN_ActivateNotification(hcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);
|
||||
}
|
||||
@ -59,23 +63,20 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) {
|
||||
slaveID = slave_CAN_id_to_slave_index[slaveID];
|
||||
uint8_t messageID = msg & 0x00F;
|
||||
updateSlaveInfo(slaveID, messageID, rxFrame);
|
||||
} else if (rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS) {
|
||||
AMSErrorHandle errorframe = {0};
|
||||
errorframe.errorcode = SlavesErrorFrameError;
|
||||
errorframe.errorarg[0] = rxFrame.data[0];
|
||||
errorframe.errorarg[1] = rxFrame.data[1];
|
||||
errorframe.errorarg[2] = rxFrame.data[2];
|
||||
errorframe.errorarg[3] = rxFrame.data[3];
|
||||
errorframe.errorarg[4] = rxFrame.data[4];
|
||||
errorframe.errorarg[5] = rxFrame.data[5];
|
||||
errorframe.errorarg[6] = rxFrame.data[6];
|
||||
errorframe.errorarg[7] = rxFrame.data[7];
|
||||
|
||||
AMS_Error_Handler(errorframe);
|
||||
}
|
||||
|
||||
/* if(rxFrame.FrameID == SLAVE_EMERGENCY_ADDRESS)
|
||||
{
|
||||
AMSErrorHandle errorframe = {0};
|
||||
errorframe.errorcode = SlavesErrorFrameError;
|
||||
errorframe.errorarg[0] = rxFrame.data[0];
|
||||
errorframe.errorarg[1] = rxFrame.data[1];
|
||||
errorframe.errorarg[2] = rxFrame.data[2];
|
||||
errorframe.errorarg[3] = rxFrame.data[3];
|
||||
errorframe.errorarg[4] = rxFrame.data[4];
|
||||
errorframe.errorarg[5] = rxFrame.data[5];
|
||||
errorframe.errorarg[6] = rxFrame.data[6];
|
||||
errorframe.errorarg[7] = rxFrame.data[7];
|
||||
|
||||
AMS_Error_Handler(errorframe);
|
||||
}*/
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user