[其他ST产品]

STR911FA42X6进不去中断

[复制链接]
518|10
手机看帖
扫描二维码
随时随地手机跟帖
sebrina2010|  楼主 | 2018-11-21 10:11 | 显示全部楼层 |阅读模式
ST, IO, pi, gp, GPIO
在官网的程序上改的,不知道为何进不去中断?串口和CAN中断都进不去,怀疑时钟的问题?
/******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 05/18/2006 : Version 1.0
* Description        : Main program body
********************************************************************************
* History:
* 05/24/2006 : Version 1.1
* 05/18/2006 : Version 1.0
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "91x_lib.h"
#include "91x_fmi.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define TxBufferSize   (countof(TxBuffer) - 1)
#define RxBufferSize   0xFF

/* Private macro -------------------------------------------------------------*/
#define countof(a)   (sizeof(a) / sizeof(*(a)))

/* Private variables ---------------------------------------------------------*/
  UART_InitTypeDef UART_InitStructure;
  u8 TxBuffer[] = "UART Example1: UART - Hyperterminal communication using hardware flow control\n\r";
u8 RxBuffer[RxBufferSize];
  u8 NbrOfDataToTransfer = TxBufferSize;
  u8 TxCounter = 0;
  u8 RxCounter = 0;
   u8 data =0;
/* Private function prototypes -----------------------------------------------*/
  void SCU_Configuration(void);
  void GPIO_Configuration(void);

/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
/*static void Delay(u32 nCount)
{
  u32 j = 0;

  for(j = nCount; j != 0; j--);
}
*/
  
int main()
{
  #ifdef DEBUG
    debug();
  #endif

  /* Configure the system clocks */
  SCU_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  /*  configuration -------------------------------------------------------*/
  /* UART2 configured as follow:
        - Word Length = 7 Bits
        - Two Stop Bit
        - No parity
        - BaudRate = 115200 baud
        - Hardware flow control enabled (RTS and CTS signals)
        - Receive and transmit enabled
        - Receive and transmit FIFOs are enabled
        - Transmit and Receive FIFOs levels have 8 bytes depth
  */
  UART_InitStructure.UART_WordLength = UART_WordLength_8D;
  UART_InitStructure.UART_StopBits = UART_StopBits_1;
  UART_InitStructure.UART_Parity = UART_Parity_No ;
  UART_InitStructure.UART_BaudRate = 9600;
// UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
  UART_InitStructure.UART_FIFO = UART_FIFO_Disable ;
// UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */
// UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */

  UART_DeInit(UART2);
  UART_Init(UART2, &UART_InitStructure);
  
// GPIO_WriteBit(GPIO4, GPIO_Pin_5, Bit_RESET);

  /* Enable the UART Receive interrupt*/
UART_ITConfig(UART2, UART_IT_Receive, ENABLE);
//     UART2->IMSC |= 0x0010;

  /* Enable VIC clock */
//SCU_AHBPeriphClockConfig(__VIC, ENABLE);
  /*configure UART2 interrupt in VIC*/
VIC_DeInit();
VIC_InitDefaultVectors(); /* initialize VICs default vector registers*/
VIC_Config(UART2_ITLine, VIC_IRQ, 0);
/* Enable the UART2 */
UART_Cmd(UART2, ENABLE);
//     VIC1->VAiR[2]=(u32)UART2_IRQHandler;
//      VIC1->INTSR &= ~4;
//      VIC1->VCiR[2] |=0x20;
// VIC1->VCiR[2] &=  0xFFFFFFE0;
//    VIC1->VCiR[2] |=0x02;
//      UART2->CR |= 0x0001;
//       VIC1->INTER |= 4;
GPIO_WriteBit(GPIO4, GPIO_Pin_5, Bit_RESET);
/*enable UART2 interrupt for data reception*/
VIC_ITCmd(UART2_ITLine,ENABLE);




while (1)
{
  
data = UART_ReceiveData(UART2);
if(data==0xaa)
{
GPIO_WriteBit(GPIO4, GPIO_Pin_5, Bit_SET);
UART_SendData(UART2,data);  
while(UART_GetFlagStatus(UART2, UART_FLAG_Busy) == SET);

GPIO_WriteBit(GPIO4, GPIO_Pin_5, Bit_RESET);
}

}
}

