sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HV_Pins.h
Go to the documentation of this file.
1 // HV_Pins.h
2 //
3 // Pin numbers and commands for high-voltage serial or parallel programming
4 //
5 // Author: Nick Gammon
6 
7 /* ----------------------------------------------------------------------------
8 NOTE: This file should only be modified in the Atmega_Hex_Uploader directory.
9 Copies in other directories are hard-linked to this one.
10 After modifying it run the shell script:
11  fixup_links.sh
12 This script needs to be run in the directories:
13  Atmega_Board_Programmer and Atmega_Board_Detector
14 That will ensure that those directories now are using the same file.
15 ------------------------------------------------------------------------------ */
16 
17 
18 #if HIGH_VOLTAGE_PARALLEL || HIGH_VOLTAGE_SERIAL
19 
20  // high-voltage programming commands we can send (when action is LOAD_COMMAND)
21  enum {
22  CMD_CHIP_ERASE = 0b10000000,
23  CMD_WRITE_FUSE_BITS = 0b01000000,
24  CMD_WRITE_LOCK_BITS = 0b00100000,
25  CMD_WRITE_FLASH = 0b00010000,
26  CMD_WRITE_EEPROM = 0b00010001,
27  CMD_READ_SIGNATURE = 0b00001000,
28  CMD_READ_FUSE_BITS = 0b00000100,
29  CMD_READ_FLASH = 0b00000010,
30  CMD_READ_EEPROM = 0b00000011,
31  CMD_NO_OPERATION = 0b00000000,
32  }; // end of commands
33 
34 #endif // HIGH_VOLTAGE_PARALLEL || HIGH_VOLTAGE_SERIAL
35 
36 #if HIGH_VOLTAGE_PARALLEL
37  // pin assignments for parallel high-voltage programming
38 
39 // Arduino pins Target pins
40 // ------------ -----------------------
41  const byte dataPins [8] = {
42  6, // 14 (PB0) (data bit 0)
43  7, // 15 (PB1) (data bit 1)
44  8, // 16 (PB2) (data bit 2)
45  9, // 17 (PB3) (data bit 3)
46  10, // 18 (PB4) (data bit 4)
47  11, // 19 (PB5) (data bit 5)
48  12, // 23 (PC0) (data bit 6)
49  13 // 24 (PC1) (data bit 7)
50  }; // end of dataPins
51 
52  enum {
53  RDY = A0, // 3 (PD1) (low means busy)
54  OE = A1, // 4 (PD2) (low means output enabled)
55  WR = A2, // 5 (PD3) (low means write)
56  BS1 = A3, // 6 (PD4)
57  XTAL1 = A4, // 9 (XTAL1)
58  XA0 = A5, // 11 (PD5)
59  XA1 = 2, // 12 (PD6)
60  PAGEL = 3, // 13 (PD7)
61  BS2 = 4, // 25 (PC2)
62  VCC = 5, // 7 and 20 (VCC and AVCC)
63  }; // end of other pins
64 
65 
66  /* Note: /RESET (Pin 1) is brought to 12V by connecting a transistor and MOSFET (high-side driver)
67  via a RC network to (the target) VCC. R = 22k, C = 10 nF. This gives a delay of around 40 uS between
68  VCC and /RESET. The transistor turns on the MOSFET, which switches +12V to /RESET.
69  For transistor/MOSFET schematic see: http://www.gammon.com.au/images/Arduino/MOSFET_high_side_driver.png
70 
71  |-------------------------------------------------------> VCC and AVCC
72  |
73  D5 >---|--/\/\/\/\---|-----------> Transistor ---> MOSFET -----> /RESET
74  22k |
75  === 10 nF
76  |
77  |
78  V
79  Gnd
80 
81  Also connect the grounds. Gnd to pins 8 and 22.
82  Decoupling capacitors: 0.1 uF between VCC/AVCC (pins 7 and 20) and Gnd.
83  Not connected on target: pins 2, 10, 21, 26, 27, 28.
84  */
85 
86  // when XTAL1 is pulsed the settings in XA1 and XA0 control the action
87  enum {
88  ACTION_LOAD_ADDRESS,
89  ACTION_LOAD_DATA,
90  ACTION_LOAD_COMMAND,
91  ACTION_IDLE
92  }; // end of actions
93 
94 
95 #endif // HIGH_VOLTAGE_PARALLEL
96 
97 #if HIGH_VOLTAGE_SERIAL
98 
99 // ATMEL ATTINY 25/45/85 / ARDUINO
100 //
101 // +-\/-+
102 // /RESET 1| |8 VCC
103 // (SCI) PB3 2| |7 PB2 (SDO)
104 // (N/C) PB4 3| |6 PB1 (SII)
105 // GND 4| |5 PB0 (SDI)
106 // +----+
107 
108 
109 // Arduino pins Target pins
110 // ------------ -------------------
111 enum {
112  VCC = 3, // VCC and /RESET (see above for comments) (pin 8)
113  SDI = 4, // Serial Data Input --> PB0 (pin 5)
114  SII = 5, // Serial Instruction Input --> PB1 (pin 6)
115  SDO = 6, // Serial Data Output --> PB2 (pin 7)
116  SCI = 7, // Serial Clock Input (min. 220nS) --> PB3 (pin 2)
117 };
118 
119 enum {
120  SII_LOAD_COMMAND = 0b01001100,
121  SII_LOAD_ADDRESS_LOW = 0b00001100,
122  SII_LOAD_ADDRESS_HIGH = 0b00011100,
123  SII_READ_LOW_BYTE = 0b01101000,
124  SII_READ_HIGH_BYTE = 0b01111000,
125  SII_WRITE_LOW_BYTE = 0b01100100,
126  SII_WRITE_HIGH_BYTE = 0b01110100,
127  SII_LOAD_LOW_BYTE = 0b00101100,
128  SII_LOAD_HIGH_BYTE = 0b00111100,
129  SII_WRITE_EXTENDED_FUSE = 0b01100110,
130  SII_PROGRAM_LOW_BYTE = 0b01101101,
131  SII_PROGRAM_HIGH_BYTE = 0b01111101,
132  SII_READ_EEPROM = 0b01101000,
133 
134  // various actions are latched in by ORing in this value
135  SII_OR_MASK = 0b00001100,
136 
137  }; // end of chip commands
138 
139 #endif // HIGH_VOLTAGE_SERIAL
uint8_t byte
Definition: Arduino.h:123