Difference in pin defines?

Post here first, or if you can't find a relevant section!
Post Reply
User avatar
Mangy_Dog
Posts: 124
Joined: Sat May 02, 2020 11:45 pm
Answers: 1

Difference in pin defines?

Post by Mangy_Dog »

Hi I've ran into a strange issue.
When wanting to read an analogue value from PB0 or PB1. I've had to use the defines PB0/1 but PB_0 and PB_1 will always return 0...

While PA_4 and PA_5 will return analogue values.

I'm trying to understand why that's the case, and if that could be a bug?

I had thought P## and P_## were meant to be interchangeable?
This is on the F030RCT6.

Thanks.
Just a dogs body developer, mostly making props and stuff...
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Difference in pin defines?

Post by fpiSTM »

Mangy_Dog wrote: Wed Dec 18, 2024 1:40 pm Hi I've ran into a strange issue.
When wanting to read an analogue value from PB0 or PB1. I've had to use the defines PB0/1 but PB_0 and PB_1 will always return 0...

While PA_4 and PA_5 will return analogue values.

I'm trying to understand why that's the case, and if that could be a bug?

I had thought P## and P_## were meant to be interchangeable?
This is on the F030RCT6.

Thanks.
Totally wrong.

PY_n is a PinName which is a concatenation of "GPIO_port << 4 | GPIO_PIN".
Ex:

Code: Select all

  // Pin name definition
  PA_0  = (PortA << 4) + 0x00,
PYn is a pin number like Dx or x.

In some case they can be equal, ex for a generic variant, PA0 is the pin number 0 so it matches. But if PA0 is not 0 on other variant it is not the same.

Always use pin number (PYn) with the standard Arduino API, the it is used to find the PinName (PY_n).
You can use the PinName for some extra API, simply check the prototype.
Post Reply

Return to “General discussion”