STM32F1 CAN

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

Previous topic - Next topic

tha

Nonautomatic retransmission mode

โหมดนี้ถูกมีให้ใช้เพื่อเติมเต็มความต้องการของ the Time Triggered Communication option ของ the CAN standard. เพื่อกำหนดค่า the hardware ในโหมดนี้ the NART bit in the CAN_MCR register ต้องถูกเซ็ต.

ในโหมดนี้, แต่ละ transmission ถูกสตาร์ทเพียงครั้งเดียว. ถ้า the first attempt ล้มเหลว, เนื่องจาก an arbitration loss หรือ an error, the hardware จะไม่รีสตาร์ท  the message transmission โดยอัตโนมัติ.

ที่ the end of the first transmission attempt, the hardware พิจารณา the request ว่าเสร็จสมบูรณ์และเซ็ต the RQCP bit ใน the CAN_TSR register. The result of the transmission ถูกแสดงให้เห็นใน the CAN_TSR register โดย the TXOK, ALST and TERR bits.


tha

24.7.2 Time triggered communication mode

ในโหมดนี้, the internal counter ของ the CAN hardware ถูกทำให้ทำงานและใช้สร้าง the Time Stamp value ที่เก็บไว้ใน the CAN_RDTxR/CAN_TDTxR registers, ตามลำดับ (สำหรับ Rx และ Tx mailboxes). The internal counter ถูกเพิ่มขึ้นแต่ละ CAN bit time (อ้างอิงถึง Section 24.7.7). The internal counter ถูก captured บน the sample point ของ the Start Of Frame bit ในทั้ง reception and transmission.

tha

24.7.3 Reception handling

สำหรับ the reception ของ CAN messages, three mailboxes ที่จัดระบบเป็น a FIFO ถูกจัดให้มี. เพื่อประหยัด CPU load, ความง่ายของ the software และรับประกันความสม่ำเสมอของ data , the FIFO ถูกจัดการอย่างสมบูรณ์โดย hardware. The application เข้าถึง the messages ที่เก็บไว้ใน the FIFO ผ่านทาง the FIFO output mailbox.

Valid message

A received message ถูกพิจารณาว่าใช้ได้เมื่อมันถูกรับอย่างถูกต้องแล้วสอดคล้องกับ the CAN protocol (ไม่มี error จนกระทั่งสุดท้ายแต่ one bit of the EOF field) และมันผ่านๆทาง the identifier filtering สำเร็จ, ดู Section 24.7.4.


tha



FIFO management

สตาร์ทจาก the empty state, the first valid message received ถูกเก็บใน the FIFO ซึ่งมาเป็น pending_1. The hardware ให้สัญญาณเหตุการณ์นี้โดยการเซ็ต the FMP[1:0] bits ใน the CAN_RFR register เป็นค่า 01b. The message มีให้ใช้ใน the FIFO output mailbox. The software อ่านออก the mailbox content และปลดปล่อยมันโดยการเซ็ต the RFOM bit ใน the CAN_RFR register. The FIFO มาเป็น empty อีกครั้ง. ถ้า a new valid message ถูกรับแล้วในระหว่างนี้, the FIFO อยู่ใน pending_1 state และ the new message มีให้ใช้ใน the output mailbox.

ถ้า the application ไม่ปลดปล่อย the mailbox, the next valid message จะถูกเก็บใน the FIFO ซึ่งเข้าสู่ pending_2 state (FMP[1:0] = 10b). The storage process ถูกซ้ำสำหรับ the next valid message โดยการผลัก the FIFO ลงใน pending_3 state (FMP[1:0] = 11b). ที่จุดนี้, the software ต้องปลดปล่อย the output mailbox โดยการเซ็ต the RFOM bit, ดังนั้น a
mailbox ถูกปล่อยเป็นอิสระเพื่อเก็บ the next valid message. มิฉะนั้น the next valid message received จะเป็นเหตุให้ a loss of message.

อ้างอิงถึง Section 24.7.5 อีกด้วย

tha

Overrun

