cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO driving outside logic

pritz1
Associate II
Posted on June 08, 2011 at 02:31

Hello,

I am a student and I am starting my final project a little early, and I am glad I did because I am really confused!  I am making a guitar-playing robot that I am going to drive off of this handy-dandy microcontroller.  Basicly I am going to put a file similar to a guitar tab in the FLASH memory and have my main C code interpret it and set output pins connected to some extra logic that will eventually drive some solenoids and stepper motors that will play the guitar.

I am having trouble setting the output pin voltage.  Here is what I have:

<code>

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_WriteBit(GPIOC, GPIO_Pin_12, Bit_SET);

</code>

I want to be able to set any given output pin to either a high or low voltage to drive external logic.  I was under the impression that this code should set the output pin C12 to a high voltage, but when i use a voltmeter to compare it to ground it reads 0 volts.  What am I doing wrong?

Any other thoughts?  Is reading a file going to be more complicated than standard C file IO?

I am using Atollic TrueSTUDIO STM32 Lite as my dev environment.

Thank you much,

Jack

#gpio #gpio-mode
6 REPLIES 6
pritz1
Associate II
Posted on June 08, 2011 at 02:35

I have attached all of my main.c to this reply for your convenience.  I took some sample code that makes the an LED blink at different speeds and added my own code to the beginning of the main function to try it out.

Andrew Neil
Evangelist
Posted on June 08, 2011 at 09:31

''I took some sample code that makes the an LED blink''

Clearly, that must involve setting a pin to high and low levels - so you could start by taking exactly  that code - unmodified - removing the LED, and measuring with the voltmeter.

This will confirm that your measurement technique is correct.

It will also give you a working example of how to set a pin high & low.

''Is reading a file going to be more complicated than standard C file IO?''

Standard 'C' file IO requires that you have a standard file system to read from - do you have that?

Where did you intend to store this file on your hardware?

How did you intend to get the file onto your hardware?

Posted on June 08, 2011 at 20:02

I have attached all of my main.c to this reply for your convenience.

You'll need to enable the clock to the GPIO C bank, prior to initializing it

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,  ENABLE);

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

clive1 - thanks.  That seems to work perfectly now.  Just to be clear are you sure that I am using the correct GPIO_Mode?  I think GPIO_Mode_Out_PP is correct but I would feel better if someone specifically said so.

Andrew - There are actually some LED specific functions that were used in the code so it didn't seem easy to do this way.  As for the file system...i don't know...I have never done this before - I am just building a project in Atollic and flashing it to the board (whatever F11 does in Atollic)...I guess I could get around the problem by having a header file with an array that describes the song but that seems hack-ish to me and I would rather have a file.  How would you suggest I solve this problem?

pritz1
Associate II
Posted on June 08, 2011 at 23:29

I tried just making a file in the ''User'' folder of my project but that didn't really work.  Attached you will find the file with my file I/O attempt at the beginning of the main function.

Posted on June 09, 2011 at 06:38

 I think GPIO_Mode_Out_PP is correct but I would feel better if someone specifically said so.

You're using a Push-Pull pin driver, this will drive the pin High or Low as you define the output. The voltages and currents won't be sufficient to drive motors, solenoids, and actuators directly.

File IO isn't going to work unless you provide code to make it work, this is embedded. If you need an OS or File System, you'll need to add that to your project.

Atollic Lite?! printf() and scanf() don't even work. Hours of joy there.

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