/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Newbie needing help with GPIO

Username:     
Password:     
             

Forum

# 1   2010-05-26 05:23:32 Newbie needing help with GPIO

unclesam88
New member
Registered: 2010-05-02
Posts: 6

Newbie needing help with GPIO

Hi,

Im working on a school project using the Primer2 and right now time is not on my side as my project deadline approaches so any help will be much appreciated.

I am very new to the Stm32 and am having trouble initializing the GPIO. Basically I need the primer2 to take a digital output from the A/D converter of another device and use it for calculations.

I have seen quite a few examples that use the GPIO's but I just cant make much sense of them. I would like to know how to properly intialize the GPIO for a digital input on one pin and a trigger on another pin aswell as how do I tell the stm32 to read the digital input pin when the trigger goes low.

thanks,
~Sam~

Offline

 

# 2   2010-05-26 07:21:53 Newbie needing help with GPIO

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: Newbie needing help with GPIO

First of all i assume you do have a datasheet and reference manual. I you don't have those get it from Resources page.

1) For any pirephiral you need to enable clocking. All GPIOs are allready clocked by CircleOS for use with MEMS sensor, display & other. If you don't use CircleOS you will need to do that manualy (code for different libraries):
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //Using ST-LIB
    RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; //Using CMSIS

2) Configure GPIO as analog pin.
    //ST-LIB
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; //Ext. connector 11,12
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    //CMSIS
    GPIOC->CRL &=~( GPIO_CRL_MODE4 | GPIO_CRL_CNF4 );
    GPIOC->CRL &=~( GPIO_CRL_MODE5 | GPIO_CRL_CNF5 );

3) Enable ADC clock:
    RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC2, ENABLE ); //ST-LIB
    RCC->APB2EN |= RCC_APB2ENR_ADC2EN; //CMSIS

4) Then you need to configure ADC2.

Can't help you any further because i'm using CMSIS library and it's not suitable for novices. It's probably not the best idea to use CMSIS for your code.

Offline

 

# 3   2010-05-26 08:09:01 Newbie needing help with GPIO

diabolo38
Member
Registered: 2010-03-12
Posts: 50

Re: Newbie needing help with GPIO

i guess   you want to configure one  IO as  "analog" input to convert it with adc ? so it's not already a "digital" input ,
I also suppose you will used ADCCX1 or ADCCX2 from the extention connector for this analog input ?

If the hint above are not enough take a look at existing project with adc (alcohol meter for instance http://www.stm32circle.com/projects/project.php?id=86) it use both ADC and GPIO output on the extension connector.  It should help

Last edited by diabolo38 (2010-05-26 08:20:23)

Offline

 

# 4   2010-05-26 22:53:39 Newbie needing help with GPIO

tiosam88
New member
Registered: 2010-05-04
Posts: 2

Re: Newbie needing help with GPIO

thanks ntrf.zns and diabolo38 for both of your replies. Im sorry for the confusion but the A/D conversion will take place on another device. What I need to do is get the digital value from that conversion and input it into the primer2. So it is a digital signal. Also, how would I actually use the input? in other words how would I save it to a variable for use in calculations. Oh and I will be using CircleOS.

I have gone through the alcohol meter projects amongst others, but the problem is I am just too new to the STM32 that its still difficult for me to understand what does what right away. I would really like to start with something more basic but that's not an option for me right now.

again any and all help is appreciated

~Sam




ps: I just realized I posted with a different username. I had issues with one account and had to create another. Then they both started working and I logged into the wrong one

Last edited by tiosam88 (2010-05-26 22:56:18)

Offline

 

# 5   2010-05-27 16:27:15 Newbie needing help with GPIO

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: Newbie needing help with GPIO

External ADC? So what interface it supports for digital output? I2C, SPI (Microwire), CAN, USART or somthing else? Even if you have a free choice, it's up to you to decide.

Offline

 

# 6   2010-05-28 01:01:08 Newbie needing help with GPIO

tiosam88
New member
Registered: 2010-05-04
Posts: 2

Re: Newbie needing help with GPIO

The ADC really doesnt matter. I just mentioned it for background information. Im just trying to properly initialize the GPIO to read a digital input.

I started a new project with CircleOS, and I entered the following within the Application_Ini section.

GPIO_InitTypeDef  GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);

When I try to debug it I get the following errors
error: 'GPIO_InitTypeDef' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: expected ';' before 'GPIO_InitStructure'
error: 'GPIO_InitStructure' undeclared (first use in this function)
error: 'GPIO_Pin4' undeclared (first use in this function)
error: 'GPIO_Pin5' undeclared (first use in this function)
error: 'GPIO_Mode_IN_FLOATING' undeclared (first use in this function)
error: 'GPIOC' undeclared (first use in this function)

The code I wrote is the only thing in the application file besides what normally appears when a new project is created for CircleOS. So what am I missing?

also Is the following line the way to read information from Pin_5?
GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5)

thanks for you help
~Sam

Offline

 

# 7   2010-05-28 14:52:54 Newbie needing help with GPIO

diabolo38
Member
Registered: 2010-03-12
Posts: 50

Re: Newbie needing help with GPIO

#include "stm32f10x_lib.h"

Offline

 

# 8   2010-05-28 16:07:52 Newbie needing help with GPIO

unclesam88
New member
Registered: 2010-05-02
Posts: 6

Re: Newbie needing help with GPIO

Now Im getting library conflicts error. I got the "STM32F10x_StdPeriph_Lib_V3.3.0" and included the files into the project folder. Do I also need to replace the library files in the Ride7 lib folder? I currently have use Old Precompiled set to no

Offline

 

# 9   2010-05-29 10:37:02 Newbie needing help with GPIO

diabolo38
Member
Registered: 2010-03-12
Posts: 50

Re: Newbie needing help with GPIO

i'll advice to delete any 3.3 files you added  to your project it think they are useless up to me. I have same ride+rkit version as yours and it is all  fine no lib conflict  and am using gpio and over lib peripheral successfully so i guess your problem, is in "circle_api.h"  if you did not fix it you'r getting tons of errors  like these
" //////circle_api.h:42: error: redefinition of typedef 's32' 

if so open local project circle_api.h and  change this
#ifndef __STM32F10x_H
to
#ifndef __STM32F10x_TYPE_H

also have #include "stm32f10x_lib.h"  first in your application.c
#include "stm32f10x_lib.h
#include "circle_api.h"

and it should be ok .  I guess if you did not updated to latest ride the primer cd  version would have been ok straight away.

Ther's  big messs of include , ride\lib\arm\stm32f10x.h do have the  #define __STM32F10x_H + typedef  but the one include is  ride\lib\arm\include\stm32f10x. and it do not have any __STM32F10x_H nor older lib type definitions why those errors .

Offline

 

# 10   2010-05-29 16:31:42 Newbie needing help with GPIO

unclesam88
New member
Registered: 2010-05-02
Posts: 6

Re: Newbie needing help with GPIO

diabolo38 you genious!!! It worked. I really appreciate your help and taking the time to help me fix this tedious problem.

ntrf.zns, also thank you for showing me the format for setting the GPIO pins.


~Sam

Offline

 

# 11   2012-08-07 11:29:28 Newbie needing help with GPIO

naturalna
New member
Registered: 2012-08-07
Posts: 1

Re: Newbie needing help with GPIO

Thanks smile

Offline

 

Board footer