Mismatch error when programming atMega2560 with Assembly

Hello,

I've recently tried to connect the ultrasonic sensor to arduino and read the output based on the External Interrupt length. The issue I have is I get an error which looks like this :

avrdude.exe: verification error, first mismatch at byte 0x0200
             0x00 != 0x01
avrdude.exe: verification error; content mismatch

avrdude.exe: safemode: Fuses OK (E:FD, H:D8, L:FF)

I have no clue what that means.
I'm guessing it may have to do with these few lines of code :

ldi r16, 0x01
	STS EICRA, r16 ; make INT0 rising edge triggered
	clr r16

	ldi r16, 0x01
	OUT EIMSK, r16 ; enable INT0 interrupt
	SEI ; enable interrupts
	clr r16

But that's just my guess.
Thank you for the help :slight_smile:

Best regards

Can you still upload example sketches?

There was/is a problem with the Mega boot loader if your sketch contains three exclamation marks in a row. So I to not think that this is cause by the code snippet that you posted.

.ORG 0
JMP MAIN

 .ORG 0x02 ; vector interrupt for INT0 = 0x02
	call int_detect_wave_from_sensor

.ORG 0x100 ; ommit first 100 addresses left for interrupts
	LDI R16, HIGH(RAMEND)
	OUT SPH, R16
	LDI R16, LOW(RAMEND)
	OUT SPL, R16 ; initialize stack pointer
	clr r16
	
	ldi r16, 0xFF ;
	out DDRA, r16 ; port A output
	ldi r16, 0x00 
	out DDRD, r16 ; port D input
	

	ldi r16, 0x01
	STS EICRA, r16 ; make INT0 rising edge triggered
	clr r16

	ldi r16, 0x01
	OUT EIMSK, r16 ; enable INT0 interrupt
	SEI ; enable interrupts
	clr r16


	;----- start main
	main :
	ldi r16, 1<<PA0
	out PORTA, r16 // Send HIGH on PA0 to start the detect and PROBABLY start interrupt
	ldi r16, 0
	out PORTA, r16 // clear the PA0
	clr r16


	

	call delay_detection_60ms

    rjmp main
	; ----- end main


		delay_detection_60ms: ; delay 60ms for the sensor accurate response
	ldi r17, 250
	
	again:
	dec r17 ; 1 c
	brne again ; 2c
	ldi r17, 80
	again2:
	dec r17
	brne again2
	ret

	
	int_detect_wave_from_sensor:

	 ldi r19, 1<<PA2 ; high on PA2 for buzzer 
	 out PORTA, r19
	 call delay_detection_60ms ; just a random delay that would put buzz at least for 60ms
	 clr r19
	 reti

This is the whole code. At this point I am only trying to get any kind of response from the sensor

Does the same error occur if you upload the bare minimum sketch you get via File > New, or does it only happen when you post the specific code you shared above?

I get it only with this specific code, my other projects work fine. I also tried to run this on two different arduinos and problem stays the same

I fixed it. The problem is I used .ORG 100 in the code, which seems to override some of the registers I was working with there. I changed it to .ORG 400 and it all runs perfect :slight_smile: