使用LL库编程时,发现外设中断即使使能也进不了中断。
: y: K/ z/ t9 K' g- n& O& G, m, C5 Z一般外设都会有自己的寄存器来控制中断的开关,比如ADC 中断使能寄存器 (ADC_IER),但是,将里面相应的位置位后,中断仍然不能相应。
( N' P5 l0 N6 S这是因为总的NVIC开关没有打开。这点也好理解。有过STM32开发经验的人都知道,NVIC有开关来控制外设的中断使能。但是在LL库如何实现呢?
8 [3 o+ N3 {5 e翻遍了LL库并没有相应的函数。因为NVIC属于CORTEX内核的东西,外设函数是触摸不到的。(而HAL库是有类似的函数的)
l) d" w3 K* p7 {+ E5 a, C% x5 J2 B( j# Q. E2 ?6 k+ ?6 y, W
以下是NVIC寄存器: {7 R+ j$ b6 C% W2 H
, E) m; f- l& i4 F6 F
5 I4 g) T) T$ x! n+ |( D$ b: d1 [
3 |" ~& U( W& X下图是对NVIC操作的函数) i% l" ?0 ?8 j8 O1 Q/ Z5 T) `7 D
) C0 \" [' r/ \3 t" I
3 v2 l( z: [4 O" A( c( x. W, h下面是各个中断的序号
7 ~4 P) u4 }" r, J8 o' P8 f# l* m7 Z1 u; @
- /** @addtogroup Peripheral_interrupt_number_definition" w' `, `, ]1 M. u: ]0 H3 x3 I8 l
- * @{: Y2 Q# H" V+ l, z4 O8 Q8 Y
- */$ r# Z4 X6 \+ G/ W9 s
D4 m/ _- x2 z9 a- o- /**
( T/ Z6 r8 D3 X' ]. i" I$ G - * @brief stm32l011xx Interrupt Number Definition, according to the selected device
+ f/ g, {- g1 T. V* u8 T2 R - * in @ref Library_configuration_section
9 V7 z& m' q; B1 d9 k3 a9 z) } - */ {0 b- R& @$ ]: x* a$ J
2 A) [) p* Y% _: b3 S( z: {" Z+ O1 }. x- /*!< Interrupt Number Definition */
. f, W. `+ c" k' e0 }( M9 A# d$ j - typedef enum w. V# P& Z& O& E, B
- {
' C% L; ~3 q1 z+ c# D - /****** Cortex-M0 Processor Exceptions Numbers ******************************************************/5 C8 u2 d- i$ g. |
- NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */
6 N) x; S! m9 l- X$ k e. ^# g y - HardFault_IRQn = -13, /*!< 3 Cortex-M0+ Hard Fault Interrupt */
5 t# g( Z# `4 ?' I - SVC_IRQn = -5, /*!< 11 Cortex-M0+ SV Call Interrupt */
+ M+ n8 [$ t( J8 R7 _ - PendSV_IRQn = -2, /*!< 14 Cortex-M0+ Pend SV Interrupt */
$ n. C) L! u) _4 h+ m! P - SysTick_IRQn = -1, /*!< 15 Cortex-M0+ System Tick Interrupt */
; J$ ?8 L/ S2 U0 X) a9 |. U# d9 v - ; T+ @! ?8 {+ h$ J$ g. ^
- /****** STM32L-0 specific Interrupt Numbers *********************************************************/
9 M' l+ h5 x% G - WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */: `: J8 N' f# O' P8 K D
- PVD_IRQn = 1, /*!< PVD through EXTI Line detect Interrupt */
# z n$ H B" U - RTC_IRQn = 2, /*!< RTC through EXTI Line Interrupt */2 G% P ~( e1 o" Q
- FLASH_IRQn = 3, /*!< FLASH Interrupt */
* N. k C0 K r' \2 o - RCC_IRQn = 4, /*!< RCC Interrupt */
! Z" ]! D- D) t0 X1 J - EXTI0_1_IRQn = 5, /*!< EXTI Line 0 and 1 Interrupts */
' T0 N' y9 M) D' [6 v$ U - EXTI2_3_IRQn = 6, /*!< EXTI Line 2 and 3 Interrupts */
( Z0 ?. J# h8 g* K* i - EXTI4_15_IRQn = 7, /*!< EXTI Line 4 to 15 Interrupts */
6 g! A" s2 Q; y! C( A* o0 V - DMA1_Channel1_IRQn = 9, /*!< DMA1 Channel 1 Interrupt */% r' R N$ M- J* O
- DMA1_Channel2_3_IRQn = 10, /*!< DMA1 Channel 2 and Channel 3 Interrupts */1 | ?; _ A# j
- DMA1_Channel4_5_6_7_IRQn = 11, /*!< DMA1 Channel 4, Channel 5, Channel 6 and Channel 7 Interrupts */! o/ J! R* K. i7 r# o; l0 T$ I
- ADC1_COMP_IRQn = 12, /*!< ADC1, COMP1 and COMP2 Interrupts */
x) m# P" `, V7 ^7 |8 p7 e; O2 P - LPTIM1_IRQn = 13, /*!< LPTIM1 Interrupt */
' I- h7 v3 B0 ?" U. @$ p - TIM2_IRQn = 15, /*!< TIM2 Interrupt */7 x: @" j e/ I2 I" L
- TIM21_IRQn = 20, /*!< TIM21 Interrupt */
, A4 b; c) c& L3 W4 a - I2C1_IRQn = 23, /*!< I2C1 Interrupt */" H7 ]4 Y' X$ d u) _9 a5 O- W$ \
- SPI1_IRQn = 25, /*!< SPI1 Interrupt */
3 k+ P5 F; e1 v, L x/ E - USART2_IRQn = 28, /*!< USART2 Interrupt */
" L, _7 ]4 {$ ]/ k/ f# g: H+ p, A - LPUART1_IRQn = 29, /*!< LPUART1 Interrupt */
# a+ `+ v( s7 d" Y4 j4 v. Y - } IRQn_Type;
复制代码
, S; o; h+ P8 W2 o t1 _5 n例如将ADC1中断使能,除了对ADC1内部的相应中断位(ADC_IER)使能外,还需要使用下列语句才可以:4 H5 b, m0 z F9 C) s+ c- ?
. Z0 Y6 t( l }+ _
NVIC_EnableIRQ(ADC1_COMP_IRQn);
( m& Q# O8 B5 |6 b: }4 A( e
- g& x q1 C* b" d) T* G
0 w! ?. H' p+ I- S; I; R E' m5 C
, C' _1 G- p: U |