เมื่อ the FIFO อยู่ใน pending_3 state (เช่น the three mailboxes เต็ม) the next valid message reception จะนำไปสู่ an overrun และ a message จะสูญหาย. The hardware ให้สัญญาณ the overrun condition โดยการเซ็ต the FOVR bit ใน the CAN_RFR register. ซึ่ง message ที่สูญหายขึ้นอยู่กับ the configuration of the FIFO:
•    ถ้า the FIFO lock function ถูกปิดการใช้งาน (RFLM bit in the CAN_MCR register เคลียร์) the last message ที่เก็บใน the
      FIFO จะถูกเขียนทับโดย the new incoming message. ในกรณีนี้ the latest messages จะมีให้ใช้เสมอกับ the application.
•    ถ้า the FIFO lock function ถูกเปิดการใช้งาน (RFLM bit in the CAN_MCR register set) the most recent message จะ
      ถูกละทิ้งและ the software จะมี the three oldest messages ใน the FIFO ให้ใช้งาน

tha

Reception related interrupts

เมื่อ a message ถูกเก็บใน the FIFO แล้ว, the FMP[1:0] bits ถูกอัปเดตและ an interrupt request ถูกสร้างขึ้นถ้า the FMPIE bit in the CAN_IER register ถูกเซ็ต.

เมื่อ the FIFO มาเป็นเต็ม (อย่างเช่น a third message ถูกเก็บ) the FULL bit ใน the CAN_RFR register ถูกเซ็ตและ an interrupt ถูกสร้างขึ้นถ้า the FFIE bit in the CAN_IER register ถูกเซ็ต.

On overrun condition, the FOVR bit ถูกเซ็ตและ an interrupt ถูกสร้างขึ้นถ้า the FOVIE bit in the CAN_IER register ถูกเซ็ต.

tha

24.7.4 Identifier filtering

ใน the CAN protocol the identifier ของ a message ไม่เกี่ยวข้องกับ the address of a node แต่เกี่ยวข้องกับ the content of the message. ด้วยเหตุนี้ a transmitter จึงออกอากาศ message ของมันไปยัง receivers ทั้งหมด. บน message reception a receiver node ตัดสิน - ขึ้นอยู่กับ the identifier value - ว่า the software ต้องการ the message หรือไม่. ถ้า the message ถูกต้องการ, มันจะถูกคัดลอกลงใน the SRAM. ถ้าไม่, the message ต้องถูกละทิ้งโดยไม่มีการแทรกแซงโดย the software.

เพื่อเติมเต็มความต้องการนี้, the bxCAN Controller จัดให้มี 28 configurable and scalable filter banks (27-0) แก่ the application. ใน devices อื่นๆ the bxCAN Controller จัดให้มี 14 configurable and scalable filter banks (13-0) แก่ the application เพื่อรับเฉพาะ the messages ที่ the software ต้องการ. hardware filtering นี้ประหยัด CPU resources ซึ่งมิฉะนั้นจะต้องถูกต้องการเพื่อดำเนินการ filtering โดย software. แต่ละ filter bank x ประกอบด้วย two 32-bit registers, CAN_FxR0 and CAN_FxR1.

tha

Scalable width

เพื่อทำให้เหมาะที่สุดและปรับ the filters ตาม the application ต้องการ, แต่ละ filter bank สามารถถูกปรับขนาดอย่างเป็นอิสระ. ขึ้นอยูกับ the filter scale  ที่ a filter bank จัดให้มี :
• One 32-bit filter for the STDID[10:0], EXTID[17:0], IDE and RTR bits.
• Two 16-bit filters for the STDID[10:0], RTR, IDE and EXTID[17:15] bits.

อ้างอิงถึง  Figure 230.

นอกจากนี้, the filters สามารถถูกกำหนดค่าใน mask mode หรือใน identifier list mode.

Mask mode

ใน mask mode the identifier registers ที่เกี่ยวข้องกับ mask registers ระบุซึ่ง bits ของ the identifier ถูกรับมือเป็น "ต้องตรงกัน" หรือเป็น "ไม่สนใจ".

Identifier list mode

ใน identifier list mode, the mask registers ถูกใช้เป็น identifier registers. ดังนั้นแทนที่จะกำหนด an identifier and a mask, two identifiers ถูกระบุ, สองเท่า the number of single identifiers. ทุกบิตของ the incoming identifier ต้องตรงกับ the bits ที่ระบุใน the filter registers