9 HAL CAN Generic Driver

  • 71 Replies
  • 1932 Views
*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #8 on: July 12, 2022, 07:16:59 am »


*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #9 on: July 12, 2022, 07:35:53 am »
Field Documentation
•   uint32_t CAN_TxHeaderTypeDef::StdId
    ระบุ the standard identifier. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 0x7FF.
•   uint32_t CAN_TxHeaderTypeDef::ExtId
    ระบุ the extended identifier. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 0x1FFFFFFF.
•   uint32_t CAN_TxHeaderTypeDef::IDE
    ระบุ the type of identifier สำหรับ the message ที่จะถูกส่ง. This parameter สามารถเป็นค่าหนึ่งของ CAN_identifier_type
•   uint32_t CAN_TxHeaderTypeDef::RTR
    ระบุ the type of frame สำหรับ the message ที่จะถูกส่ง. This parameter สามารถเป็นค่าหนึ่งของ
    CAN_remote_transmission_request
•   uint32_t CAN_TxHeaderTypeDef::DLC
    ระบุ the length of the frame ที่จะถูกส่ง. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 8.
•   FunctionalState CAN_TxHeaderTypeDef::TransmitGlobalTime
    ระบุว่า the timestamp counter value ที่จับที่ start of frame transmission, ถูกส่งใน DATA6 and DATA7 แทนที่ pData[6]
    and pData[7].
    Note:
            –   : Time Triggered Communication Mode ต้องถูกเปิดใช้งาน.
            –   : DLC ต้องถูกโปรแกรมเป็น 8 bytes, เพื่อว่า 2 bytes นี้จะถูกส่ง. This parameter สามารถถูกเซ็ตเป็น ENABLE or
                   DISABLE.

*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #10 on: July 15, 2022, 07:24:43 am »

*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #11 on: July 15, 2022, 07:28:15 am »
Field Documentation
•   uint32_t CAN_RxHeaderTypeDef::StdId
   ระบุ the standard identifier. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 0x7FF.
•   uint32_t CAN_RxHeaderTypeDef::ExtId
    ระบุ the extended identifier. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 0x1FFFFFFF.
•   uint32_t CAN_RxHeaderTypeDef::IDE
    ระบุ the type of identifier สำหรับ the message ที่จะถูกส่ง. This parameter สามารถเป็นค่าหนึ่งของ CAN_identifier_type
•   uint32_t CAN_RxHeaderTypeDef::RTR
    ระบุ the type of frame สำหรับ the message ที่จะถูกส่ง. This parameter สามารถเป็นค่าหนึ่งของ
    CAN_remote_transmission_request
•   uint32_t CAN_RxHeaderTypeDef::DLC
    ระบุ the length of the frame ที่จะถูกส่ง. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 8.
•   uint32_t CAN_RxHeaderTypeDef::Timestamp
    ระบุ the timestamp counter value ที่จับบน start of frame reception.
    Note:
          – : Time Triggered Communication Mode ต้องถูกเปิดใช้งาน. This parameter ต้องเป็น a number ระหว่าง Min_Data
               = 0 and Max_Data = 0xFFFF.
•   uint32_t CAN_RxHeaderTypeDef::FilterMatchIndex
    ระบุ the index of matching acceptance filter element. This parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and
    Max_Data = 0xFF.

*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #12 on: July 18, 2022, 07:42:59 am »

*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #13 on: July 18, 2022, 08:00:38 am »
9.2 CAN Firmware driver API description

ส่วนต่อไปนี้แสดงรายการ the various functions ของ the CAN library.

9.2.1 How to use this driver
1.   กำหนดค่าเริ่มต้น the CAN low level resources โดยการจัดให้มีใช้ the HAL_CAN_MspInit():
     –   เปิดใช้งาน the CAN interface clock โดยใช้ __HAL_RCC_CANx_CLK_ENABLE()
     –   กำหนดค่า CAN pins
          ◦   เปิดใช้งาน the clock สำหรับ the CAN GPIOs
          ◦   กำหนดค่า CAN pins เป็น alternate function open-drain
     –   ในกรณีของการใช้ interrupts (ตัวอย่างเช่น HAL_CAN_ActivateNotification())
          ◦   กำหนดค่า the CAN interrupt priority โดยใช้ HAL_NVIC_SetPriority()
          ◦   เปิดใช้งาน the CAN IRQ handler โดยใช้ HAL_NVIC_EnableIRQ()
          ◦   ใน CAN IRQ handler, เรียก HAL_CAN_IRQHandler()
2.   กำหนดค่าเริ่มต้น the CAN peripheral โดยใช้ HAL_CAN_Init() function. ฟังชั่นนี้ใช้ HAL_CAN_MspInit() สำหรับ low-
      level initialization.
3.   กำหนดค่า the reception filters โดยใช้ the following configuration functions:
      –   HAL_CAN_ConfigFilter()
4.   สตาร์ท the CAN module โดยใช้ HAL_CAN_Start() function. ที่ level นี้ the node จะทำงานบน the bus: มันรับ
      messages, และสามารถส่ง messages.

*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #14 on: July 18, 2022, 08:58:58 am »
5.   เพื่อจัดการ messages transmission, the following Tx control functions สามารถถูกใช้:
     –   HAL_CAN_AddTxMessage() เพื่อร้องขอ transmission of a new message.
     –   HAL_CAN_AbortTxRequest() เพื่อยกเลิก transmission of a pending message.
     –   HAL_CAN_GetTxMailboxesFreeLevel() เพื่อได้รับจำนวนของ free Tx mailboxes.
     –   HAL_CAN_IsTxMessagePending() เพื่อเช็คว่ามี a message กำลังค้างอยู่ใน a Tx mailbox หรือไม่.
     –   HAL_CAN_GetTxTimestamp() เพื่อได้รับ the timestamp of Tx message ที่ส่ง, ถ้า time triggered communication
          mode ถูกเปิดใช้งาน.
6.   เมื่อ a message ถูกรับลงใน the CAN Rx FIFOs, มันสามารถถูกดึงออกโดยใช้ the HAL_CAN_GetRxMessage() function.
      The function HAL_CAN_GetRxFifoFillLevel() ยอมให้รู้ว่าจำนวนเท่าไหร่ที่ Rx message ถูกเก็บใน the Rx Fifo.
7.   การเรียก the HAL_CAN_Stop() function จะหยุด the CAN module.
8.   การยกเลิกการกำหนดค่าเริ่มต้นถูกทำให้สำเร็จลงด้วย HAL_CAN_DeInit() function.

*

Offline tha

  • *****
  • 5007
    • View Profile
Re: 9 HAL CAN Generic Driver
« Reply #15 on: July 18, 2022, 09:35:47 am »
Polling mode operation
1.   Reception:
      –   มอนิเตอร์ reception of message โดยใช้ HAL_CAN_GetRxFifoFillLevel() จนกระทั่งอย่างน้อย one message ถูกรับ.
      –   จากนั้นรับ the message โดยใช้ HAL_CAN_GetRxMessage().
2.   Transmission:
     –   มอนิเตอร์ the Tx mailboxes availability จนกระทั่งอย่างน้อย one Tx mailbox ว่างงาน, โดยใช้
          HAL_CAN_GetTxMailboxesFreeLevel().
     –   จากนั้นร้องขอ transmission of a message โดยใช้ HAL_CAN_AddTxMessage().