| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

ADC_PDM_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : ADC_PDM_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 19-September-2016
7 * Description : Code demostrating the ADC functionality
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
202 /* Includes ------------------------------------------------------------------*/
203 #include "BlueNRG1.h"
204 #include "BlueNRG1_conf.h"
205 #include "SDK_EVAL_Config.h"
206 #include <stdio.h>
207
220 /* Private typedef -----------------------------------------------------------*/
221 /* Private define ------------------------------------------------------------*/
222 #define FS 8000
223
224 #undef UART_BAUDRATE
225 #define UART_BAUDRATE (512000)
226
227 #if (FS == 16000)
228 #define PCM_BUFFER_SIZE 16 * 2
229 #elif (FS == 8000)
230 #define PCM_BUFFER_SIZE 16
231 #endif
232
233 /* Private macro -------------------------------------------------------------*/
234 /* Private variables ---------------------------------------------------------*/
235 ADC_InitType xADC_InitType;
236 int16_t PCM_Buffer[PCM_BUFFER_SIZE]; /* Bytes */
237
238 /* Private function prototypes -----------------------------------------------*/
239 void ADC_Configuration(void);
240 void GPIO_Configuration(void);
241 void DMA_Configuration(void);
242
243 /* Private functions ---------------------------------------------------------*/
244
245
251 int main(void)
252 {
253 /* System initialization function */
254 SystemInit();
255
256 /* Identify BlueNRG1 platform */
257 SdkEvalIdentification();
258
259 /* UART initialization */
260 SdkEvalComUartInit(UART_BAUDRATE);
261
262 /* GPIO Initialization */
263 GPIO_Configuration();
264
265 /* ADC Initialization */
266 ADC_Configuration();
267
268 /* DMA Initialization */
269 DMA_Configuration();
270
271 /* Start new conversion */
272 ADC_Cmd(ENABLE);
273
274 /* Infinite loop */
275 while(1)
276 {
277
278 }
279 }
280
281
287 void GPIO_Configuration(void)
288 {
289 GPIO_InitType GPIO_InitStructure;
290
291 /* Enables the GPIO Clock */
292 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE);
293
294 /* Configure GPIO_Pin_1 and GPIO_Pin_2 as PDM_DATA and PDM_CLOCK */
295 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
296 GPIO_InitStructure.GPIO_Mode = Microphone_Mode;
297 GPIO_InitStructure.GPIO_Pull = DISABLE;
298 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
299 GPIO_Init(&GPIO_InitStructure);
300
301 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
302 GPIO_InitStructure.GPIO_Mode = Microphone_Mode;
303 GPIO_Init(&GPIO_InitStructure);
304
305 }
306
312 void ADC_Configuration(void)
313 {
314 /* Enable ADC clock */
315 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_ADC, ENABLE);
316
317 #if (FS == 16000)
318 xADC_InitType.ADC_DecimationRate = ADC_DecimationRate_100;
319 #elif (FS == 8000)
320 xADC_InitType.ADC_DecimationRate = ADC_DecimationRate_200;
321 #endif
322
323 xADC_InitType.ADC_Input = ADC_Input_Microphone;
324 xADC_InitType.ADC_ConversionMode = ADC_ConversionMode_Continuous;
325 xADC_InitType.ADC_ReferenceVoltage = ADC_ReferenceVoltage_0V6;
326 xADC_InitType.ADC_Attenuation = ADC_Attenuation_0dB;
327 ADC_Init(&xADC_InitType);
328
329 /* Enable ADC round converted data */
330 ADC_RoundConvertedData(ENABLE);
331
332 /* Enable auto offset correction */
333 ADC_Calibration(ENABLE);
334 ADC_AutoOffsetUpdate(ENABLE);
335
336 }
337
343 void DMA_Configuration(void)
344 {
345 DMA_InitType DMA_InitStructure;
346 NVIC_InitType NVIC_InitStructure;
347
348 /* Configure DMA peripheral */
349 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_DMA, ENABLE);
350
351 /* Configure DMA TX channel */
352 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC->DATA_CONV);
353 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)PCM_Buffer;
354 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
355 DMA_InitStructure.DMA_BufferSize = (uint32_t)(PCM_BUFFER_SIZE);
356 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
357 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
358 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
359 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
360 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
361 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
362 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
363
364 DMA_Init(DMA_CH0, &DMA_InitStructure);
365
366 /* Enable DMA_CH_UART_TX Transfer Complete interrupt */
367 DMA_FlagConfig(DMA_CH0, DMA_FLAG_TC | DMA_FLAG_HT, ENABLE);
368
369 /* Select DMA ADC CHANNEL 0 */
370 DMA_SelectAdcChannel(DMA_ADC_CHANNEL0, ENABLE);
371
372 /* Enable ADC DMA requests */
373 DMA_Cmd(DMA_CH0, ENABLE);
374 ADC_DmaCmd(ENABLE);
375
376 /* Enable the USARTx Interrupt */
377 NVIC_InitStructure.NVIC_IRQChannel = DMA_IRQn;
378 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = HIGH_PRIORITY;
379 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
380 NVIC_Init(&NVIC_InitStructure);
381
382 }
383
389 void TC_IT_Callback(void)
390 {
391 uint16_t i = 0;
392
393 for ( i = 0; i< PCM_BUFFER_SIZE; i++)
394 {
395 /* Send the PDM data through UART */
396 UART_SendData( ((uint8_t *)PCM_Buffer)[i + PCM_BUFFER_SIZE]); /* Bytes */
397 while (UART_GetFlagStatus(UART_FLAG_TXFE) == RESET);
398 }
399
400 }
401
407 void HT_IT_Callback(void)
408 {
409 uint16_t i = 0;
410
411 for ( i = 0; i< PCM_BUFFER_SIZE; i++)
412 {
413 /* Send the PDM data through UART */
414 UART_SendData(((uint8_t *)PCM_Buffer)[i]); /* Bytes */
415 while (UART_GetFlagStatus(UART_FLAG_TXFE) == RESET);
416 }
417
418 }
419
420 #ifdef USE_FULL_ASSERT
421
428 void assert_failed(uint8_t* file, uint32_t line)
429 {
430 /* User can add his own implementation to report the file name and line number,
431 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
432
433 /* Infinite loop */
434 while (1)
435 {
436 }
437 }
438
439 #endif
440
441
454 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
GPIO_Configuration
void GPIO_Configuration(void)
GPIO_Configuration.
Definition: ADC_PDM_main.c:287
HT_IT_Callback
void HT_IT_Callback(void)
DMA Half Transfer Callback.
Definition: ADC_PDM_main.c:407
PCM_Buffer
int16_t PCM_Buffer[PCM_BUFFER_SIZE]
Definition: ADC_PDM_main.c:236
PCM_BUFFER_SIZE
#define PCM_BUFFER_SIZE
Definition: ADC_PDM_main.c:230
ADC_Configuration
void ADC_Configuration(void)
ADC_Configuration.
Definition: ADC_PDM_main.c:312
xADC_InitType
ADC_InitType xADC_InitType
Definition: ADC_PDM_main.c:235
DMA_Configuration
void DMA_Configuration(void)
DMA_Configuration.
Definition: ADC_PDM_main.c:343
TC_IT_Callback
void TC_IT_Callback(void)
DMA Transfer Complete Callback.
Definition: ADC_PDM_main.c:389
main
int main(void)
Main program.
Definition: ADC_PDM_main.c:251
UART_BAUDRATE
#define UART_BAUDRATE
Definition: ADC_PDM_main.c:225