Arduino Forum

Using Arduino => Microcontrollers => Topic started by: jimmyhorns on Feb 17, 2020, 10:02 pm

Title: Bare microcontroller pin outs....
Post by: jimmyhorns on Feb 17, 2020, 10:02 pm
Im struggling to find the answer to this - and i'm sure the question must have been asked before, so apologies if I haven't searched using the correct terms.

I'm starting the move to using a bare microcontroller (in this case a 328p) in a project where I am going to build the pcb myself, and program the 328p in circuit.

What I am struggling with is understanding how to 'map' the pins of, say, a nano board to the 328p when writing the code.


Can someone point me to the working out / understanding which pin arduino thinks is pin 1 on the nano and how it is going to address that on the 328p (its a tqfp package).

Im confusing myself even asking the question.

Thanks in advance

James
Title: Re: Bare microcontroller pin outs....
Post by: DrAzzy on Feb 17, 2020, 10:08 pm
If it is a part from an official board, and using the official board definitions, just Google "arduino pinout" and the part number. There are some great diagrams for '328p.

If it is a part not used on an official board, or you are using a third party board package for it (ex, a 328pb with minicore, or an attiny with one of my cores), a pinout diagram will be in the documentation included with the third party board package.
Title: Re: Bare microcontroller pin outs....
Post by: jimmyhorns on Feb 18, 2020, 12:56 am
If it is a part from an official board, and using the official board definitions, just Google "arduino pinout" and the part number. There are some great diagrams for '328p.

If it is a part not used on an official board, or you are using a third party board package for it (ex, a 328pb with minicore, or an attiny with one of my cores), a pinout diagram will be in the documentation included with the third party board package.

Ah - yes my original question didn't really make clear what I am struggling with, which I thought might be the case.

So say for example I write in the arduino IDE

digitalWrite (4, LOW);

This sends digital pin 4 on the nano board low.

However the bare microcontrollers do not have neatly numbered digital I/O pins, they have a series of ports so for example Port B I/O number 3 (PB3).

So what I guess I am asking, is where abouts I find the conversion table for how the arduino IDE 'looks up' what digital pin 4 is for example when writing to the port on the microcontroller.

I hope that makes more sense?... its still a bit muddled I guess.
Title: Re: Bare microcontroller pin outs....
Post by: pert on Feb 18, 2020, 02:25 am
The conversion table is in the variants file. For the classic Arduino Nano, the variant used is "eightanaloginputs":
https://github.com/arduino/ArduinoCore-avr/blob/master/variants/eightanaloginputs/pins_arduino.h (https://github.com/arduino/ArduinoCore-avr/blob/master/variants/eightanaloginputs/pins_arduino.h)
but that pretty much just points to the "standard" variant:
https://github.com/arduino/ArduinoCore-avr/blob/master/variants/standard/pins_arduino.h (https://github.com/arduino/ArduinoCore-avr/blob/master/variants/standard/pins_arduino.h)
There, you will find several PROGMEM arrays. The Arduino pin number is the index of the array. So if you look at digital_pin_to_port_PGM[4]:
Code: [Select]
PD,
you can see that Arduino pin 4 is port D
and if you look at digital_pin_to_bit_mask_PGM[4]:
Code: [Select]
_BV(4),
you can see that Arduino pin 4 is bit 4 of port D (PD4)
Title: Re: Bare microcontroller pin outs....
Post by: DrAzzy on Feb 18, 2020, 03:49 am
If you looked at the pinout charts as suggested, you'd find something like this:

(https://i.pinimg.com/originals/bb/11/f1/bb11f1963aa704b86fb8c9c90a8e75ed.png)

they show the arduino pin number, the port number (eg, PC2), the analog pin number (if applicable), list any special functions, all showing which physical pin that corresponds to
Title: Re: Bare microcontroller pin outs....
Post by: jimmyhorns on Feb 18, 2020, 02:54 pm
The conversion table is in the variants file. For the classic Arduino Nano, the variant used is "eightanaloginputs":
https://github.com/arduino/ArduinoCore-avr/blob/master/variants/eightanaloginputs/pins_arduino.h (https://github.com/arduino/ArduinoCore-avr/blob/master/variants/eightanaloginputs/pins_arduino.h)
but that pretty much just points to the "standard" variant:
https://github.com/arduino/ArduinoCore-avr/blob/master/variants/standard/pins_arduino.h (https://github.com/arduino/ArduinoCore-avr/blob/master/variants/standard/pins_arduino.h)
There, you will find several PROGMEM arrays. The Arduino pin number is the index of the array. So if you look at digital_pin_to_port_PGM[4]:
Code: [Select]
PD,
you can see that Arduino pin 4 is port D
and if you look at digital_pin_to_bit_mask_PGM[4]:
Code: [Select]
_BV(4),
you can see that Arduino pin 4 is bit 4 of port D (PD4)
Thanks thats great - I understand how I can work it out now :)
Title: Re: Bare microcontroller pin outs....
Post by: jimmyhorns on Feb 18, 2020, 02:59 pm
If you looked at the pinout charts as suggested, you'd find something like this:

(https://i.pinimg.com/originals/bb/11/f1/bb11f1963aa704b86fb8c9c90a8e75ed.png)

they show the arduino pin number, the port number (eg, PC2), the analog pin number (if applicable), list any special functions, all showing which physical pin that corresponds to
Thanks - the pinouts I have been using / seen have never included the arduino pin reference as per the one you posted, which is why I have been struggling.

Having done another google search (the same one I think I did the first time - 'atmega 328pu tqfp pinout' a few of them have the arduino pins listed, just by chance I must have only clicked on the ones that didn't or I would not have asked the question!

Thanks for your help