Go Down

Topic: Bare microcontroller pin outs....  (Read 568 times) previous topic - next topic

jimmyhorns

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

DrAzzy

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.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

jimmyhorns

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.

pert

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
but that pretty much just points to the "standard" variant:
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)

DrAzzy

#4
Feb 18, 2020, 03:49 am Last Edit: Feb 18, 2020, 03:50 am by DrAzzy
If you looked at the pinout charts as suggested, you'd find something like this:



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
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

jimmyhorns

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
but that pretty much just points to the "standard" variant:
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 :)

jimmyhorns

If you looked at the pinout charts as suggested, you'd find something like this:



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

Go Up