Skip to content

Commit

Permalink
added can_msg type
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Dec 7, 2023
1 parent f68cd84 commit 5109618
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 7 additions & 1 deletion platforms/stm32f405/include/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ typedef struct{
void (*can_callback)(CAN_HandleTypeDef *hcan);
} can_t;

typedef struct{
uint16_t id;
uint8_t data[8];
uint8_t size;
} can_msg_t;

void can_init(can_t *can);
void can_send_msg(can_t *can, uint16_t id, uint8_t *data, uint8_t size);
void can_send_msg(can_t *can, can_msg_t *msg);



Expand Down
11 changes: 5 additions & 6 deletions platforms/stm32f405/src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ void can_init(can_t *can)
HAL_CAN_ActivateNotification(can->hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
}

void can_send_msg(can_t *can, uint16_t id, uint8_t *data, uint8_t size)
void can_send_msg(can_t *can, can_msg_t *msg)
{
CAN_TxHeaderTypeDef tx_header;
tx_header.StdId = id;
tx_header.StdId = msg->id;
tx_header.ExtId = 0;
tx_header.IDE = CAN_ID_STD;
tx_header.RTR = CAN_RTR_DATA;
tx_header.DLC = size;
tx_header.DLC = msg->size;
tx_header.TransmitGlobalTime = DISABLE;

uint32_t tx_mailbox;
HAL_CAN_AddTxMessage(can->hcan, &tx_header, data, &tx_mailbox);
}
```
HAL_CAN_AddTxMessage(can->hcan, &tx_header, msg->data, &tx_mailbox);
}

0 comments on commit 5109618

Please sign in to comment.