Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

XMC™ Forum Discussions

Not applicable
Why is it that if i use this.....the pin does not work....i.e. not output

XMC_GPIO_SetMode( P2_10, XMC_GPIO_MODE_OUTPUT_PUSH_PULL );


but.... if i use this ...... the pin does work.


pin_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
XMC_GPIO_Init( P2_10, &pin_config );

???

what is the correct procedure to setup pins and does it differ from different pins types ?
0 Likes
2 Replies
chismo
Employee
Employee
First like received
Hello,

Port 2 contains analog pin functionality and by default, the digital pin functionality is disabled.
Therefore, to enable Port 2 pins, the digital pin functionally needs to be especially enabled.

This step is automatically included in the XMC_GPIO_Init() function, which explains why you see the difference.
For the first method, you will need to add for PORT2 the following:

XMC_GPIO_EnableDigitalInput(P2_10);
XMC_GPIO_SetMode( P2_10, XMC_GPIO_MODE_OUTPUT_PUSH_PULL );


For non-analog pins, the two methods would have worked.
In general, I will recommend to use the pin init function.

Regards,
Min Wei
0 Likes
Not applicable
chismo wrote:
Hello,

Port 2 contains analog pin functionality and by default, the digital pin functionality is disabled.
Therefore, to enable Port 2 pins, the digital pin functionally needs to be especially enabled.

This step is automatically included in the XMC_GPIO_Init() function, which explains why you see the difference.
For the first method, you will need to add for PORT2 the following:

XMC_GPIO_EnableDigitalInput(P2_10);
XMC_GPIO_SetMode( P2_10, XMC_GPIO_MODE_OUTPUT_PUSH_PULL );


For non-analog pins, the two methods would have worked.
In general, I will recommend to use the pin init function.

Regards,
Min Wei


This does explain it, but it also shows a issue in the GPIO lib......

You should only have one method to setup a pin, the user should be abstracted away from the issue of if ports have different requirments
0 Likes