打印
[STM32F1]

采用stm32f103ve的SPI1,用DMA方式发送数据,不能进入中断函数

[复制链接]
5388|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
闲来2012|  楼主 | 2014-3-17 16:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
配置SPI1工作在DMA模式下,采用循环模式,数据可以正常的经由DMA发送,传输完成后,中断寄存器的传输完成中断标志位被置位,但是不能进入中断函数,请教各位,是什么原因?

void SpiCC3000Init(void)
{
     SPI_InitTypeDef   SPI_InitStructure;
    GPIO_InitTypeDef  GPIO_InitStructure;
  /*!< Disable SPI */
  SPI_Cmd(SPI_USED, DISABLE);

  /*!< DeInitializes the SPI */
  SPI_I2S_DeInit(SPI_USED);

  /*!< SPI Periph clock disable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 , DISABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 , DISABLE);   
        /*Enable SPI2 Clock */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
  RCC_APB2PeriphClockCmd(        RCC_APB2Periph_GPIOB,        ENABLE);
        /*Enable SPI1 Clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 |RCC_APB2Periph_GPIOA,ENABLE);
        /*Config  clk and mosi */
        GPIO_InitStructure.GPIO_Pin = SPI_CLK_PIN| SPI_MOSI_PIN;//
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//AF_PP
        GPIO_Init(SPI_PORT, &GPIO_InitStructure);
       

      /*!< Configure SPI pins: MISO */
        GPIO_InitStructure.GPIO_Pin = SPI_MISO_PIN;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
        GPIO_Init(SPI_PORT, &GPIO_InitStructure);
        /*!< Configure SPI pins: CS output high */
        GPIO_InitStructure.GPIO_Pin = SPI_CS_PIN;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(SPI_PORT, &GPIO_InitStructure);

  /*!< CC3000 SPI Init */
  SPI_StructInit(&SPI_InitStructure);
  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;

  /* The buadrate is a fraction of the 32MHz clock*/
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;//32
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
        SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SPI_USED, &SPI_InitStructure);
  /*!< Enable SPI interrupt */
  SPI_I2S_ClearITPendingBit(SPI_USED, SPI_I2S_IT_TXE);
  SPI_I2S_ITConfig(SPI_USED, SPI_I2S_IT_TXE, ENABLE);     
  /*!< SPI Init */
  SPI_SSOutputCmd(SPI_USED,ENABLE);
  SPI_Cmd(SPI_USED, ENABLE);

  /*Configure SPI for DMA Operation*/
#if defined(ENABLE_SPI_DMA)
  SpiCC3000DMAInit();
#else
  //SpiRxInterruptClkInit();
#endif
}
void SpiCC3000DMAInit(void)
{
       
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

       
  DMA_DeInit(SPI_DMA_RX_CHANNEL);
  DMA_DeInit(SPI_DMA_TX_CHANNEL);

  /* Configure and enable SPI DMA TX Channel interrupt */
  //NVIC_RxInt_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn; //SPI2 TX
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
        NVIC_RxInt_InitStructure.NVIC_IRQChannel = DMA1_Channel3_IRQn;//SPI1 TX // not config the Rx channel
  NVIC_RxInt_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_RxInt_InitStructure.NVIC_IRQChannelSubPriority = 0;//0
  NVIC_RxInt_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_RxInt_InitStructure);
        //yichuan
       
  DMA_ITConfig(SPI_DMA_TX_CHANNEL, DMA1_IT_TC3, ENABLE);
// DMA_ITConfig(SPI_DMA_RX_CHANNEL, DMA_IT_TC, ENABLE);

  /* Enable the DMA Channels Interrupts */
// DMA_ITConfig(SPI_DMA_TX_CHANNEL, DMA_IT_TC, ENABLE);
// DMA_ITConfig(SPI_DMA_RX_CHANNEL, DMA_IT_TC, ENABLE);   
  /* Configure DMA Peripheral but don't send data*/
  C3000_DMA_Config(SPI_DMA_RX, (uint8_t*)wlan_rx_buffer,0);
