|
stm32 spi1和spi3通讯,进不了中断处理函数
[复制链接]
GPIO初始化:
/* SPI1 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* SPI3 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4 |GPIO_Pin_5;
GPIO_Init(GPIOB, &GPIO_InitStructure);
NVIC初始化:
/* Enable the SPI1 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the SPI3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
SPI初始化:
void SPI_Cfg(void)
{
SPI_InitTypeDef SPI_InitStructure;
/* SPI1 Configuration */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//µ¥ÏßË«Ïò·¢ËÍ
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/* SPI3 Configuration */
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_Init(SPI3, &SPI_InitStructure);
//--------- Enable SPI1 TXE interrupt ------------
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);
//--------- Enable SPI3 RXNE interrupt -------------
SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_RXNE, ENABLE);
}
中断处理函数:
void SPI1_IRQHandler(void)
{
GPIO_ResetBits(GPIOC, GPIO_Pin_1);
SPI_WriteByte(SPI1,SPI1_Buffer_Tx[TxId++]);
if(TxId == BufferSize)
{
TxId = 0;
// GPIO_ResetBits(GPIOC, GPIO_Pin_1);
SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, DISABLE);
}
}
void SPI3_IRQHandler(void)
{
GPIO_ResetBits(GPIOC, GPIO_Pin_14);
SPI3_Buffer_Rx[RxId++] = SPI_ReadByte(SPI3);
if(RxId == BufferSize)
{
RxId = 0;
// GPIO_ResetBits(GPIOC, GPIO_Pin_14);
//USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
}
}
就是进不了中断处理函数!?!?!?!?!?
|
|