(https://i.imgur.com/fQTQtsr.png)
Field Documentation
• uint32_t CAN_InitTypeDef::Prescaler
ระบุ the length of a time quantum. This parameter ต้องเป็น a number ระหว่าง Min_Data = 1 และ Max_Data = 1024.
• uint32_t CAN_InitTypeDef::Mode
ระบุ the CAN operating mode. This parameter สามารถเป็นค่าหนึ่งของ CAN_operating_mode
• uint32_t CAN_InitTypeDef::SyncJumpWidth
ระบุจำนวนสูงสุดของ time quanta ที่ the CAN hardware ได้รับอนุญาตให้ยาวขึ้นหรือสั้นลงเล็กน้อยเพื่อดำเนินการซิงโครไนส์ซ้ำ. This
parameter สามารถเป็นค่าหนึ่งของ CAN_synchronisation_jump_width
• uint32_t CAN_InitTypeDef::TimeSeg1
ระบุจำนวนของ time quanta ใน Bit Segment 1. This parameter สามารถเป็นค่าหนึ่งของ
CAN_time_quantum_in_bit_segment_1
• uint32_t CAN_InitTypeDef::TimeSeg2
ระบุจำนวนของ time quanta in Bit Segment 2. This parameter สามารถเป็นค่าหนึ่งของ
CAN_time_quantum_in_bit_segment_2
• FunctionalState CAN_InitTypeDef::TimeTriggeredMode
เปิดใช้งานหรือปิดใช้งาน the time triggered communication mode. This parameter สามารถถูกเซ็ตเป็น ENABLE or
DISABLE.
• FunctionalState CAN_InitTypeDef::AutoBusOff
เปิดใช้งานหรือปิดใช้งาน the automatic bus-off management. This parameter สามารถถูกเซ็ตเป็น ENABLE or DISABLE.
• FunctionalState CAN_InitTypeDef::AutoWakeUp
เปิดใช้งานหรือปิดใช้งาน the automatic wake-up mode. This parameter สามารถถูกเซ็ตเป็น ENABLE or DISABLE.
• FunctionalState CAN_InitTypeDef::AutoRetransmission
เปิดใช้งานหรือปิดใช้งาน the non-automatic retransmission mode. This parameter สามารถถูกเซ็ตเป็น ENABLE or
DISABLE.
• FunctionalState CAN_InitTypeDef::ReceiveFifoLocked
เปิดใช้งานหรือปิดใช้งาน the Receive FIFO Locked mode. This parameter สามารถถูกเซ็ตเป็น ENABLE or DISABLE.
• FunctionalState CAN_InitTypeDef::TransmitFifoPriority
เปิดใช้งานหรือปิดใช้งาน the transmit FIFO priority. This parameter สามารถถูกเซ็ตเป็น ENABLE or DISABLE.
(https://i.imgur.com/6EU3ZfS.png)
Field Documentation
• uint32_t CAN_FilterTypeDef::FilterIdHigh
ระบุ the filter identification number (MSBs สำหรับ a 32-bit configuration, ตัวแรกสำหรับ a 16-bit configuration). This
parameter ต้องเป็น a number ระหว่าง Min_Data = 0x0000 and Max_Data = 0xFFFF.
• uint32_t CAN_FilterTypeDef::FilterIdLow
ระบุ the filter identification number (LSBs สำหรับ a 32-bit configuration, ตัวที่สองสำหรับ a 16-bit configuration).
This parameter ต้องเป็น a number ระหว่าง Min_Data = 0x0000 and Max_Data = 0xFFFF.
• uint32_t CAN_FilterTypeDef::FilterMaskIdHigh
ระบุ the filter mask number or identification number, สอดคล้องกับ the mode (MSBs สำหรับ a 32-bit configuration,
ตัวแรกสำหรับ a 16-bit configuration). This parameter ต้องเป็น a number ระหว่าง Min_Data = 0x0000 and Max_Data
= 0xFFFF.
• uint32_t CAN_FilterTypeDef::FilterMaskIdLow
ระบุ the filter mask number or identification number, สอดคล้องกับ the mode (LSBs สำหรับ a 32-bit configuration,
ตัวที่สองสำหรับ a 16-bit configuration). This parameter ต้องเป็น a number ระหว่าง Min_Data = 0x0000 and
Max_Data = 0xFFFF.
• uint32_t CAN_FilterTypeDef::FilterFIFOAssignment
ระบุ the FIFO (0 or 1U) ซึ่งจะถูกกำหนดให้กับ the filter. This parameter สามารถเป็นค่าหนึ่งของ CAN_filter_FIFO
• uint32_t CAN_FilterTypeDef::FilterBank
ระบุ the filter bank ซึ่งจะถูกกำหนดค่าเริ่มต้น. สำหรับ single CAN instance(14 dedicated filter banks), this parameter ต้อง
เป็น a number ระหว่าง Min_Data = 0 and Max_Data = 13. สำหรับ dual CAN instances(28 filter banks ที่แชร์กัน), this
parameter ต้องเป็น a number ระหว่าง Min_Data = 0 and Max_Data = 27.
• uint32_t CAN_FilterTypeDef::FilterMode
ระบุ the filter mode ที่จะถูกกำหนดค่าเริ่มต้น. This parameter สามารถเป็นค่าหนึ่งของ CAN_filter_mode
• uint32_t CAN_FilterTypeDef::FilterScale
ระบุ the filter scale. This parameter สามารถเป็นค่าหนึ่งของ CAN_filter_scale
• uint32_t CAN_FilterTypeDef::FilterActivation
เปิดใช้งานหรือปิดใช้งาน the filter. This parameter สามารถเป็นค่าหนึ่งของ CAN_filter_activation
• uint32_t CAN_FilterTypeDef::SlaveStartFilterBank
เลือก the start filter bank สำหรับ the slave CAN instance. สำหรับ single CAN instances, this parameter ไม่มีความ
หมายอะไร. สำหรับ dual CAN instances, ทุก filter banks ที่มี lower index ถูกกำหนดให้กับ master CAN instance, ในขณะที่
ทุก filter banks ที่มี greater index ถูกกำหนดให้กับ slave CAN instance. This parameter ต้องเป็น a number ระหว่าง
Min_Data = 0 and Max_Data = 27.
(https://i.imgur.com/cQN5Sfz.png)
(https://i.imgur.com/hSket3C.png)
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.
(https://i.imgur.com/E6Fc5tg.png)
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.
(https://i.imgur.com/wNntuZ7.png)
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.
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.
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().
Interrupt mode operation
1. Notifications ถูกทำให้ทำงานโดยใช้ HAL_CAN_ActivateNotification() function. จากนั้น, the process สามารถถูกควบคุม
ผ่านทาง the available user callbacks: HAL_CAN_xxxCallback(), โดยใช้ APIs เดียวกัน HAL_CAN_GetRxMessage()
and HAL_CAN_AddTxMessage().
2. Notifications สามารถถูกยกเลิกการทำงานโดยใช้ HAL_CAN_DeactivateNotification() function.
3. ควรใช้ความระมัดระวังเป็นพิเศษสำหรับ CAN_IT_RX_FIFO0_MSG_PENDING and CAN_IT_RX_FIFO1_MSG_PENDING
notifications. These notifications จะทริก the callbacks HAL_CAN_RxFIFO0MsgPendingCallback() and
HAL_CAN_RxFIFO1MsgPendingCallback(). ผู้ใช้มีสองทางเลือกที่สามารถเป็นได้นี้.
– รับ the Rx message โดยตรงใน the callback, โดยใช้ HAL_CAN_GetRxMessage().
– หรือยกเลิกการทำงาน the notification ใน the callback โดยไม่มีการรับ the Rx message. The Rx message ดังนั้น
สามารถได้รับภายหลังโดยใช้ HAL_CAN_GetRxMessage(). เมื่อ the Rx message ถูกอ่านแล้ว, the notification สามารถ
ถูกทำให้ทำงานอีกครั้ง.
Sleep mode
1. The CAN peripheral สามารถถูกใส่ใน sleep mode (low power), โดยใช้ HAL_CAN_RequestSleep(). The sleep mode
จะถูกเข้าสู่ทันทีที่ the current CAN activity (transmission or reception of a CAN frame) จะเสร็จสมบูรณ์.
2. A notification สามารถถูกทำให้ทำงานเพื่อถูกแจ้งข่าวเมื่อ the sleep mode จะถูกเข้าสู่.
3. มันสามารถถูกเช็คว่า the sleep mode ถูกเข้าสู่หรือไม่โดยใช้ HAL_CAN_IsSleepActive(). โดยทราบว่า the CAN state (เข้าถึง
ได้จาก the API HAL_CAN_GetState()) เป็น HAL_CAN_STATE_SLEEP_PENDING ทันทีที่ the sleep mode request ถูก
ส่ง (the sleep mode ยังไม่ถูกเข้าสู่), และกลายมาเป็น HAL_CAN_STATE_SLEEP_ACTIVE เมื่อ the sleep mode มีผล.
4. The wake-up จาก sleep mode สามารถถูกทริกโดยสองวิธีนี้:
– โดยใช้ HAL_CAN_WakeUp(). เมื่อส่งคืนกลับจากฟังชั่นนี้, the sleep mode จะถูกออก (ถ้า return status คือ HAL_OK).
– เมื่อ a start of Rx CAN frame ถูกตรวจพบโดย the CAN peripheral, ถ้า automatic wake up mode ถูกเปิดใช้งาน.
Callback registration
(https://i.imgur.com/XypU2Cn.png)
(https://i.imgur.com/d4a1MQg.png)
(https://i.imgur.com/SW7gaW6.png)
(https://i.imgur.com/psDMpEr.png)
(https://i.imgur.com/hA0wPGD.png)
(https://i.imgur.com/prwj5Br.png)
(https://i.imgur.com/sSFdVvT.png)
(https://i.imgur.com/0DyNtPr.png)
(https://i.imgur.com/eWRzKYJ.png)
(https://i.imgur.com/TCQqKeQ.png)
(https://i.imgur.com/e2auapA.png)
(https://i.imgur.com/SuLrlpP.png)
(https://i.imgur.com/7ZktSvm.png)
(https://i.imgur.com/wpprkRy.png)
(https://i.imgur.com/wI0kAuJ.png)
(https://i.imgur.com/vaUnALo.png)
(https://i.imgur.com/4Ej6gUC.png)
(https://i.imgur.com/8BHKFiq.png)
(https://i.imgur.com/5X6Uf8R.png)
(https://i.imgur.com/u8rklBJ.png)
(https://i.imgur.com/WekIGRZ.png)
(https://i.imgur.com/jJKPzPP.png)
(https://i.imgur.com/yXZIGn8.png)
(https://i.imgur.com/ETHE9U6.png)
(https://i.imgur.com/XYDwYxT.png)
(https://i.imgur.com/sPxDvhP.png)
(https://i.imgur.com/hH6aoF3.png)
(https://i.imgur.com/1YZ51f4.png)
(https://i.imgur.com/H4MzEav.png)
(https://i.imgur.com/sVCjb4R.png)
(https://i.imgur.com/tG6r26a.png)
(https://i.imgur.com/xQ4OP6V.png)
(https://i.imgur.com/o4JzeiT.png)
(https://i.imgur.com/vNWuJ4Y.png)
(https://i.imgur.com/TxQMfol.png)
(https://i.imgur.com/o2rChBM.png)
(https://i.imgur.com/RkDeaSl.png)
(https://i.imgur.com/dxSoKP7.png)
(https://i.imgur.com/n9gwEsB.png)
(https://i.imgur.com/JAjPA4O.png)
(https://i.imgur.com/1327upB.png)
(https://i.imgur.com/MWelPTu.png)
(https://i.imgur.com/ChZFlqs.png)
(https://i.imgur.com/72niLsW.png)
(https://i.imgur.com/15kmhH4.png)
(https://i.imgur.com/ewl02aU.png)
(https://i.imgur.com/AavcETa.png)
(https://i.imgur.com/zEKO1vm.png)
(https://i.imgur.com/VfhZUVD.png)
(https://i.imgur.com/H6CDL3P.png)
(https://i.imgur.com/A74b0t2.png)
(https://i.imgur.com/HedgzHH.png)
(https://i.imgur.com/Av9WcUA.png)
(https://i.imgur.com/QX0Z0EO.png)
(https://i.imgur.com/nLcqBCV.png)
(https://i.imgur.com/gPUUYa6.png)
(https://i.imgur.com/DwejXyZ.png)
(https://i.imgur.com/4uXZ1VB.png)
(https://i.imgur.com/4qVGwzk.png)
(https://i.imgur.com/wXcQR6m.png)
(https://i.imgur.com/k93IMjI.png)
(https://i.imgur.com/OXRlxQU.png)
(https://i.imgur.com/Oi2gfuQ.png)
(https://i.imgur.com/eFoWvUY.png)
(https://i.imgur.com/nHdtqSH.png)
(https://i.imgur.com/QvKxeVF.png)
(https://i.imgur.com/cNSkRmM.png)
(https://i.imgur.com/iJNKiT6.png)
(https://i.imgur.com/Gumjds4.png)
(https://i.imgur.com/UFuW5dA.png)
(https://i.imgur.com/EF9B7ln.png)
(https://i.imgur.com/7rk4Udg.png)
(https://i.imgur.com/kXlur5x.png)
(https://i.imgur.com/2LypICA.png)
(https://i.imgur.com/nhhrvmt.png)