I have used below program for ESP8266 as ISP to upload a program to an ATmega16.
ISP program uploaded in ESP8266
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266AVRISP.h>
const uint8_t reset_pin = 5;
const uint16_t port = 328;
ESP8266AVRISP avrprog(port, reset_pin);
void setup() {
Serial.begin(9600);//115200
Serial.println("");
Serial.println("Arduino AVR-ISP over TCP");
avrprog.setReset(false); // let the AVR run
// listen for avrdudes
avrprog.begin();
}
void loop() {
static AVRISPState_t last_state = AVRISP_STATE_IDLE;
AVRISPState_t new_state = avrprog.update();
if (last_state != new_state) {
switch (new_state) {
case AVRISP_STATE_IDLE: {
Serial.printf("[AVRISP] now idle\r\n");
Serial.println("idle...");
// Use the SPI bus for other purposes
break;
}
case AVRISP_STATE_PENDING: {
Serial.printf("[AVRISP] connection pending\r\n");
Serial.println("pending...");
// Clean up your other purposes and prepare for programming mode
break;
}
case AVRISP_STATE_ACTIVE: {
Serial.printf("[AVRISP] programming mode\r\n");
Serial.println("Active...");
// Stand by for completion
break;
}
}
last_state = new_state;
}else{
Serial.println("newstate not equal to old");
}
// Serve the client
if (last_state != AVRISP_STATE_IDLE) {
avrprog.serve();
Serial.println("serve..");
}
}
Then I have changed the board to ATmega16 and used programmer as AVR ISP
and fetched/written below simple blink program to upload in ATmega16.
void setup() {
// initialize digital pin 13 as an output.
pinMode(1, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
Serial.println("light on");
digitalWrite(1, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Serial.println("light off...");
}
Tried uploading blink program to ATmega16 using ESP8266 as ISP by Sketch =>Upload Using Programmer. This resulted to compilation followed by uploading status in Arduino IDE for longer period. I didn't get any response after 10 mins of time. Then i have tried opening Serial Monitor which shows newstate not equal to old
.
I am not sure what went wrong in my coding? How can I debug this issue ?