打印
[STM32F1]

无法进入SPI2 接收中断

[复制链接]
1040|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
pb1005|  楼主 | 2016-4-6 21:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
spi, IO, ni, gp, GPIO
SPI2作为从机接收数据,但是无论如何也进不了它的中断。请高手指教,谢谢!
程序如下

void SPI_COMMS_GPIO_init(void)
{   
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
       
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_12;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_14;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_13|GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
}

void SPI_COMMS_SPI_init(void)
{
       
        SPI_InitTypeDef   SPI_InitStructure;
        SPI_InitStructure.SPI_Mode=SPI_Mode_Slave;
        SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;         //0
        SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
        SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
        SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
        SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
        SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_128;
        SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
        SPI_InitStructure.SPI_CRCPolynomial = 0;
        SPI_Init(SPI2,&SPI_InitStructure);
        SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);
       
}

void SPI_COMMS_init(void)
{
        SPI_COMMS_GPIO_init();
        SPI_COMMS_SPI_init();
        SPI_COMMS_NVIC_Configuration();
        SPI_Cmd(SPI2,ENABLE);
       
}

void SPI_COMMS_SEND(unsigned char theFunc, unsigned char no)
{
       
}

void SPI_COMMS_NVIC_Configuration(void)
{

  //EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  /* Configure one bit for preemption priority */
  #if defined (VECT_TAB_RAM)
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#elif defined(VECT_TAB_FLASH_IAP)
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x2000);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif

  /* Configure the NVIC Preemption Priority Bits */  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

  
  NVIC_InitStructure.NVIC_IRQChannel =  SPI2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void SPI2_IRQHandler(void)
{
  SPI_I2S_ClearITPendingBit(SPI2, SPI_I2S_IT_RXNE);
        SPI_I2S_SendData(SPI2, 0x23);
}
沙发
pb1005|  楼主 | 2016-4-6 21:36 | 只看该作者
自已先顶一下

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

27

帖子

0

粉丝