AVRFLASH breaks my ATMEGA328P

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
digibum
Posts: 19
Joined: 08 May 2017 07:37

AVRFLASH breaks my ATMEGA328P

#1 Post by digibum » 08 May 2017 08:00

Hi all.

I have a cusom board made by my friend. He is using MicroBasic with ChipBlasterAVR.
Now he can normaly program ATMEGA328P on board with no problems. Then i tried with my new mikroProg to read the chip and it works. So I loaded my LedBlink sample.

Code: Select all

void main() {
  DDRB = 0xFF;
  //DDRB.F2 = 1;           // Set direction 1=out, 0=in
  //DDB2_bit = 1;

  do {
    PORTB = 0x00;
    //PORTB.F2 = 0;        // Turn OFF diodes on PORTB.F2
    //PORTB2_bit = 0;
    Delay_ms(1000);      // 1 second delay

    PORTB = 0xFF;
    //PORTB.F2 = 1;        // Turn ON diodes on PORTB.F2
    //PORTB2_bit = 1;
    Delay_ms(1000);      // 1 second delay
  } while(1);            // Endless loop
}
Im still learning so there is some comments because i dont know witch way is correct. But this code kinda works. The problem is that the led toggles for 8 seconds and not 1 second. So i tried to change my code meany times... Uploaded my code meany times... Led stil toggles for 8 seconds.

In one of my upload proccesses the ATMEGA328P stops responding and AVRFLASH reports "Can not synchronise device with programmer". Now i can't read or write to chip.

Next i took my Arduino Fio with same ATMEGA328P and connected mikroProg with it. Read chip and uploaded same LedBLink code to it. Led toggles for 8 seconds insted of 1 second. Tried to change, reupload my code. After some uploades the chip stops responding, error: "Can not synchronise device with programmer".

What am i dooing wrong? Are my chips dead?

Used settings (from read):
Image

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: AVRFLASH breaks my ATMEGA328P

#2 Post by darko.ilijevski » 08 May 2017 17:04

Hello,

It seems that you have set up the clock of the MCU uncorrectly, so it defaulted to 1MHz somehow.
To be able to recover the MCU, you need to get a programmer your friend has (ChipBlasterAVR) since it has JTAG and switch to a good clock setting.
You will know a good setting if the led blinks as it's supposed to. Also - best would be if you can switch to an external clock so you can work from there, until you find out what is wrong with the clock settings.

I have read some data in the datasheet, and the MCU comes with the /8 divider by default. You have to make sure you are not using that. Also - better to use Factory calibrated RC clock, but all in all - RC clock speed depends on the power supply you use - so if you do not provide the correct voltage, clock might fail.

Currently - your clock clearly works @ 1MHz, which is not enough for the other (SPI) programmer to access it. That's why you have to use JTAG programmer (like ChipBlasterAVR) and correct the clock setting.

Best retards
BR,
Darko

digibum
Posts: 19
Joined: 08 May 2017 07:37

Re: AVRFLASH breaks my ATMEGA328P

#3 Post by digibum » 09 May 2017 06:58

Your answer seams reasonable, but :)
How could I change CPU clock? Device frequency [MHz] was always set to 8.0MHz.

User avatar
darko.ilijevski
Posts: 581
Joined: 21 Mar 2017 16:57

Re: AVRFLASH breaks my ATMEGA328P

#4 Post by darko.ilijevski » 09 May 2017 16:39

digibum wrote:Your answer seams reasonable, but :)
How could I change CPU clock? Device frequency [MHz] was always set to 8.0MHz.
Hi,

Let me make this more clear: Our programmer can not work with the clock frequencies lower than 1MHz. The internal clock has been configured incorrectly so it was set to a frequency lower than our programmer can support. This caused misalignment of the programmer and the MCU's frequencies and made the programmer not able to program correct bits into the MCU to even start the programming.

By using the JTAG programmer, you will avoid the necessity of having aligned clocks, so you will able to set the required fuse bits correctly. I would advise you to set up your clock to use the external clock, which is more reliable and easier to set up, with no fine tuning needed. In any case, you need to set up the clock correctly using JTAG so the MCU can align with our programmer and get programmed by it.

Best regards
BR,
Darko

Post Reply

Return to “mikroC PRO for AVR General”