cancel
Showing results for 
Search instead for 
Did you mean: 

u

vaibhavsharma63
Associate II
Posted on June 18, 2013 at 20:51

The original post was too long to process during our migration. Please click on the attachment to read the original post.
8 REPLIES 8
Posted on June 18, 2013 at 20:59

The thread is poorly titled.

The uart_puts() routine is broken by a cut-n-paste failure, it's suppose to use a character pointer.

You don't actually initialize the USART.

And you assume that printf() magically routes to an arbitrary USART. You could sprintf() to a buffer and use uart_puts() to be tool chain agnostic.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vaibhavsharma63
Associate II
Posted on June 18, 2013 at 21:50

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6n9&d=%2Fa%2F0X0000000bvY%2FPBXSGzTARoH7gNWWah3FCjwUkH6iQHOCE1zxMFpX1KI&asPdf=false
raptorhal2
Lead
Posted on June 19, 2013 at 03:07

Now that you have gotten this far - here is a simple debugging technique. You have an input from a device to be sent to a usart for verification. Use a watch window on the ADCConvertedValues buffer in debug mode to verify that the accelerometer inputs have been properly received before being sent to the usart.

The Discovery kit has a gotcha - some of the pins are dedicated to board functions. PCO/ADC123_IN10 pin is pulled up to 3V for the user USB function. The pins for ADC channels 1, 2, 3, 11, 12, 14 & 15 plus the 8 & 9 you are currently using are freely available. There is a table in the F4 Discovery User Manual that identifies board pin functions.

Cheers, Hal

Posted on June 19, 2013 at 15:16

This should be workable. Please pay attention to ADC channels/pins usable (PB2 is not).

// STM32F4-Discovery ADC3 - sourcer32@gmail.com 
#include ''stm32f4xx.h'' 
#include <
stdio.h
> // sprintf 
//****************************************************************************** 
void USART2_Configuration(void) 
{ 
GPIO_InitTypeDef GPIO_InitStructure; 
USART_InitTypeDef USART_InitStructure; 
/* enable peripheral clock for USART2 */ 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); 
/* GPIOA clock enable */ 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 
/* GPIOA Configuration: USART2 TX on PA2 */ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOA, &GPIO_InitStructure); 
/* Connect USART2 pin to AF2 */ 
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); // PA2 (USART2_TX) 
USART_InitStructure.USART_BaudRate = 9600; 
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_Tx; 
USART_Init(USART2, &USART_InitStructure); 
USART_Cmd(USART2, ENABLE); // enable USART2 
} 
//****************************************************************************** 
void USART2_SendString(char *s) 
{ 
while(*s) 
{ 
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); 
USART_SendData(USART2, *s++); 
} 
} 
//****************************************************************************** 
volatile uint16_t ADCConvertedValues[3]; 
//****************************************************************************** 
void GPIO_Configuration(void) 
{ 
GPIO_InitTypeDef GPIO_InitStructure; 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE); 
/* Configure ADC1 Channel8 pin as analog input PB0 *****************************/ 
/* Configure ADC1 Channel9 pin as analog input PB1 *****************************/ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; 
GPIO_Init(GPIOB, &GPIO_InitStructure); 
/* Configure ADC1 Channel12 pin as analog input PC2 *****************************/ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; 
GPIO_Init(GPIOC, &GPIO_InitStructure); 
} 
//****************************************************************************** 
void ADC1_Configuration(void) 
{ 
ADC_InitTypeDef ADC_InitStructure; 
ADC_CommonInitTypeDef ADC_CommonInitStructure; 
DMA_InitTypeDef DMA_InitStructure; 
/* Enable peripheral clocks *************************************************/ 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); 
/* DMA2_Stream0 channel0 configuration **************************************/ 
DMA_DeInit(DMA2_Stream0); 
DMA_InitStructure.DMA_Channel = DMA_Channel_0; 
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR; 
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCConvertedValues[0]; 
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; 
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_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); 
/* DMA2_Stream0 enable */ 
DMA_Cmd(DMA2_Stream0, ENABLE); 
/* 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); 
/* ADC1 Init ****************************************************************/ 
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; 
ADC_InitStructure.ADC_ScanConvMode = ENABLE; // Multiple Channels 
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; // Keep Sampling 
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; 
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; 
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 
ADC_InitStructure.ADC_NbrOfConversion = 3; 
ADC_Init(ADC1, &ADC_InitStructure); 
/* ADC1 regular channel configuration ******************************/ 
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_480Cycles); // PB0 
ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 2, ADC_SampleTime_480Cycles); // PB1 
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_480Cycles); // PC2 (BANKC) 
/* Enable DMA request after last transfer (Single-ADC mode) */ 
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); 
/* Enable ADC1 DMA */ 
ADC_DMACmd(ADC1, ENABLE); 
/* Enable ADC1 **************************************************************/ 
ADC_Cmd(ADC1, ENABLE); 
/* Start ADC1 Software Conversion */ 
ADC_SoftwareStartConv(ADC1); 
} 
//****************************************************************************** 
int main(void) 
{ 
USART2_Configuration(); 
GPIO_Configuration(); 
ADC1_Configuration(); 
while(1) /* Infinite loop */ 
{ 
if (ADCConvertedValues[2] != 0xFFFF) // Check for new values loaded 
{ 
char string[32]; 
sprintf(string, ''%03X %03X %03
X'', ADCConvertedValues[0], ADCConvertedValues[1], ADCConvertedValues[2]); 
USART2_SendString(string); 
ADCConvertedValues[2] = 0xFFFF; // Invalidate 
} 
} 
} 
/**************************************************************************/ 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vaibhavsharma63
Associate II
Posted on June 19, 2013 at 23:07

