GPIO ACCESS
Answer
11/18/15 1:25 PM
Hallo,
We should synchronize Data Logging start with camera recording.
We have the idea to set the Extension Board GPIO Connector Pin A12 ( == MCU Pin PA1) on logging start.
By inspecting code of the DEMO applications, I found no real hint how to set the GPIO.
Can You explain perhaps with a code example; Ho to set and reset this GPOI ?
Thanks for Your help.
Kind Regards
Manfred

 
0 (0 Votes)
GPIO ACCESS
Answer
11/19/15 3:48 AM as a reply to Manfred Holzapfel.
Hey,

one possiblity is to abuse the button.h library for this:

#include "button.h"

static GPIO_handleInfo_t custom_button_HandleInfo =
{
        .magicWord = GPIO_HANDLE_MAGIC_WORD,
        .port = gpioPortA,
        .bitIndex = 1,
        .Direction = GPIO_DIRECTION_INPUT,
        .lockDirection = false,
        .initDone = false,
};

static BUTTON_handle_tp ButtonHandle = (BUTTON_handle_tp) 0; /**< variable to store button 1 handle */

void initButton(void)
{
    Button1Handle = BUTTON_create((GPIO_handle_tp)&custom_button_HandleInfo, GPIO_STATE_OFF);
    BUTTON_enable(ButtonHandle);
    BUTTON_setCallback(ButtonHandle, callback_func, 0);
}

It is also possible to work with the GPIO_init() and PTD_intConfig() functions directly but the way with the button library works fine and convenient for me.

Kind regards,

Kai Liebich
0 (0 Votes)
GPIO ACCESS
Answer
11/19/15 4:14 AM as a reply to Kai Clemens Liebich.
If you don't need the interrupt function I would stick to:

static GPIO_handleInfo_t custom_button_HandleInfo =
{
        .magicWord = GPIO_HANDLE_MAGIC_WORD,
        .port = gpioPortA,
        .bitIndex = 1,
        .Direction = GPIO_DIRECTION_INPUT,
        .lockDirection = false,
        .initDone = false,
};

void initButton(void)
{
    GPIO_init((GPIO_handle_tp)&custom_button_HandleInfo, GPIO_DIRECTION_INPUT, GPIO_STATE_OFF);
    //Optional disable pull-up/-down resistors
    //GPIO_PinModeSet(custom_button_HandleInfo->port, custom_button_HandleInfo->bitIndex, gpioModeInput, 1);
   
    //Read pin status
    if(GPIO_getPin((GPIO_handle_tp)&custom_button_HandleInfo) == GPIO_STATE_ON)
    {
        printf("PA1 high");
    }
    else
    {
        printf("PA1 low");
    }
0 (0 Votes)
GPIO ACCESS
Answer
11/19/15 10:44 AM as a reply to Kai Clemens Liebich.
Hello Kai,
thanks for Your help,

Yor example showes, how to read the PA1 PIN.
What we want, is Write the PA1 PIN.
I think, this can be done with the following code:

In addition: Is ther any to do with switching PULL-Down resisters ?

static GPIO_handleInfo_t custom_button_HandleInfo =
{
        .magicWord = GPIO_HANDLE_MAGIC_WORD,
        .port = gpioPortA,
        .bitIndex = 1,
        .Direction = GPIO_DIRECTION_OUTPUT,       // changed
        .lockDirection = false,
        .initDone = false,
};

void writeButton(GPIO_pinStates_t value)
{
    GPIO_init((GPIO_handle_tp)&custom_button_HandleInfo, GPIO_DIRECTION_INPUT, GPIO_STATE_OFF);
   
    //Write the PIN pin
    GPIO_setPIN((GPIO_handle_tp)&custom_button_HandleInfo, value);

}

 
0 (0 Votes)
GPIO ACCESS
Answer
11/20/15 7:52 AM as a reply to Manfred Holzapfel.
Oh, sorry that I mixed this up. Writing to the PIN can be done like you wrote it, as long as you conifgure the pin in the GPIO_init as GPIO_DIRECTION_OUTPUT not GPIO_DIRECTION_INPUT ;)

To prevent extra work at this point I would suggest to write the GPIO_init like this:

GPIO_init((GPIO_handle_tp)&custom_button_HandleInfo, custom_button_HandleInfo.Direction, GPIO_STATE_OFF);

The default state for an input pin after calling the GPIO_init() is "gpioModeInputPullFilter" with pull-up-resistors. To change them to be pull-down resistors you need to call the GPIO_setPIN function. The value of the output defines in which direction the resistors are pulling the input pin.

Pull-Up:
GPIO_setPIN((GPIO_handle_tp)&custom_button_HandleInfo, 1);

Pull-Down:
GPIO_setPIN((GPIO_handle_tp)&custom_button_HandleInfo, 0);
 
0 (0 Votes)
GPIO ACCESS
Answer
11/20/15 9:55 AM as a reply to Kai Clemens Liebich.
These posts are great, thanks for posting them and sharing them with the community.

I will try the posted code myself and post them as a FAQ/Tutorial later on so other people can take advantage of that as well!

Thanks,
Florian
0 (0 Votes)
RE: GPIO ACCESS
Answer
8/31/16 7:02 AM as a reply to Kai Clemens Liebich.

Hi Clemens,

your code is not working with workbench 1.6.0. Do you have an updated version of code for this workbench version.

0 (0 Votes)