stuartpittaway / diyBMSv4Code

Software for diyBMS v4
Other
145 stars 65 forks source link

Flash using avrdude / pio + "arduino as ISP" #84

Open corbolais opened 3 years ago

corbolais commented 3 years ago

Hi, Just flashed the ATTiny841 hex using pio and an "Arduino as ISP", here I used an UNO. For future reference in case anyone wants to quickly repeat this process I'm opening this issue. Maybe one could integrate it into the documentation?

Firstly, flash the bootloader (prefererably the "new" variant) to your *duino to be able to use it as ISP programmer. This can be done using the Arduino IDE (didn't get to flash it using pio run -t bootloader): 1) Connect USB cable to the Arduino UNO and nothing else is connected at this point 2) Tools->"Programmer: Arduino as ISP" 3) Tools->"Flash bootloader" command.Sometimes this didn't work here, so an alternative is to select the "arduino ISP" example sketch compile and upload

Secondly, connect the Arduino ISP to your ATTiny board like this:

Arduino ISCP pin/
      header pin -> ATTiny board ICSP (pinout per schematic)
  ----------------------------
    1 MOSI / D11 -> 1 MOSI
    4 MISO / D12 -> 4 MISO
    3 SCK  / D13 -> 3 SCK
    2        VCC -> 2 VCC
    6        GND -> 6 GND
             D10 ->   /RST <== This is crucial
    5        RST -> 5 NC (!)

This may be done using the Arduino ISCP header or directly using the pins as shown in parenthesis. Arduino ICSP pinout. Usually, you also need a 10uF cap across D10 (Arduino RST) and GND. (For programming, in this case, CS (pin 6:PA7 or pin 11:PA2) on the ATTiny is not required to be pulled down.)

Thirdly, flash the firmware either using avrdude directly: avrdude -C ~/./avrdude.conf -p attiny841 -P /dev/ttyUSB0 -b 19200 -c stk500v1 -U flash:w:.pio/build/attiny841_V400/module_firmware_attiny841_V400_400.hex:i Just replace the hex filename with the one you need and the correct ttyUSB? device.

To flash using pio run -e attiny841_V400 -t upload --upload-port /dev/ttyUSB1 -vv one would need to modify platformio.ini:

upload_protocol = avrisp
; efuse = 1111 0100 = Enables SPM instruction
; hfuse = 1101 0110 = EESAVE & 1.8V BOD detection level
; lfuse = 1110 0010 = CKDIV8 & Calibrated Internal 8MHz Oscillator
board_fuses.lfuse = 0b11100010
board_fuses.hfuse = 0b11010110
board_fuses.efuse = 0b11110100
;-B16 option needed for my USBASP programmer to slow it down!
upload_speed = 19200
upload_flags =
    -C
    $PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
    -p
    $BOARD_MCU
    -P
    $UPLOAD_PORT
    -b
    $UPLOAD_SPEED
    -c
    stk500v1
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

Then do: pio run -e attiny841_V400 -t upload --upload-port /dev/ttyUSB0

HTH

stuartpittaway commented 3 years ago

Thank you

LeighAS commented 1 year ago

I may have to try this, i have failed a few times trying with usbasp devices

EDIT my new usbasp device arrived. same problem as before observed. tried -F upload flag, tried -B16 upload flag. all to no avail. Any advices here Stuart. Last thing to try might be the tinyisp like Adam Welch does but honestly think that the slaves may be broken too.

I struggled last night to flash the 4.21 slaves Uploading .pio\build\V421\module_fw_V421_attiny841_421_eF4_hD6_l62.hex

avrdude: error: program enable: target doesn’t answer. 1 avrdude: initialization failed, rc=-1 Double check connections and try again, or use -F to override this check.

I have a usbasp device which is showing as good in device manager and is being recognised in platformio in vscode, I have triple checked the six wires that go from the icsp headers and when i attempt upload it give the message shown above. any advices would be appreciated. thanks. I get one green flash on the 4.21 slave board when the upload is attempted.

I have now put an order on amazon for the usbasp linked in the description of this video. hopefully there is just some difference in my old usbasp device that i cant see, but i am doubtful.

stuartpittaway commented 1 year ago

Are you using the older (small) controller PCB? The newer one includes a TINY841 programmer through the web interface.

LeighAS commented 1 year ago

Yes its the older one about 2 years ago the v4.21 and usbasp programmer through the 6 pins on the slave. Havent tried a tinyisp flasher like adam welch yet but that my last possible thought to get these working.

On Tue, 7 Mar 2023, 12:25 Stuart Pittaway, @.***> wrote:

Are you using the older (small) controller PCB? The newer one includes a TINY841 programmer through the web interface.

— Reply to this email directly, view it on GitHub https://github.com/stuartpittaway/diyBMSv4Code/issues/84#issuecomment-1458082392, or unsubscribe https://github.com/notifications/unsubscribe-auth/AESC3HJPSRXJAEPISXTAXV3W24SMNANCNFSM4WKTVEXQ . You are receiving this because you commented.Message ID: @.***>

LeighAS commented 1 year ago

Here are 3 that i havent soldered the header to flash then yet 16781924817772524563565005864648