/** ****************************************************************************** * @file Audio_playback_and_record/src/main.c * @author MCD Application Team * @version V1.0.0 * @date 28-October-2011 * @brief Main program body ****************************************************************************** * @attention * * THE PRESENT FIRMWARE 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 FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * *

© COPYRIGHT 2011 STMicroelectronics

*/ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "spi_3201.h" #include /* Exported macro ------------------------------------------------------------*/ /* Select 3201: Chip Select pin low */ //#define 3201_CS_LOW() GPIO_ResetBits(GPIOB, GPIO_Pin_12) /* Deselect 3201: Chip Select pin high */ //#define 3201_CS_HIGH() GPIO_SetBits(GPIOB, GPIO_Pin_12) /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define ADC3_DR_ADDRESS ((uint32_t)0x4001224C) /* Private variables ---------------------------------------------------------*/ static __IO uint32_t TimingDelay; extern uint8_t NbrOfDataToTransfer; extern uint8_t NbrOfDataToRead; extern __IO uint8_t TxCounter; extern __IO uint16_t RxCounter; extern uint8_t RxBuffer[]; char *command; char *command_AT1 = "AT+CGATT?\r\n"; //char *command_AT2 = "AT+UPSD=0,1,"AIRTELGPRS.COM"\r\n"; //char command[]="vv, "as" "; unsigned char *Buffer; unsigned char ab[64]; unsigned char bc[64]; unsigned char cd[64]; unsigned char de[64]; unsigned char ef[64]; unsigned char gh[64]; unsigned char hi[64]; unsigned char ij[64]; unsigned char jk[64]; unsigned int i; unsigned char d; __IO uint16_t ADC3ConvertedValue = 0; __IO uint32_t ADC3ConvertedVoltage = 0; RCC_ClocksTypeDef RCC_Clocks; __IO uint8_t RepeatState = 0; __IO uint8_t RepeatState1 = 0; __IO uint8_t RepeatState2 = 0; __IO uint8_t RepeatState3 = 0; __IO uint8_t RepeatState4 = 0; __IO uint8_t RepeatState5 = 0; __IO uint8_t RepeatState6 = 0; __IO uint8_t RepeatState7 = 0; __IO uint8_t RepeatState8 = 0; __IO uint8_t RepeatState9 = 0; __IO uint8_t RepeatState10 = 0; __IO uint16_t CCR_Val = 16826; extern __IO uint8_t LED_Toggle; /* Private function prototypes -----------------------------------------------*/ static void TIM_LED_Config(void); void RCC_Configuration(void); void NVIC_Config(void); void GPIO_Configuration(void); void ADC3_CH12_DMA_Config(void); void itoa(int,char *,int); /* Private functions ---------------------------------------------------------*/ void RCC_Configuration(void) { /* --------------------------- System Clocks Configuration -----------------*/ /* GPIOC clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* USART4 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); /* GPIOC clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* USART5 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE); } void NVIC_Config(void) { NVIC_InitTypeDef NVIC_InitStructure; /* Enable the USARTx Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);/* UART4_TX */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);/* UART4_RX */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);/* UART4_TX */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);/* UART4_RX */ /*-------------------------- GPIO Configuration ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /*-------------------------- GPIO Configuration ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); } void USART4_Configuration(void) { USART_InitTypeDef USART_InitStructure; // USART_ClockInitTypeDef USART_ClockInitStruct; /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; //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_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART4,&USART_InitStructure); //uart USART_Cmd(UART4, ENABLE); } void USART5_Configuration(void) { USART_InitTypeDef USART_InitStructure; // USART_ClockInitTypeDef USART_ClockInitStruct; /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; //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_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART5,&USART_InitStructure); //uart USART_Cmd(UART5, ENABLE); } void relay_config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* GPIOD Periph clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Configure PD11 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); } void SendChar(char ch) { /* Wait till holding buffer empty */ while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); USART_SendData(UART4, (unsigned int) ch); } void SendInt(uint16_t num) { while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); USART_SendData(UART4, (uint16_t) num); } void SendInt2(char num) { while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); USART_SendData(UART4, (unsigned int) num); } void SendString(char *s) { while(*s) { while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); USART_SendData(UART4, (unsigned int) *s++); } } void SendStringadc(uint32_t *s) { while(*s) { while(USART_GetFlagStatus(UART4, USART_FLAG_TXE) == RESET); USART_SendData(UART4, (unsigned int) *s++); } } void SendChar5(unsigned char ch) { /* Wait till holding buffer empty */ while(USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET); USART_SendData(UART5, (unsigned int) ch); } void SendString5(unsigned char *s) { while(*s) { while(USART_GetFlagStatus(UART5, USART_FLAG_TXE) == RESET); USART_SendData(UART5, (unsigned int) *s++); } } unsigned int RecvChar(void) { unsigned int aa; /* Wait till holding buffer empty */ while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); aa = (unsigned int) (USART_ReceiveData(UART4) & 0x7F); return aa; } void RecvString(unsigned char *buffer) { unsigned char data; do { while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); // Wait for data to be received data = (unsigned char) (USART_ReceiveData(UART4) & 0x7F); *buffer = data; buffer++; // Increment the string pointer } while(data!='K'); *buffer='\0'; } void RecvStringg(void) { unsigned char data; int i=0; do { while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); // Wait for data to be received data = (unsigned char) (USART_ReceiveData(UART4) & 0x7F); ab[i] = data; i++; // Increment the string pointer } while(data!='K'); } /** * @brief Delay Function. * @param nCount:specifies the Delay time length. * @retval None */ void Delay(__IO uint32_t nCount) { while(nCount--) { } } void Response(void) { i=0; do { while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); d = (USART_ReceiveData(UART4) & 0x7F); ab[i]=d; i++; }while(d!='K'); } void Response1(void) { i=0; do { while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); d = (USART_ReceiveData(UART4) & 0x7F); bc[i]=d; i++; }while(d!='K'); } void Response2(void) { i=0; do { while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); d = (USART_ReceiveData(UART4) & 0x7F); cd[i]=d; i++; }while(d!='K'); } void ResponseSt(void) { i=0; do { while(USART_GetFlagStatus(UART4, USART_FLAG_RXNE) == RESET); d = (USART_ReceiveData(UART4) & 0x7F); ab[i]=d; i++; }while(ab[1]!='K'); } void Gprs(void) { SendString("AT+UPSDA=0,4\r\n"); //GPRS DEACTIVATE Response(); SendString5(ab); SendString("AT+UPSD=0,1,\"AIRTELGPRS.COM\"\r\n"); Response(); SendString5(ab); SendString("AT+UPSD=0,7,\"0.0.0.0\"\r\n"); Response(); SendString5(ab);; SendString("AT+UPSDA=0,3\r\n"); //GPRS ACTIVATE Response(); SendString5(ab); } void Http(void) { SendString("AT+UHTTP=0\r\n"); //RESET Response(); SendString5(ab); SendString("AT+UHTTP=0,2,\"marudham\"\r\n"); //USERNAME Response(); SendString5(ab); SendString("AT+UHTTP=0,3,\"marudham\"\r\n"); //PASSWORD Response(); SendString5(ab); SendString("AT+UHTTP=0,1,\"www.marudham.co.in\"\r\n"); //gate way Response(); SendString5(ab); //SendString("AT+UHTTPC=0,1,\"/datacapture.php?imeiid=357464034993805&latitude=13.0218N&longitude=80.2056E&date=23062012&time=092652.000&speed=0.61\",\"get.ffs\"\r\n"); //Response(); } /** * @brief Main program. * @param None * @retval None void AdcConfig(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); // ADC1 configuration ------------------------------------------------------ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); } */ void SpiConfig(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); /*!< Enable GPIO clocks */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /*!< SPI pins configuration *************************************************/ /*!< Connect SPI pins to AF5 */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2 ); GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2 ); GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2 ); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; /*!< SPI SCK pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< SPI MOSI pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< SPI MISO pin configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< Configure sFLASH Card CS pin in output pushpull mode ********************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); /*!< Deselect the FLASH: Chip Select high */ c3201_CS_HIGH(); /*!< SPI configuration */ 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_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI2, &SPI_InitStructure); /*!< Enable the sFLASH_SPI */ SPI_Cmd(SPI2, ENABLE); } /* char *itoa(int n, char *s, int b) { static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; int i=0, sign; if ((sign = n) < 0) n = -n; do { s[i++] = digits[n % b]; } while ((n /= b) > 0); if (sign < 0) s[i++] = '-'; s[i] = '\0'; return strrev(s); } */ char * utoa(unsigned int n) { char * res, buf[30]; // long enough for largest number unsigned int i, counter = 0; if (n == 0) buf[counter++] = '0'; for ( ; n; n /= 10) buf[counter++] = "0123456789"[n%10]; res = malloc(counter); for (i = 0; i < counter; ++i) res[i] = buf[counter - i - 1]; return res; } int main(void) { char read; char value; int num = 123; char buf[5]; //SystemCoreClockUpdate(); /* Initialize LEDS */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /* Green Led On: start of application */ STM_EVAL_LEDOn(LED4); /* SysTick end of count event each 10ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* Configure TIM4 Peripheral to manage LEDs lighting */ //TIM_LED_Config(); //relay_config(); NVIC_Config(); //*** RCC_Configuration(); //*** GPIO_Configuration(); //**** USART4_Configuration(); //*** USART5_Configuration(); /* Enable the uart receive interrupt: this interrupt is generated when the transmit data register is empty */ //USART_ITConfig(UART4, USART_IT_RXNE, ENABLE); //*** //AdcConfig(); SpiConfig(); /* ADC3 configuration *******************************************************/ /* - Enable peripheral clocks */ /* - DMA2_Stream0 channel2 configuration */ /* - Configure ADC Channel12 pin as analog input */ /* - Configure ADC3 Channel12 */ //ADC3_CH12_DMA_Config(); /* Start ADC3 Software Conversion */ //ADC_SoftwareStartConv(ADC3); value=4; while (1) { STM_EVAL_LEDOn(LED6); //Gprs(); //Http(); //ADC3ConvertedVoltage = ADC3ConvertedValue *3300/0xFFF; SendChar('a'); c3201_CS_LOW(); SendChar('b'); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); read=SPI_I2S_ReceiveData(SPI2); SendChar('d'); c3201_CS_HIGH(); SendChar('e'); SendChar(read); STM_EVAL_LEDOn(LED5); //atoi ("456"); //atol (Convert string to long integer) //atof (Convert string to double) //strtol (Convert string to long integer) //SendInt2(value); //SendChar('a'); /* SendChar('a'); ADC3ConvertedVoltage = ADC3ConvertedValue *3300/0xFFF; command=utoa(ADC3ConvertedVoltage); SendString(command); SendChar('b'); */ } } /** * @brief ADC3 channel12 with DMA configuration * @param None * @retval None */ void ADC3_CH12_DMA_Config(void) { ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable ADC3, DMA2 and GPIO clocks ****************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); /* DMA2 Stream0 channel0 configuration **************************************/ DMA_InitStructure.DMA_Channel = DMA_Channel_2; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC3ConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = 1; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); DMA_Cmd(DMA2_Stream0, ENABLE); /* Configure ADC3 Channel12 pin as analog input ******************************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure); /* ADC Common Init **********************************************************/ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC3 Init ****************************************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC3, &ADC_InitStructure); /* ADC3 regular channel12 configuration *************************************/ ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 1, ADC_SampleTime_3Cycles); /* Enable DMA request after last transfer (Single-ADC mode) */ ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE); /* Enable ADC3 DMA */ ADC_DMACmd(ADC3, ENABLE); /* Enable ADC3 */ ADC_Cmd(ADC3, ENABLE); } /** * @brief Configures the TIM Peripheral for Led toggling. * @param None * @retval None */ static void TIM_LED_Config(void) { TIM_OCInitTypeDef TIM_OCInitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; uint16_t prescalervalue = 0; /* TIM4 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); /* Enable the TIM3 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Initialize Leds mounted on STM324F4-EVAL board */ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED6); /* Compute the prescaler value */ prescalervalue = (uint16_t) ((SystemCoreClock ) / 550000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = prescalervalue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); /* Enable TIM4 Preload register on ARR */ TIM_ARRPreloadConfig(TIM4, ENABLE); /* TIM PWM1 Mode configuration: Channel */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; /* Output Compare PWM1 Mode configuration: Channel2 */ TIM_OC1Init(TIM4, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable); /* TIM Interrupts enable */ TIM_ITConfig(TIM4, TIM_IT_CC1 , ENABLE); /* TIM4 enable counter */ TIM_Cmd(TIM4, ENABLE); } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while (1) { } } #endif /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/