Hi,
Thanks for your reply.
I know that in the datasheet they mentionned the 8bits LSB & 8bits MSB but it didn't work for me. This is why I've followed this link Electronics The King of Hobbies!: My own AVR ISP programmer using PIC16f877a and python!. His article contain a code that test for even/odd addresses and the written code is for Atmega8, 16, 32. Also, if you can see in the USBASP source code especially in isp.c file you will find a test like:
ispTransmit(0x40|((address&1)<<3));
This is the code that I've created following the atmel datasheet to program Atmega using arduino, I can get such as (Signature, sync code, program, lock bits, fuses) but no writing:
#define ENABLE_PROGRAMMING 0xAC530000L
#define CHIP_ERASE 0xAC800000L
#define READ_BYTE_LSB 0x20000000L
#define READ_BYTE_MSB 0x28000000L
#define WRITE_BYTE 0x4C000000L
#define LOAD_BYTE_MSB 0x48000041L
#define LOAD_BYTE_LSB 0x40000041L
#define SIGNATURE0 0x30000000L
#define SIGNATURE1 0x30000100L
#define SIGNATURE2 0x30000200L
#define READ_LOCK_BITS 0x58000000L
#define WRITE_LOCK_BITS 0xACE00000L
#define LOCKB_NOPROTECT 0x000000FFL
#define LOCKB_NOPROGRAM 0x000000FEL
#define LOCKB_ALLPROTECT 0x000000FCL
int RST_P = 9;
int MOSI_P = 10;
int MISO_P = 11;
int CLK_P = 12;
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(MOSI_P, OUTPUT);
pinMode(MISO_P, INPUT);
pinMode(RST_P, OUTPUT);
pinMode(CLK_P, OUTPUT);
digitalWrite(RST_P, HIGH);
digitalWrite(MOSI_P, HIGH);
digitalWrite(CLK_P, LOW);
}
void sendCmd(long cmd, boolean output)
{
boolean counter_bool = false;
int counter = 0;
for (int i=31; i>=0; i--)
{
if (cmd&bit(i))
{
digitalWrite(MOSI_P, HIGH);
}
else
{
digitalWrite(MOSI_P, LOW);
}
digitalWrite(CLK_P, HIGH);
delay(1);
if (output/*&&counter_bool*/)
Serial.print(digitalRead(MISO_P));
digitalWrite(CLK_P, LOW);
}
Serial.println("");
}
void programmingEnable(boolean x)
{
int c = 0;
if (x)
{
digitalWrite(MOSI_P, LOW);
digitalWrite(CLK_P, LOW);
digitalWrite(RST_P, LOW);
//A LED indicator
for (int i=0; i<4; i++) {
delay(40);
digitalWrite(8, c=(~c));
}
//digitalWrite(CLK_P, HIGH);
}
else
{
digitalWrite(RST_P, HIGH);
digitalWrite(MOSI_P, HIGH);
digitalWrite(CLK_P, HIGH);
}
delay(1);
}
void programChip(char *program)
{
long address = 0x00000000;
int counter = 0;
int len = strlen(program);
while (counter != len)
{
for (;;)
counter ++;
}
}
void loop()
{
programmingEnable(true);
sendCmd(ENABLE_PROGRAMMING, false);
sendCmd(LOAD_BYTE_LSB, false);
sendCmd(LOAD_BYTE_MSB, false);
sendCmd(WRITE_BYTE, false);
sendCmd(READ_BYTE_LSB, true);
while(1);
}
What do you think guys ?