首先 SPI 的NVIC 宣告
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* 1 bit for pre-emption priority, 3 bits for subpriority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Configure and enable SPI1 interrupt -------------------------------------*/
NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure and enable SPI2 interrupt -------------------------------------*/
NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
}
stm32中断应使用在 stm32f10x_it.c
Main Interrupt Service Routines
Example
void SPI1_IRQHandler(void)
{
if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_TXE) != RESET)
{
/* Send SPI1 data */
SPI_I2S_SendData(SPI1, SPI1_Buffer_Tx[TxIdx++]);
/* Disable SPI1 TXE interrupt */
if (TxIdx == BufferSize)
{
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);
}
}
}
|