2011-06-07 05:31 PM
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-mode2011-06-07 05:35 PM
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.
2011-06-08 12:31 AM
''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?2011-06-08 11:02 AM
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);2011-06-08 02:28 PM
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?
2011-06-08 02:29 PM
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.
2011-06-08 09:38 PM
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.