hello when i dump this program in stm32discovery board ..i get this error please fix it ..and please suggest me which tool chain should i use...and the error is here:-

compile:

    [mkdir] Skipping C:\CooCox\CoIDE\workspace\oooooooo\oooooooo\Debug\bin because it already exists.

    [mkdir] Skipping C:\CooCox\CoIDE\workspace\oooooooo\oooooooo\Debug\obj because it already exists.

       [cc] Starting dependency analysis for 19 files.

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_syscfg.c

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_syscfg.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_rcc.h

       [cc] Parsing ..\..\..\cmsis_boot\stm32f4xx.h

       [cc] Parsing ..\..\..\cmsis\core_cm4.h

       [cc] Parsing ..\..\..\cmsis_boot\system_stm32f4xx.h

       [cc] Parsing ..\..\..\cmsis_boot\stm32f4xx_conf.h

       [cc] Parsing ..\..\..\cmsis\core_cmInstr.h

       [cc] Parsing ..\..\..\cmsis\core_cmFunc.h

       [cc] Parsing ..\..\..\cmsis\core_cm4_simd.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_dac.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_dma.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_exti.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_gpio.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_i2c.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_spi.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_tim.h

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_usart.h

       [cc] Parsing ..\..\..\cmsis_lib\include\misc.h

       [cc] Parsing ..\..\..\STM32F4-Discovery\stm32f4_discovery_audio_codec.c

       [cc] Parsing ..\..\..\STM32F4-Discovery\stm32f4_discovery_audio_codec.h

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_usart.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_dac.c

       [cc] Parsing ..\..\..\cmsis_boot\startup\startup_stm32f4xx.c

       [cc] Parsing ..\..\..\STM32F4-Discovery\stm32f4_discovery.c

       [cc] Parsing ..\..\..\STM32F4-Discovery\stm32f4_discovery.h

       [cc] Parsing ..\..\..\main.c

       [cc] Parsing ..\..\..\cmsis_lib\include\stm32f4xx_adc.h

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_rcc.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_adc.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_gpio.c

       [cc] Parsing ..\..\..\cmsis_boot\system_stm32f4xx.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_dma.c

       [cc] Parsing ..\..\..\stm32f4_discovery_callbacks.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_spi.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_i2c.c

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_exti.c

       [cc] Parsing ..\..\..\cmsis_lib\source\misc.c

       [cc] Parsing ..\..\..\STM32F4-Discovery\stm32f4_discovery_lis302dl.c

       [cc] Parsing ..\..\..\STM32F4-Discovery\stm32f4_discovery_lis302dl.h

       [cc] Parsing ..\..\..\cmsis_lib\source\stm32f4xx_tim.c

       [cc] 19 files are up to date.

       [cc] 0 files to be recompiled from dependency analysis.

       [cc] 0 total files to be compiled.

       [cc] Starting link

       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -g -nostartfiles -flto -Wl,-Map=oooooooo.map -O0 -Wl,--gc-sections -Wl,--entry=main -LC:\CooCox\CoIDE\configuration\ProgramData\oooooooo -Wl,-TC:\CooCox\CoIDE\configuration\ProgramData\oooooooo/arm-gcc-link.ld -g -o oooooooo.elf ..\obj\stm32f4xx_syscfg.o ..\obj\stm32f4_discovery_audio_codec.o ..\obj\stm32f4xx_usart.o ..\obj\stm32f4xx_dac.o ..\obj\startup_stm32f4xx.o ..\obj\stm32f4_discovery.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4xx_gpio.o ..\obj\system_stm32f4xx.o ..\obj\stm32f4xx_dma.o ..\obj\stm32f4_discovery_callbacks.o ..\obj\stm32f4xx_spi.o ..\obj\stm32f4xx_i2c.o ..\obj\stm32f4xx_exti.o ..\obj\misc.o ..\obj\stm32f4_discovery_lis302dl.o ..\obj\stm32f4xx_tim.o -L..\..\..\STM32F4-Discovery -lpdmfilter_gcc

       [cc] C:\Users\AKG\AppData\Local\Temp\cc6POStm.s: Assembler messages:

       [cc] C:\Users\AKG\AppData\Local\Temp\cc6POStm.s:961: Error: offset out of range

       [cc] C:\Users\AKG\AppData\Local\Temp\cc6POStm.s:962: Error: offset out of range

       [cc] lto-wrapper: C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q1\bin\arm-none-eabi-gcc returned 1 exit status

       [cc] c:/program files (x86)/gnu tools arm embedded/4.7 2013q1/bin/../lib/gcc/arm-none-eabi/4.7.3/../../../../arm-none-eabi/bin/ld.exe: lto-wrapper failed

       [cc] collect2.exe: error: ld returned 1 exit status

       [cc] 200

Posted on June 19, 2013 at 23:16

hello when i dump this program in stm32discovery board ..i get this error please fix it ..and please suggest me which tool chain should i use...and the error is here:-

NMP, I'm using Keil with a project structure and settings which comport with those of the template projects.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vaibhavsharma63
Associate II
Posted on June 20, 2013 at 12:18

i am using coocox ..in coocox i am getting a error ..which i have shown you in last post .please fix it

Posted on June 20, 2013 at 13:47

i am using coocox ..in coocox i am getting a error ..which i have shown you in last post .please fix it

 

Sorry, but this really isn't my problem, I'm not here to provide support for the clowns at CooCox, and their broken tool. Seek support from CooCox.

This isn't even a problem unique to my code, you had the same problem here [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/stm32%20adc%20multi%20channel&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx&currentviews=147#%7b314E8D1E-6C89-4834-8847-88E5E4FCD317%7d]sharma.vaibhav : stm32 adc multi channel

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..