can.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file can.h
  5. * @brief This file contains all the function prototypes for
  6. * the can.c file
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2025 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __CAN_H__
  22. #define __CAN_H__
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Includes ------------------------------------------------------------------*/
  27. #include "main.h"
  28. /* USER CODE BEGIN Includes */
  29. /* USER CODE END Includes */
  30. extern CAN_HandleTypeDef hcan1;
  31. extern CAN_HandleTypeDef hcan2;
  32. /* USER CODE BEGIN Private defines */
  33. enum CANBAUD
  34. {
  35. CAN250kBaud = 1, /* 250 kBit/sec */
  36. CAN500kBaud = 2, /* 500 kBit/sec */
  37. CAN1MBaud = 3,/* 1 MBit/sec */
  38. };
  39. //¶¨ÒåCAN ±ê־λ
  40. #define CAN_EFF_FLAG 0x80000000 //À©Õ¹Ö¡±ê־λ
  41. #define CAN_SFF_MASK 0x000007FF // ÑÚÂë
  42. #define CAN_EFF_MASK 0x1FFFFFFF
  43. typedef struct
  44. {
  45. CAN_RxHeaderTypeDef RXHeader;
  46. uint8_t DATA[8];
  47. }CAN_RXBuffer;
  48. typedef struct
  49. {
  50. CAN_TxHeaderTypeDef TXHeader;
  51. uint8_t DATA[8];
  52. }CAN_TXBuffer;
  53. /* USER CODE END Private defines */
  54. void MX_CAN1_Init(void);
  55. void MX_CAN2_Init(void);
  56. /* USER CODE BEGIN Prototypes */
  57. void CAN_ConfigFilter(void);
  58. void MX_CAN_Init(uint8_t can1_baud,uint8_t can2_baud);
  59. uint8_t can_send_msg(CAN_HandleTypeDef *hcan,uint8_t IDE,uint32_t id, uint8_t *msg, uint8_t len );
  60. /* USER CODE END Prototypes */
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* __CAN_H__ */