使用LL库编程时,发现外设中断即使使能也进不了中断。- f r/ j& i! n
一般外设都会有自己的寄存器来控制中断的开关,比如ADC 中断使能寄存器 (ADC_IER),但是,将里面相应的位置位后,中断仍然不能相应。
( B- j y, l L2 k1 S, N2 f/ d这是因为总的NVIC开关没有打开。这点也好理解。有过STM32开发经验的人都知道,NVIC有开关来控制外设的中断使能。但是在LL库如何实现呢?
* P! j6 O- q1 {4 U- }翻遍了LL库并没有相应的函数。因为NVIC属于CORTEX内核的东西,外设函数是触摸不到的。(而HAL库是有类似的函数的)
8 h r) |7 A9 g# F1 R" j" H
* D8 s3 J% n& X& I3 O7 j: I- @9 x以下是NVIC寄存器
% z) q! h- {- K4 r5 D- v- @# G
# K2 l! v/ X3 \0 E+ b& o% v7 K% M7 r8 P, v- M4 f; R$ F' U
4 ~) q7 g" M, h, u3 {+ i; P6 w/ \下图是对NVIC操作的函数
! w4 @) x0 a. C, X a) O. r$ O
7 T F( K1 M v% m2 |
4 S- n2 c/ s0 [) p: C6 f3 j% E下面是各个中断的序号
+ P% N) p+ H# g% o5 Z4 k* O; v! r7 {- r' K- I" M5 i7 Y2 k Z0 s
- /** @addtogroup Peripheral_interrupt_number_definition
9 B3 w8 }1 D! |+ K/ V4 I - * @{& n5 E; W! t+ q# f
- */" D3 [* X3 i; G; h% g
- / e9 I8 @ G6 w3 D' G
- /**
8 N+ j5 w8 e( h# {6 N" r - * @brief stm32l011xx Interrupt Number Definition, according to the selected device : P' I: P/ ]5 Y4 C; x. P' y6 _
- * in @ref Library_configuration_section ; O0 [8 M& J/ g$ E3 s
- */
, q3 Y, }# O+ `0 u6 X
9 T# o/ ]. P% j& F- /*!< Interrupt Number Definition */9 V4 K3 E, @/ u) f
- typedef enum
# ]1 _5 z' P/ ^+ O - {0 m* _" H4 m: ~* [: F
- /****** Cortex-M0 Processor Exceptions Numbers ******************************************************/
l0 |) H" [" |; N - NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
' s ]; @4 ]0 h: k u* B8 Z& ~ - HardFault_IRQn = -13, /*!< 3 Cortex-M0+ Hard Fault Interrupt */4 i2 @. g0 @6 D
- SVC_IRQn = -5, /*!< 11 Cortex-M0+ SV Call Interrupt */
5 \7 b, f/ L. H5 f- U; z - PendSV_IRQn = -2, /*!< 14 Cortex-M0+ Pend SV Interrupt */) [0 H1 S7 b' O @+ i% I, U- |
- SysTick_IRQn = -1, /*!< 15 Cortex-M0+ System Tick Interrupt */" L, ?* ^ o9 d6 o5 u. P
- 7 F |8 N. E' j- C+ ^
- /****** STM32L-0 specific Interrupt Numbers *********************************************************/' P! K% h# P0 r: O0 q
- WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */
) b/ s* |- ^0 O4 w# p8 j- S/ i - PVD_IRQn = 1, /*!< PVD through EXTI Line detect Interrupt */
, X& J4 W4 @% O - RTC_IRQn = 2, /*!< RTC through EXTI Line Interrupt */& M4 q# h8 F( S* G
- FLASH_IRQn = 3, /*!< FLASH Interrupt */3 I8 V s U5 M' J: s5 Y- [9 L
- RCC_IRQn = 4, /*!< RCC Interrupt */
3 _" s4 i7 N4 A! v. b3 N+ V - EXTI0_1_IRQn = 5, /*!< EXTI Line 0 and 1 Interrupts */4 i) U8 r" d2 i5 B0 B& s
- EXTI2_3_IRQn = 6, /*!< EXTI Line 2 and 3 Interrupts */
7 b6 z v6 ]6 @( ^, [/ e6 ] - EXTI4_15_IRQn = 7, /*!< EXTI Line 4 to 15 Interrupts */6 M6 F- g- p3 v# ]5 w' @# s5 |
- DMA1_Channel1_IRQn = 9, /*!< DMA1 Channel 1 Interrupt */5 _3 f& [( d5 v8 w) C
- DMA1_Channel2_3_IRQn = 10, /*!< DMA1 Channel 2 and Channel 3 Interrupts */
8 I. V/ e F* n& B6 Z2 Z, | - DMA1_Channel4_5_6_7_IRQn = 11, /*!< DMA1 Channel 4, Channel 5, Channel 6 and Channel 7 Interrupts */
- Z% A/ w% G; F* P0 ~* b# s3 O2 S4 [0 k% b - ADC1_COMP_IRQn = 12, /*!< ADC1, COMP1 and COMP2 Interrupts */
9 m* _8 u* A( h4 e! y0 \/ n4 G - LPTIM1_IRQn = 13, /*!< LPTIM1 Interrupt */+ v5 y% V s p" t0 y, M
- TIM2_IRQn = 15, /*!< TIM2 Interrupt */
" l* J0 w) ]9 F& ?# e8 |& \ - TIM21_IRQn = 20, /*!< TIM21 Interrupt */
+ M0 d( c% L# b, l& t5 v. s - I2C1_IRQn = 23, /*!< I2C1 Interrupt */
( z7 S' b7 U" T) B9 l4 M - SPI1_IRQn = 25, /*!< SPI1 Interrupt */
4 n# V7 s& O B3 }2 T4 ? - USART2_IRQn = 28, /*!< USART2 Interrupt */
7 N9 M/ L: Y3 ~1 s, k3 f - LPUART1_IRQn = 29, /*!< LPUART1 Interrupt */) }! W5 W2 z" d% P
- } IRQn_Type;
复制代码
# J: v* Y1 m9 u; f) V例如将ADC1中断使能,除了对ADC1内部的相应中断位(ADC_IER)使能外,还需要使用下列语句才可以:. p+ B) K9 Z2 Y' w/ R% o
8 z4 r$ q; `, Y- Z. e
NVIC_EnableIRQ(ADC1_COMP_IRQn);" r( B4 A O( {" V0 I) n$ ^
$ y6 U3 G0 c1 U; q0 y4 Z U' k! p. N( ]3 }, ` F% J& K E. A* m6 X
" t% p4 Q6 H( L' \: A3 q2 e8 @
|