STM32F1 CAN

Started by tha, January 29, 2021, 09:07:28 AM

Previous topic - Next topic

tha

24.4.3 Sleep mode (low power)

เพื่อลด power consumption, bxCAN มี a low-power mode ที่เรียกว่า Sleep mode. โหมดนี้ถูกเข้าสู่บน software ร้องขอโดยการเซ็ต the SLEEP bit in the CAN_MCR register. ในโหมดนี้, the bxCAN clock ถูกหยุด, อย่างไรก็ตาม software สามารถยังคงเข้าถึง the bxCAN mailboxes.

ถ้า software ร้องขอเข้าสู่ไปยัง initialization mode โดยการเซ็ต the INRQ bit ในขณะที่ bxCAN อยู่ใน Sleep mode, มันต้องเคลียร์ the SLEEP bit ด้วย.

bxCAN สามารถถูกปลูก (ออกจาก Sleep mode) อย่างใดอย่างหนึ่งโดย software การเคลียร์ the SLEEP bit หรือบนการตรวจพบของ CAN bus activity

บน CAN bus activity detection, hardware ดำเนินการ the wakeup sequence โดยอัตโนมัติโดยการเคลียร์ the SLEEP bit ถ้า the AWUM bit ใน the CAN_MCR register ถูกเซ็ต. ถ้า the AWUM bit ถูกเคลียร์, software ต้องเคลียร์ the SLEEP bit เมื่อ a wakeup interrupt เกิดขึ้น, เพื่อออกจาก Sleep mode.

Note: ถ้า the wakeup interrupt ถูกเปิดการใช้งาน (WKUIE bit ถูกเซ็ตใน CAN_IER register) a wakeup interrupt จะถูกสร้าง
           ขึ้นบนการตรวจพบของ CAN bus activity, ถึงแม้ว่า the bxCAN ดำเนินการ the wakeup sequence โดยอัตโนมัติ.

หลังจาก the SLEEP bit ถูกเคลียร์แล้ว, Sleep mode ถูก exited เมื่อ bxCAN ได้ synchronized กับ the CAN bus, อ้างอิงถึง Figure 224. The Sleep mode ถูก exited เมื่อ the SLAK bit ถูกเคลียร์แล้วโดย hardware.



1. ACK = The wait state ในระหว่างที่ hardware ยืนยัน a request โดยการเซ็ต the INAK or SLAK bits in the CAN_MSR register
2. SYNC = The state ในระหว่างที่ bxCAN คอยจนกระทั่ง the CAN bus อยู่ idle, ซึงหมายถึง 11 consecutive recessive bits ถูกมอนิเตอร์แล้วบน CANRX

tha

24.5 Test mode

Test mode สามารถถูกเลือกโดย the SILM and LBKM bits in the CAN_BTR register. บิตเหล่านี้ต้องถูกกำหนดค่าขณะที่ bxCAN อยู่ใน Initialization mode. เมื่อ test mode ถูกเลือกแล้ว, the INRQ bit in the CAN_MCR register ต้องถูกรีเซ็ตเพื่อเข้าสู่ Normal mode.

24.5.1 Silent mode

The bxCAN สามารถถูกใส่ใน Silent mode โดยการเซ็ต the SILM bit in the CAN_BTR register.

ใน Silent mode, the bxCAN สามารถที่จะรับ valid data frames และ valid remote frames, แต่มันส่งเฉพาะ recessive bits บน the CAN bus และมันไม่สามารถสตาร์ท a transmission. ถ้า the bxCAN ต้องส่ง a dominant bit (ACK bit, overload flag, active error flag), the bit จะถูกกำหนดเส้นทางใหม่ภายในเพื่อว่า the CAN Core มอนิเตอร์ dominant bit นี้, แม้ว่า the CAN bus อาจยังคงอยู่ใน recessive state. Silent mode สามารถถูกใช้วิเคราะห์การจราจรบน a CAN bus ไม่มีผลกระทบมันโดยการส่งของ dominant bits (Acknowledge Bits, Error Frames).


tha

24.5.2 Loop back mode

The bxCAN สามารถถูกเซ็ตใน Loop Back Mode โดยการเซ็ต the LBKM bit in the CAN_BTR register. ใน Loop Back Mode, the bxCAN ปฏิบัติต่อ transmitted messages ของตัวเองดัง received messages และเก็บพวกมัน (ถ้าพวกมันผ่านการยอมรับการกรอง) ใน a Receive mailbox.



โหมดนี้ถูกจัดให้มีสำหรับ self-test functions. เพื่อให้เป็นอิสระจาก external events, the CAN Core จะเพิกเฉยต่อ acknowledge errors (ไม่มี dominant bit ถูกสุ่มใน the acknowledge slot ของ a data / remote frame) ใน Loop Back Mode. ในโหมดนี้, the bxCAN ดำเนินการป้อนกลับภายในจาก Tx output ของมันไปยัง Rx input ของมัน. ค่าจริงของ the CANRX input pin ถูกมองข้ามโดย the bxCAN. The transmitted messages สามารถถูกมอนิเตอร์บน the CANTX pin.