void SCU_Configuration(void)
{
   SCU_MCLKSourceConfig(SCU_MCLK_OSC);   /* Default configuration */

  /*wait state insertion :This function should be executed from SRAM when*/
  /*booting from bank1 to avoid  Read-While-Write from the Same Bank.*/
  FMI_Config(FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_0, FMI_PWD_ENABLE,\
                 FMI_LVD_ENABLE, FMI_FREQ_HIGH);/*Insert 2 Wait States for read*/

  SCU_PLLFactorsConfig(192, 8, 2); /* PLL factors Configuration based on*/
                                        /* a OSC/Crystal value = 25Mhz*/
  SCU_PLLCmd(ENABLE);  /* PLL Enable and wait for Locking*/                                    
      SCU_RCLKDivisorConfig(SCU_RCLK_Div1); /* RCLK @Osc/crystal Frequency*/
      SCU_HCLKDivisorConfig(SCU_HCLK_Div1); /* AHB @Osc/crystal Frequency*/
      SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1);/* FMI @Osc/crystal Frequency*/
      SCU_PCLKDivisorConfig(SCU_PCLK_Div2); /* APB @Osc/crystal Frequency*/
      SCU_MCLKSourceConfig(SCU_MCLK_OSC);  /* MCLK @Osc/crystal Frequency*/
  /* Enable UART2 Clock */
  SCU_APBPeriphClockConfig(__UART2, ENABLE);
  
  /* Enable VIC clock */
SCU_AHBPeriphClockConfig(__VIC, ENABLE);

  /* Enable GPIO2 Clock */
  SCU_APBPeriphClockConfig(__GPIO4, ENABLE);


  /* Enable GPIO5 Clock */
  SCU_APBPeriphClockConfig(__GPIO5, ENABLE);

}

/*******************************************************************************
* Function Name  : GPIO_Configuration
* Description    : Configures the different GPIO ports.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /*Configure UART0_CTS P2.0*/
  //GPIO_DeInit(GPIO2);
  /*After DeInit function P2.0 = UART0_CTS (defaut configuration)*/

  GPIO_DeInit(GPIO5);
  /*Gonfigure UART0_Rx pin GPIO5.2*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1  ;
  GPIO_Init (GPIO5, &GPIO_InitStructure);

//  GPIO_DeInit(GPIO3);
  /*Gonfigure UART0_Tx pin GPIO5.1*/
  GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3  ;
  GPIO_Init (GPIO5, &GPIO_InitStructure);
  
  
GPIO_DeInit(GPIO4);
  /*Gonfigure UART0_RTS pin GPIO4.5*/
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
//GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
  GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1  ;
  GPIO_Init (GPIO4, &GPIO_InitStructure);
}


/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/

sebrina2010|  楼主 | 2018-11-21 11:16 | 显示全部楼层
是否时钟的问题?为何中断都进不去。串口查询方式可以

使用特权

评论回复
paotangsan| | 2018-11-21 13:43 | 显示全部楼层
初始化能通过的话应该不是时钟的问题呀

使用特权

评论回复
renzheshengui| | 2018-11-21 15:29 | 显示全部楼层
用的什么时钟?

使用特权

评论回复
wakayi| | 2018-11-21 15:34 | 显示全部楼层
开总中断了没有呀

使用特权

评论回复
sebrina2010|  楼主 | 2018-11-23 08:47 | 显示全部楼层
问题解决了。换了个版本的启动文件,中断就OK 了。谢谢各位。

使用特权

评论回复
sebrina2010|  楼主 | 2018-11-23 08:48 | 显示全部楼层
wakayi 发表于 2018-11-21 15:34
开总中断了没有呀

开了。不是程序的问题

使用特权

评论回复
sebrina2010|  楼主 | 2018-11-23 08:48 | 显示全部楼层

用的OSC

使用特权

评论回复
renzheshengui| | 2018-12-3 14:01 | 显示全部楼层

那晶振起振了吗

使用特权

评论回复
sebrina2010|  楼主 | 2018-12-5 10:01 | 显示全部楼层
谢谢各位。已经解决,因为启动文件有点问题。换了就好了

使用特权

评论回复
sebrina2010|  楼主 | 2018-12-5 10:01 | 显示全部楼层

起了。谢谢您

使用特权

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

本版积分规则

2

主题

10

帖子

0

粉丝