#include "stm32f10x.h" #include "stdio.h" uint16_t ADCConvertedValue[3]; uint8_t Tx_Buffer[520]; uint32_t Rx_length=0; uint32_t Rx_xiaobiao=0; uint32_t Rx_have_done = 0; uint8_t RxBuffer[64]; typedef enum { GPIO_PIN_One, GPIO_PIN_Two, GPIO_PIN_Three, GPIO_PIN_Four, GPIO_PIN_Five, GPIO_PIN_Six, GPIO_PIN_Seven }GPIO; uint16_t PIN[16]={GPIO_Pin_0,GPIO_Pin_1,GPIO_Pin_2,GPIO_Pin_3,GPIO_Pin_4,GPIO_Pin_5,GPIO_Pin_6,GPIO_Pin_7,GPIO_Pin_8,GPIO_Pin_9,GPIO_Pin_10,GPIO_Pin_11,GPIO_Pin_12,GPIO_Pin_13,GPIO_Pin_14,GPIO_Pin_15}; GPIO_TypeDef* GPIOX[7]={GPIOA,GPIOB,GPIOC,GPIOD,GPIOE,GPIOF,GPIOG}; void Delay(unsigned int nCount) { while(nCount--); } void STM32LED(GPIO gpio,unsigned char pin) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = PIN[pin]; GPIO_Init(GPIOX[gpio],&GPIO_InitStructure); GPIOD->BSRR = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_7; } void STM32_USART_Init(void)//meiwenti { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO,ENABLE); GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD,&GPIO_InitStructure); USART_Init(USART2,&USART_InitStructure); USART_Cmd(USART2,ENABLE); printf("\n\r ############ WWW.ARMJISHU.COM! ############ \n"); } #ifndef MicroLIB #pragma import(__use_no_semihosting) struct __FILE { int handle; }; FILE __stdout; _sys_exit(int x) { x= x; } int fputc(int ch,FILE *f) { while(USART_GetFlagStatus(USART2,USART_FLAG_TC) == RESET) {} USART_SendData(USART2,(uint8_t) ch); return ch; } int ferror(FILE *f) { return EOF; } #endif FILE __stdin; int fgetc(FILE *fp) { int ch = 0; while(USART_GetFlagStatus(USART2,USART_FLAG_RXNE) == RESET) {} ch = (int)USART2->DR & 0XFF; putchar(ch); return ch; } #ifdef USE_FULL_ASSERT void assert_failed(uint8_t* file,uint32_t line { printf("Wrong parameters Value:file %s on line %d\r\n",file,line); while(1) { } }11 #endif void UsartIrqHandlerUser(void) { if(USART_GetITStatus(USART2,USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USART2,USART_IT_RXNE); RxBuffer[Rx_length] = USART2->DR; Rx_length++; if(USART2->DR == '\r' || Rx_length >= 64) { Rx_have_done = 1; } } // else if(USART_GetITStatus(USART2,USART_IT_TC) != RESET) // { // USART_ClearITPendingBit(USART2,USART_IT_TC); // } } void NVIC_GroupConfig(void) { //GPIOD->BRR= GPIO_Pin_4; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); } void NVIC_COMConfiguration(void) { NVIC_InitTypeDef NVIC_InitStructure; //->BRR= GPIO_Pin_3; USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } uint32_t UsartReadData(uint8_t* Buffer) { uint32_t uartDataLength = 0,i; if(Rx_length != 0) { uartDataLength = Rx_length ; Rx_length = 0; Rx_have_done = 0; for(i=0;i<uartDataLength;i++) { Buffer = RxBuffer; } Buffer = '\0'; } return uartDataLength ; } void USART2_IRQHandler(void) { //__disable_irq(); //GPIOD->BRR= GPIO_Pin_2; UsartIrqHandlerUser(); //GPIOD->BRR= GPIO_Pin_2; //__enable_irq(); } void ADC_GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//|GPIO_Pin_1|GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC,&GPIO_InitStructure); } void STM32_ADC_Configuration(void) { ADC_InitTypeDef ADC_InitStructure; DMA_InitTypeDef DMA_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE); GPIOD->BRR = GPIO_Pin_7; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADCConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 3; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1,&DMA_InitStructure); DMA_Cmd(DMA1_Channel1,ENABLE); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 3; ADC_Init(ADC1,&ADC_InitStructure); RCC_ADCCLKConfig(RCC_PCLK2_Div8);// ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1,ADC_Channel_11,2,ADC_SampleTime_55Cycles5); ADC_RegularChannelConfig(ADC1,ADC_Channel_12,3,ADC_SampleTime_55Cycles5); ADC_DMACmd(ADC1,ENABLE); ADC_Cmd(ADC1,ENABLE); ADC_ResetCalibration(ADC1); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); ADC_SoftwareStartConvCmd(ADC1,ENABLE); } void DMA1_Channel1_IRQHandler(void) { if(DMA_GetITStatus(DMA1_IT_TC1) == 1) { DMA_ClearITPendingBit(DMA1_IT_TC1); } while(1) { GPIOD->BRR = GPIO_Pin_2; } } int main(void) { unsigned int i; float AD_ANALOG[3]; uint8_t ucStr[65]; for(i=0;i<520;i++) { Tx_Buffer = 'w'; } STM32LED(GPIO_PIN_Four,2); STM32LED(GPIO_PIN_Four,3); STM32LED(GPIO_PIN_Four,4); STM32LED(GPIO_PIN_Four,7); STM32_USART_Init(); NVIC_GroupConfig(); NVIC_COMConfiguration(); ADC_GPIO_Configuration(); STM32_ADC_Configuration(); while(1) { Delay(10000000); for(i=0;i<3;i++) AD_ANALOG =(float) ADCConvertedValue*(3.3/4095); Delay(10000000); printf("\r\n DATA = %f V \r\n",AD_ANALOG[0]); printf("\r\n ANALOG = %f V \r\n",AD_ANALOG[1]); printf("\r\n ANALOG = %f V \r\n",AD_ANALOG[2]); } } 我配置了IT_TC标志;也写了DMA中断,为什么就是进不去中断.求指教 |
检查下中断服务程序名字跟startup.S里的是否一致;
恩恩,谢谢了,(昨晚已经解决了,嘿嘿)
评分
查看全部评分
怎么的解决的啊 我也遇到了啊