STM32F1 EXTI

Started by tha, September 21, 2020, 09:04:51 AM

Previous topic - Next topic

tha

10.2 External interrupt/event controller (EXTI)
The external interrupt/event controller มีถึง 20 edge detectors(ขา) ใน connectivity line devices, หรือ 19 edge detectors ใน mcu เบอร์อื่นๆ สำหรับทำให้เกิด event/interrupt requests. แต่ละขาอินพุทสามารถกำหนดค่าได้อย่างอิสระเพื่อเลือกชนิด (event หรือ interrupt) และ the corresponding trigger event(ขอบขาที่จะทริก) (rising หรือ falling หรือ both). แต่ละขาสามารถที่จะ masked ได้อย่างอิสระ(ถ้า mask(เป็น '0') ก็ไม่ยอมให้เกิดอินเตอรัพท์ ถ้าไม่ mask(เป็น '1' ก็ยอมให้อินเตอรัพท์). A pending register จะรักษาสถานะของแต่ละขาของ the interrupt requests (เกิดการทริกที่ขอบขาขึ้นหรือขอบขาลง(แล้วแต่เราจะเลือก) แล้วมีการไม่ mask ด้วย ถึงจะเกิด interrupt requests) 

tha

10.2.1 Main features
The EXTI controller main features เป็นไปตามนี้ :
   • Independent trigger(เลือกขอบขาที่จะทริก) และ mask(ถ้า mask(เป็น '0') ก็ไม่ยอมให้เกิดอินเตอรัพท์ได้ ถ้าไม่ mask(เป็น '1') ก็ยอมให้เกิดอินเตอรัพท์) ในแต่ละ interrupt/event line
   • มีบิตที่แสดงสถานะการเกิดอินเตอรัพท์ของแต่ละ interrupt line (ที่ pending register หรือเปล่า?)
   • สามารถสร้าง event/interrupt requests ด้วยซอฟแวร์ ได้ถึง 20 ตัว
   • การตรวจจับสัญญานภายนอกที่เป็นสัญญานพลัลส์ที่ต่ำกว่าสัญญาน APB2 clock period. ดูที่ the electrical characteristics section ของ the datasheet สำหรับรายละเอียดของ parameter นี้.

tha


มีการเลือกขอบขา
มีการสร้างสัญญานอินเตอรัพท์ด้วยซอฟแวร์
มีการ mask ไม่ mask
มีการค้างสถานะของการเกิดอินเตอรัพท์
ส่วน Pluse Generator สร้างสัญญานพลัสไปทางไหนก็ยังไม่ทราบครับ


tha

10.2.3 Wakeup event management
The STM32F10xxx สามารถที่จะจัดการกับ external หรือ internal events เพื่อ wake up the core(WFE). The wakeup event สามารถถูกสร้างโดยอย่างใดอย่างหนึ่ง:
   • เปิดใช้งาน an interrupt ใน the peripheral control register แต่ไม่ใช่ใน the NVIC, และเปิดใช้งานบิต(ทำให้เป็น '1') the
      SEVONPEND bit ใน the Cortex®-M3 System Control register. เมื่อ MCU ดำเนินการต่อจาก WFE, the peripheral
      interrupt pending bit และ the peripheral NVIC IRQ channel pending bit (ใน the NVIC interrupt clear pending
      register) ต้องถูกเคลียร์.
   • หรือกำหนดค่า an external หรือ internal EXTI line ใน event mode. เมื่อ the CPU  ดำเนินการต่อจาก WFE, มันไม่จำเป็นที่จะ
      ต้องเคลียร์ the peripheral interrupt pending bit หรือ the NVIC IRQ channel pending bit เพราะ the pending bit ที่ตรง
      กันกับ the event line นั้นๆไม่ได้ถูกเซ็ต.
ใน connectivity line devices, Ethernet wakeup events มีความสามารถที่จะ the WFE wakeup อีกด้วย.
เพื่อใช้ an external line เป็น a wakeup event, ดูที่ Section 10.2.4: Functional description.

ปล. แปลไปก่อนนะ ยังไม่ชัดเท่าไหร่ หาบิตกันเอาเองนะครับ ตอนนี้ผมยังมึนอยู่ คงยังไม่ได้ใช้ ก็แปลให้รู้คร่าวๆไปก่อน ท่านใดจะใช้ก็ศึกษากันต่อไปนะตรับ

tha

10.2.4 Functional description
เพื่อทำให้เกิด the interrupt, the interrupt line ต้องถูกกำหนดค่าและเปิดการใช้งาน. นี้สามารถทำโดยการโปรแกรม the two trigger registers ด้วย the desired edge detection(ขอบขาที่ต้องการตรวจจับ) และโดยการเปิดใช้งาน the interrupt request(การร้องขออินเตอรัพท์) โดยการเขียน '1' ไปยังบิตที่ตรงกันใน the interrupt mask register. เมื่อขอบขา(ขึ้นหรือลง)ที่เลือกเกิดขึ้นบน the external interrupt line, an interrupt request จึงถูกสร้างขึ้น. The pending bit ที่ตรงกับ the interrupt line ก็ถูกเซตอีกด้วย. interrupt request นี้จะถูกรีเซ็ตโดยการเขียน '1' ใน the pending register (ในบิตที่ตรงกัน).

เพื่อทำให้เกิด the event, the event line ต้องถูกกำหนดค่าและเปิดการใช้งาน. นี้สามารถทำโดยการโปรแกรม the two trigger registers ด้วย the desired edge detection(ขอบขาที่ต้องการตรวจจับ) และโดยการเปิดใช้งาน the event request โดยการเขียน '1' ไปยังบิตที่ตรงกันใน the event mask register.  เมื่อขอบขา(ขึ้นหรือลง)ที่เลือกเกิดขึ้นบน the event line, an event pulse(พลัสเดียว)ถูกสร้างขึ้น. The pending bit ที่ตรงกันกับ the event line ไม่ได้ถูกเซ็ต
An interrupt/event request สามารถถูกสร้างขึ้นโดย software โดยการเขียน '1' ใน the software interrupt/event register

tha

Hardware interrupt selection
เพื่อกำหนด the 20 lines ให้เป็น interrupt sources, ใช้ขบวนการดังต่อไปนี้ :
   • กำหนดค่า the mask bits(ให้เป็น '1')ของ the 20 Interrupt lines (EXTI_IMR)
   • กำหนดค่า the Trigger Selection bits ของ the Interrupt lines (EXTI_RTSR(ขอบขาขึ้น) and EXTI_FTSR(ขอบขาลง))
   • กำหนดค่า the enable และ mask bits ที่ควบคุม the NVIC IRQ channel ที่ mapped ถึง the External Interrupt
     Controller (EXTI) เพื่อที่ว่า interrupt ที่มาจากหนึ่งใน the 20 lines สามารถถูกรู้จักได้อย่างถูกต้อง.(ผมไม่ชัดนะตรงนี้ ท่านใดทราบโปรดเสริมมาด้วยครับ)

Hardware event selection
เพื่อกำหนด the 20 lines ให้เป็น event sources, ใช้ขบวนการดังต่อไปนี้:
   • กำหนดค่า the mask bits(mask เป็น '0' ไม่ mask เป็น '1')ของ the 20 Event lines (EXTI_EMR)
   • กำหนดค่า the Trigger Selection bits ของ the Event lines (EXTI_RTSR and EXTI_FTSR)

Software interrupt/event selection
The 20 lines สามารถถูกำหนดเป็น software interrupt/event lines. ขบวนการดังต่อไปนี้ทำให้เกิด software interrupt.
   • กำหนดค่า the mask bits ของ the 20 Interrupt/Event lines (EXTI_IMR, EXTI_EMR)
   • เซ็ตบิตที่ต้องการของ the software interrupt register (EXTI_SWIER)

tha

https://scienceprog.com/interrupt-based-button-read-on-stm32f103zet6-board/
เจอแล้วที่บอกว่าไม่ชัด ก็ต้องมีการเซ็ตอินเตอรัพท์ที่ NVIC ด้วย ตามที่เขาบอกตรงนี้ ต้องขอขอบคุณเขามา ณ ที่นี้ด้วยครับ

The whole procedure of enabling interrupts consists of the following steps:
(ขั้นตอนทั้งหมดของการเปิดใช้งาน interrupts ประกอบด้วยขั้นตอนต่อไปนี้:)
1.Select the interrupt channel in NVIC module;(เลือก interrupt channel ใน NVIC module)
2.Set preemptive priority; (priority ก็มีอยู่ 4 บิต ก็แบ่งเป็น preemptive priority 2 บิตสูง sub-priority 2 บิตต่ำ)
3.Set sub-priority;
4.Enable interrupt for a particular line.(ทำการเปิดใช้งาน interrupt สำหรับเฉพาะอินเตอรัพท์ที่เราใช้ไป)


tha