OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2839|回复: 4

SPI2无法进入中断

[复制链接]

1

主题

4

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2016-2-16
在线时间
4 小时
发表于 2016-4-7 11:08:21 | 显示全部楼层 |阅读模式
3金钱
我在做试验时候,用两个模拟板发送数据,一块作为SPI SLAVE 用SPI2接收数据. 但是发现SPI2无法进入中断,接线都是良好的。
请教大侠是哪里设置错误了。

对于SPI的设置如下
#include "includes.h"



void SPI_COMMS_GPIO_init(void)
{   
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, 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_8; //optional usage
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_14|GPIO_Pin_13|GPIO_Pin_15;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
       
        GPIO_SetBits(GPIOA,GPIO_Pin_8);
}

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_NSSInternalSoftwareConfig(SPI2, SPI_NSSInternalSoft_Set); //CS select
        SPI_Cmd(SPI2,ENABLE);       
}


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)
{
        GPIO_ResetBits(GPIOA,GPIO_Pin_8);
}



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2016-2-16
在线时间
4 小时
 楼主| 发表于 2016-4-7 14:02:06 | 显示全部楼层
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2016-2-16
在线时间
4 小时
 楼主| 发表于 2016-4-7 14:33:13 | 显示全部楼层
SPI_NSSInternalSoftwareConfig(SPI2, SPI_NSSInternalSoft_Reset); // corrected by myself, but the problem still exists
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2016-2-16
在线时间
4 小时
 楼主| 发表于 2016-4-7 20:43:16 | 显示全部楼层
最新发现,和UCOS有关。不用UCOS的能收到。显然设置没错,但不知道为什么用了UCOS SPI中断就没有用了。
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-4-9 22:04:49 | 显示全部楼层
pb1005 发表于 2016-4-7 20:43
最新发现,和UCOS有关。不用UCOS的能收到。显然设置没错,但不知道为什么用了UCOS SPI中断就没有用了。

是不是ucosii禁止了中断?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-18 21:23

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表