Go Down

Topic: A clear and simple flow (Read 23708 times) previous topic - next topic

tksm372

Hi famo,

I found pin mappings are defined in the following file:
"C:\Users\(your_id)\AppData\Local\Arduino15\packages\arduino\hardware\samd_beta\1.6.25\variants\mkrvidor4000\variant.cpp"


like this.
Quote
+------------+------------------+--------+-----------------+--------+-----------------------+---------+---------+--------+--------+----------+----------+
| Pin number |  MKR  Board pin  |  PIN   | Notes           | Peri.A |     Peripheral B      | Perip.C | Perip.D | Peri.E | Peri.F | Periph.G | Periph.H |
|            |                  |        |                 |   EIC  | ADC |  AC | PTC | DAC | SERCOMx | SERCOMx |  TCCx  |  TCCx  |    COM   | AC/GLCK  |
|            |                  |        |                 |(EXTINT)|(AIN)|(AIN)|     |     | (x/PAD) | (x/PAD) | (x/WO) | (x/WO) |          |          |
+------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
|            | FPGA             |        |                 |        |     |     |     |     |         |         |        |        |          |          |
| 26         |                  |  PA12  | FPGA TDI        |   12   |     |     |     |     |  *2/00  |   4/00  | TCC2/0 | TCC0/6 |          | AC/CMP0  |
| 27         |                  |  PA13  | FPGA TCK        |   13   |     |     |     |     |  *2/01  |   4/01  | TCC2/1 | TCC0/7 |          | AC/CMP1  |
| 28         |                  |  PA14  | FPGA TMS        |   14   |     |     |     |     |   2/02  |   4/02  |  TC3/0 | TCC0/4 |          | GCLK_IO0 |
| 29         |                  |  PA15  | FPGA TDO        |   15   |     |     |     |     |  *2/03  |   4/03  |  TC3/1 | TCC0/5 |          | GCLK_IO1 |
| 30         |                  |  PA27  | FPGA CLK        |   15   |     |     |     |     |         |         |        |        |          | GCLK_IO0 |
+------------+------------------+--------+-----------------+--------+-----+-----+-----+-----+---------+---------+--------+--------+----------+----------+
Minatsu Tukisima

famo

Thanks a lot Minatsu!

Are the A0 ... D0 ...  defines  (-->   #define <mySignal> A0) at higher level, as
Arduino shield connector standard?

philippe_at_sysemb

Thanks to famo's question, I finally looked further in arduino's libraries code and discovered how it works.

The JTAG's pin definition in jtag.h file are the real pin assigments for the processor.
So TDI = 12, TDO = 15, TCK = 13 and TMS = 13.

These defines are used by low level functions (ex : port_pin_set_output_level).

For compatibility problems between arduino cards, the high level functions (pinmode, digitalWrite,...) do not use real processor pin number but an index in the structure g_APinDescription[] (in variant.cpp file).

So the TDO pin (as an example) is at index 29 in the structure with the port number (ulPort = PORTA) and real pin number (ulPin = 15).

To use high level functions, correct #define are :
TDI = 26, TDO = 29,TCK = 27
 and TMS = 28.





famo

Ok, this is what you have discovered looking into the some file.
Very likely it is not necessary for an Arduino user/programmer to search for
the variant file to know what number he have to put in the pins #define.

Well, were is the manual for that?

here   https://www.arduino.cc/en/Tutorial/DigitalPins
"Digital pin 13 is harder to use as a digital input than the other digital pins because it has an LED and resistor attached ...", this should be valid for any Arduino?

here again "... digital pin 13 ...", chip pin number or what port number?
https://www.arduino.cc/reference/en/language/functions/digital-io/pinmode/


here is mnemonic https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
analogRead(pin)
"pin: the name of the analog input pin to read from (A0 to A5 on most boards,
A0 to A6 on MKR boards, A0 to A7 on the Mini and Nano, A0 to A15 on the Mega)"

What seems clear is that ALL Arduino boards have the signal names on the shield
connectors, A0 ... An for the possible analog inputs (but good for digital i/o use too),
0 ... m  for the digital i/o, and so on.
These names must be used in pinMode, digitalRead, digitalWrite, ... functions.



philippe_at_sysemb

#49
Feb 13, 2019, 08:53 pm Last Edit: Feb 13, 2019, 09:32 pm by philippe_at_sysemb
I have just corrected all sketches available on my website https://systemes-embarques.fr/wp/ with right #include and #define.
Sorry if it has been a source of confusion for some of you.

Regards
Philippe

Update : I add also a column with values to use for high level functions in the MKR connector description https://systemes-embarques.fr/wp/brochage-connecteur-mkr-vidor-4000/

Go Up