//C3000_DMA_Config(SPI_DMA_TX, (uint8_t*)wlan_tx_buffer,0);
  C3000_DMA_Config(SPI_DMA_TX, (uint8_t*)wlan_tx_buffer,1700);  //buffer is 1700
       

    /* Enable SPI DMA request */
  SPI_I2S_DMACmd(SPI_USED,SPI_I2S_DMAReq_Tx, ENABLE);
  SPI_I2S_DMACmd(SPI_USED,SPI_I2S_DMAReq_Rx, ENABLE);
   /* Enable DMA RX Channel */
  DMA_Cmd(SPI_DMA_RX_CHANNEL, ENABLE);  
/* Enable DMA TX Channel */  
  DMA_Cmd(SPI_DMA_TX_CHANNEL, ENABLE);
}


static void C3000_DMA_Config(SPI_DMADirection_TypeDef Direction, uint8_t* buffer, uint16_t NumData)
{
       
#if defined(ENABLE_SPI_DMA)
  DMA_InitTypeDef DMA_InitStructure;
  /* Initialize the DMA_PeripheralBaseAddr member */
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t )&SPI1->DR; //SPI_DR_BASE; //
  /* Initialize the DMA_MemoryBaseAddr member */
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)buffer;
   /* Initialize the DMA_PeripheralInc member */
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  /* Initialize the DMA_MemoryInc member */
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  /* Initialize the DMA_PeripheralDataSize member */
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  /* Initialize the DMA_MemoryDataSize member */
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  /* Initialize the DMA_Mode member */
        //yichuan
  //DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
        DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  /* Initialize the DMA_Priority member */
  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
  /* Initialize the DMA_M2M member */
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  /* If using DMA for Reception */
  if (Direction == SPI_DMA_RX)
  {
    /* Initialize the DMA_DIR member */
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

    /* Initialize the DMA_BufferSize member */
    DMA_InitStructure.DMA_BufferSize = NumData;

    DMA_DeInit(SPI_DMA_RX_CHANNEL);

    DMA_Init(SPI_DMA_RX_CHANNEL, &DMA_InitStructure);
  }
   /* If using DMA for Transmission */
  else if (Direction == SPI_DMA_TX)
  {
    /* Initialize the DMA_DIR member */
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

    /* Initialize the DMA_BufferSize member */
    DMA_InitStructure.DMA_BufferSize = NumData;

    DMA_DeInit(SPI_DMA_TX_CHANNEL);

    DMA_Init(SPI_DMA_TX_CHANNEL, &DMA_InitStructure);
  }
#endif
}


void DMA1_Channel3_IRQHandler(void)
{
    if(DMA_GetITStatus(DMA1_IT_TC3)==SET)
    {
          GPIO_InitTypeDef GPIO_InitStructure;
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
         GPIO_Init(GPIOC, &GPIO_InitStructure);
         GPIO_ResetBits(GPIOC,GPIO_Pin_6);

    }
   DMA_ClearITPendingBit(DMA1_IT_TC3);

}





沙发
闲来2012|  楼主 | 2014-3-17 16:52 | 只看该作者
自己顶一下。

使用特权

评论回复
板凳
mmuuss586| | 2014-3-17 19:42 | 只看该作者
用厂家自带的例程可以吗

使用特权

评论回复
地板
闲来2012|  楼主 | 2014-3-17 20:39 | 只看该作者
厂家的历程没有试过,配置到spi2的dma也是一样的现象,中断标志位能够置位,还是不能进入中断处理函数。

使用特权

评论回复
5
闲来2012|  楼主 | 2014-3-17 21:34 | 只看该作者
问题解决了,DMA_ITConfig(SPI_DMA_TX_CHANNEL, DMA_IT_TC, ENABLE);这句话被放在DMA的初始化(配置)前面去了,应该放到初始化后面才能正常工作。

使用特权

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

本版积分规则

2

主题

77

帖子

0

粉丝