tha

24.5.3 Loop back combined with silent mode

มันเป็นไปได้ที่จะรวม Loop Back mode และ Silent mode ได้อีกด้วยโดยการเซ็ต the LBKM และ SILM bits in the CAN_BTR register. โหมดนี้สามารถถูกใช้สำหรับ a "Hot Selftest", หมายความว่า the bxCAN สามารถถูกทดสอบเหมือนใน Loop Back mode แต่ไม่มีผลกระทบกับ a running CAN system ที่ต่อถึง the CANTX and CANRX pins. ในโหมดนี้, the CANRX pin จะถูกตัดการเชื่อมต่อจาก the bxCAN และ the CANTX pin ถูกยึด recessive.


tha

24.6 Debug mode

เมื่อ the microcontroller เข้าสู่ the debug mode (Cortex®-M3 core ถูกหยุด), the bxCAN ยังคงทำงานต่อไปโดยปกติหรือหยุด, ขึ้นอยู่กับ:
•    the DBG_CAN1_STOP bit สำหรับ CAN1 หรือ the DBG_CAN2_STOP bit สำหรับ CAN2 ใน the DBG module. สำหรับราย
      ละเอียดที่มากขึ้น, อ้างอิงถึง Section 31.16.2: Debug support for timers, watchdog, bxCAN and I2C.
•    the DBF bit in CAN_MCR. สำหรับรายละเอียดที่มากขึ้น, อ้างอิงถึง Section 24.9.2.

tha

24.7 bxCAN functional description

24.7.1 Transmission handling

เพื่อส่ง a message, the application ต้องเลือก one empty transmit mailbox, ตั้งค่า the identifier, the data length code (DLC) และ the data ก่อนการร้องขอ the transmission โดยการเซ็ต the corresponding TXRQ bit ใน the CAN_TIxR register. เมื่อ the mailbox ออกจาก empty state แล้ว, the software ไม่สามารถเขียนเข้าถึงไปยัง the mailbox registers ได้อีกต่อไป. ทันทีหลังจาก the TXRQ bit ถูกเซ็ตแล้ว, the mailbox เข้าสู่ pending state และคอยมาเป็น the highest priority mailbox, ดู Transmit Priority. ทันทีที่ the mailbox มี the highest priority มันจะถูกวาง scheduled สำหรับ transmission. The transmission ของ the message ของ the scheduled mailbox จะสตาร์ท (เข้าสู่ transmit state) เมื่อ the CAN bus มาเป็น idle. เมื่อ the mailbox ถูกส่งสำเร็จแล้ว, มันจะมาเป็น empty อีกครั้ง. The hardware จะแสดงให้เห็นว่า a successful transmission โดยการเซ็ต the RQCP และ TXOK bits ใน the CAN_TSR register.

ถ้า the transmission ล้มเหลว, สาเหตุถูกแสดงให้เห็นโดย the ALST bit in the CAN_TSR register ในกรณีของ an Arbitration Lost, และ/หรือ the TERR bit, ในกรณีของ transmission error detection.

tha

Transmit priority

By identifier                           เมื่อมากกว่า one transmit mailbox ถูก pending, the transmission order ถูกให้โดย the
                                                identifier ของ the message ที่ถูกเก็บใน the mailbox. The message ที่มี the lowest
                                                identifier value จะมี the highest priority สอดคล้องกันกับ the arbitration ของ the CAN
                                                protocol. ถ้า the identifier values เท่ากัน, the lower mailbox number จะถูก
                                                scheduled ก่อน.

By transmit request order    The transmit mailboxes สามารถถูกกำหนดค่าเป็น a transmit FIFO โดยการเซ็ต the TXFP bit
                                                  ใน the CAN_MCR register. ในโหมดนี้ the priority order ถูกให้โดย the transmit
                                                  request order. โหมดนี้มีประโยชน์มากสำหรับ segmented transmission.

tha

Abort

A transmission request สามารถถูกยกเลิกโดย the user เซ็ต the ABRQ bit ใน the CAN_TSR register. ใน pending หรือ scheduled state, the mailbox จะถูกยกเลิกโดยทันที. An abort request ในขณะที่ the mailbox อยู่ใน transmit state สามารถมีสองผล. ถ้า the mailbox ถูกส่งสำเร็จ the mailbox มาเป็น empty พร้อมด้วย the TXOK bit set ใน the CAN_TSR register. ถ้า the transmission ล้มเหลว, the mailbox มาเป็น scheduled, the transmission ถูกยกเลิกและมาเป็น empty พร้อมด้วย TXOK cleared. ในทุกกรณี the mailbox จะมาเป็น empty อีกครั้งอย่างน้อยที่ the end of the current transmission.