Jump to content

Controlling a pin in MIOS32


jmayes
 Share

Recommended Posts

Hi, I am trying to convert my app from mios8 to mios32. In mios8 I used "PORTCbits.RC0 = 1" to turn a pin on, I can't seem to find an equivalent in mios32. I would like to use the J19 pins if possible. Also is there anything I will need to do to turn off any preexisting drivers or to configure the pins?

Thankx for any help someone can provide,

Jmayes

Link to comment
Share on other sites

Not sure about J19, but there is a tutorial that shows how to do that for J5.

Thank you ilmenator, I am looking at that now. Seems some pins have mios32 def's and some don't, I was hoping there was generic C defs could be used to toggle any pin like with the pic. Can someone put some more light on this?

Thankx again all,

Jmayes

Link to comment
Share on other sites

There are generic IO configuration routines which are part of the low-level driver provided by STM.

It's already part of the repository, used by MIOS32 and available for all applications as well.

Here the source code if you are interested: http://svnmios.midibox.org/listing.php?repname=svn.mios32&path=%2Ftrunk%2Fdrivers%2FSTM32F10x%2Fv3.3.0%2FSTM32F10x_StdPeriph_Driver%2F

(but again: the sources are already compiled into the application, no special treatments required to integrate them)

Example to configure J19:RC1 (pin PC13) as push-pull output (0/3.3V):


GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // weak driver to reduce transients
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
[/code] Example to configure J19:RC1 (pin PC13) as open drain output (0/5V if pull-up resistor is used):
[code]
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // weak driver to reduce transients
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
Example to configure J19:RC1 (pin PC13) as input with internal pull-up to 3.3V enabled:

GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // doesn't really matter for inputs
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
[/code] Example to configure J19:RC1 (pin PC13) as floating input (w/o pull device):
[code]
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // doesn't really matter for inputs
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
MIOS32 configures J19 pins for software based SPI, but as long as you don't use MIOS32_SPI_...(2...) (SPI port 2), the pins can be used for other purposes w/o danger. Toggling pins:

GPIOC->BSRR = GPIO_Pin_13;
[/code] will set the pin to 1, and:
[code]
GPIOC->BRR = GPIO_Pin_13;

will set the pin to 0

Best Regards, Thorsten.

Link to comment
Share on other sites

There are generic IO configuration routines which are part of the low-level driver provided by STM.

..........

Best Regards, Thorsten.

Great! That was exactly what I needed.

Thankx again for a quick answer,

Jmayes

Edited by jmayes
Link to comment
Share on other sites

  • 3 weeks later...

Hey TK,

While I got this working (with your help), I still don't understand exactly why all the config statements are needed (or how they work). Could you give a statement by statement explanation of how this works?

I know it would help me greatly and I am sure other nubies too.

Thankx again for all your help!

Jmayes

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...