Arduino ISP Programming

For general Flowcode discussion that does not belong in the other sections.
Post Reply
mnfisher
Valued Contributor
Posts: 953
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Arduino ISP Programming

Post by mnfisher »

I've been following a long running saga on the old matrix format - trying to get an atmega8 MCU running as an SPI slave.

I managed to find an Mega8 - and fancied a play along - but first hurdle is programming it from Flowcode.

I wanted to use an Arduino (in this case a Nano) programmed as an ISP.

So - I have a 16MHz crystal connected across pin 9 and 10 (with caps) 5v and gnd to 7 and 8 respectively.

Then I connected 10 (on the nano - CS) to 1
11 (MOSI) to 17
12 (MISO) to 18
13 (SCK) to 19

I also connected an LED to pin 4 (PD2) - with a current limiting resistor. To allow a blinky to run.

Using the Arduino IDE - I programmed the Nano as an ISP - and set the mega8 to 16Mhz external crystal, no bootloader.
Connect a 10uF electrolytic between ground and reset (on the nano) and program an empty program from Arduino IDE (this sets the fuses)

Then - I created a new Flowcode program - set target as ATMega 8 - wrote a simple blinky.

Then I needed to create a new programmer batch file - which I struggled with a bit - hence the lack of fuses.

I created ArduinoISP.bat in C:\ProgramData\MatrixTSL\FlowcodeV10\FCD\AVR\batchfiles

Code: Select all

:ProgFlash
@SET AVRDUDEcmd="C:/Program Files (x86)/Flowcode/Common/Compilers/avr/bin/avrdude.exe" -p atmega8 -P COM6 -b 19200 -c avrisp -U flash:w:%3:i
@SHIFT

%AVRDUDECmd%

:End
@ECHO.
@ECHO Programming successful!
@EXIT 0
Note that the com port is hardcoded as COM6 - you might need to change this - the settings for the ATMega8 doesn't allow a com port to be set.

In compiler-options->programmer I set the batch file as ArduinoISP.bat and the parameters as

Code: Select all

"$(compileravr)" AVRDUDE "$(outdir)$(target).hex" 
Then I could compile and upload ATMega8 programs - blinky working happily (remember to set CPU speed as 16MHz if using an external crystal)

Getting the batch file 'right' took a fair bit of fiddling - hence the hard-coded address for avrdude.exe too :-( - and if I knew what the cfg settings were (probably should have printed them from the batch file....) life might have been a little easier! I had a lot of issues - I had a space at the start of the file name - avrdude was not happy about this!

However - it should also allow the ArduinoISP to be used to program other AVR chips from within Flowcode...

Now - to brush up on those SPI techniques.

Martin

Post Reply