cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 adc multi channel

vaibhavsharma63
Associate II
Posted on June 08, 2013 at 12:15

The original post was too long to process during our migration. Please click on the attachment to read the original post.
22 REPLIES 22
vaibhavsharma63
Associate II
Posted on June 13, 2013 at 12:41

hello ..this programe is working.now i wana get this data simultaneously on serial monitor..which command should i follow?

frankmeyer9
Associate II
Posted on June 13, 2013 at 13:40

Just add some code to initialise  the UART and associated pins, and the send functionality.

You will find plenty of examples around in the web, google is your friend (well, except if you insist on privacy ...).

Coocox should maintain a collection of examples, and the StdPeripheralLibrary, as part of the F4 discovery firmware, is available from the ST website. The latter contains examples for all peripherals, including UART:

vaibhavsharma63
Associate II
Posted on June 13, 2013 at 14:14

this is my code for usart .and i am  facing again one error which i found last time ..please suggest me how to remove it .....code is here

#include <stm32f4xx_usart.h>

#include ''stm32f4xx_adc.h''

#include ''stm32f4xx_gpio.h''

#include ''stm32f4xx_rcc.h''

#include ''stm32f4xx.h''

void init_usart(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_50MHz;

 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* Connect USART2 pins to AF2 */

 // TX = PA2

 GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

 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 Delay(__IO uint32_t nCount)

{

  while(nCount--)

  {

  }

}

int main(void){

 init_usart();

 uart_puts(''Init complete!'');

 while(1){

  USART_SendData(USART2, 'v'); // defined in stm32f4xx_usart.h

  Delay(0x3FFFFF);

 }

}

.ERROR IS HERE

GCC HOME: C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q1\bin

compile:

    [mkdir] Created dir: C:\CooCox\CoIDE\workspace\usart\usart\Debug\bin

    [mkdir] Created dir: C:\CooCox\CoIDE\workspace\usart\usart\Debug\obj

       [cc] 18 total files to be compiled.

       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wall -ffunction-sections -g -O0 -flto -fno-builtin -c -DSTM32F407VG -DSTM32F4XX -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -IC:\CooCox\CoIDE\workspace\usart\cmsis_lib -IC:\CooCox\CoIDE\workspace\usart\cmsis_boot -IC:\CooCox\CoIDE\workspace -IC:\CooCox\CoIDE\workspace\usart\cmsis_lib\include -IC:\CooCox\CoIDE\workspace\usart -IC:\CooCox\CoIDE\workspace\usart\cmsis -IC:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_syscfg.c C:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery\stm32f4_discovery_audio_codec.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_usart.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_dac.c C:\CooCox\CoIDE\workspace\usart\cmsis_boot\startup\startup_stm32f4xx.c C:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery\stm32f4_discovery.c C:\CooCox\CoIDE\workspace\usart\main.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_rcc.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_adc.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_gpio.c C:\CooCox\CoIDE\workspace\usart\cmsis_boot\system_stm32f4xx.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_dma.c C:\CooCox\CoIDE\workspace\usart\stm32f4_discovery_callbacks.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_spi.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_i2c.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\stm32f4xx_exti.c C:\CooCox\CoIDE\workspace\usart\cmsis_lib\source\misc.c C:\CooCox\CoIDE\workspace\usart\STM32F4-Discovery\stm32f4_discovery_lis302dl.c

       [cc] C:\CooCox\CoIDE\workspace\usart\main.c: In function 'main':

       [cc] C:\CooCox\CoIDE\workspace\usart\main.c:59:2: warning: implicit declaration of function 'uart_puts' [-Wimplicit-function-declaration]

       [cc] Starting link

       [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -g -nostartfiles -flto -Wl,-Map=usart.map -O0 -Wl,--gc-sections -Wl,--entry=main -LC:\CooCox\CoIDE\configuration\ProgramData\usart -Wl,-TC:\CooCox\CoIDE\configuration\ProgramData\usart/arm-gcc-link.ld -g -o usart.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 -L..\..\..\STM32F4-Discovery -lpdmfilter_gcc

       [cc] C:\Users\AKG\AppData\Local\Temp\ccT4as9i.ltrans0.ltrans.o: In function `main':

       [cc] C:\CooCox\CoIDE\workspace\usart/main.c:59: undefined reference to `uart_puts'

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

vaibhavsharma63
Associate II
Posted on June 13, 2013 at 14:23

vaibhavsharma63
Associate II
Posted on June 13, 2013 at 14:25

vaibhavsharma63
Associate II
Posted on June 13, 2013 at 14:30

hello .now i am interfacing pressure sensor (mpx415a) on stm32 discovery board .do u have any sample code in which we can see pressure sensor's data ,

frankmeyer9
Associate II
Posted on June 13, 2013 at 14:52

  [cc] C:\CooCox\CoIDE\workspace\usart/main.c:59: undefined reference to `uart_puts'

 

You call a function that nowhere exists in the project space.

Either your toolchain/library supports routing printf()-like functions to UART, or you write it yourself. This forum contains several threads on how to do this with Keil. Not sure what your (undisclosed / gcc-based) toolchain provides.

Writing it yourself can offer significant code space savings.

frankmeyer9
Associate II
Posted on June 13, 2013 at 15:03

If you mean a MPX4105A/4115A, this devices have an analog output, and require a +5V supply.

You will need a buffer amplifier to interface the sensor output with the ADC, to reduce the impedance and to convert the 0..5V sensor output span to 0..3.3V of the ADC.

Posted on June 13, 2013 at 15:19

void uart_puts(char *s)
{
while(*s)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, *s++);
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
raptorhal2
Lead
Posted on June 13, 2013 at 15:20

Minor correction - the F4 Discovery ADC range is 0 to 3V.

This is a simple exercize for the student.

Cheers, Hal