Assembly - EEprom writting issue

Guys

May someone help here .; really don't understand what is wrong in the code but cannot write EEprom ..

I have tn25def. inc included
I am right putting Low adress (0x0A) in EEAR, data into EEDR (R
EEPMn are well set to 0 and EEPE is set to 1 for 2 cycles ( not 4 )?
In the below code ///////////////////////////////////// means code but removed as nothing to see with EEprom

.include "tn25def.inc"

/////////////////////////////////////

		ldi R17,0x09	; EEprom Adress Low

/////////////////////////////////////

EEPROM_read:
	; Wait for completion of previous write
	sbic EECR,EEPE
	rjmp EEPROM_read
	; Set up address (r18 High : r17 LOW) in address register only using low as tn25 >= 256bytes
	;out EEARH, r18
	out EEARL, r17
	; Start eeprom read by writing EERE
	sbi EECR,EERE
	; Read data from data register
	in r16,EEDR
	
/////////////////////////////////////

CYCLE_INT:

	ldi R16,0x01	; Forcing value R16 ( EEDR ) valeur EEPROM


EEPROM_write_INT:
	; Wait for completion of previous write
	sbic EECR,EEMPE
	rjmp EEPROM_write_INT
	; Set Programming mode
	ldi r23, (0<<EEPM1)|(0<<EEPM0)
	out EECR, r23
	; Set up address (r18 High : r17 LOW) in address register only using low as tn25 >= 256bytes
	;out EEARH, r18
	out EEARL, r17
	; Write data (r16) to data register
	out EEDR, r16
	; Write logical one to EEMPE
	sbi EECR,EEMPE
	; Start eeprom write by setting EEPE
	sbi EECR,EEPE
	nop				; aucune action just +1us au timer
	rjmp Start_INT

Kindly, let me know:
1. The type of AVR?
2. Which Assembler you are using?
3. How are you storing the program codes inside the flash of your AVR? I mean -- are you using ROM Programmer or UNO as a Programmer ot what else?
4. Location addresses and the data you are storing in the EEPROM.
5. How do you verify that the data are correctly written into the target locations?

1 Like

Without knowing the processor it is impossible to answer your question properly. If the processor does not contain internal EEPROM and supposedly does it is supported by an external device. Generally that is emulated in RAM and written back to the EEPROM when you use the commit statement. This will depend on the library etc that you are using. Here is a link that will explain what I am trying to say: EEPROM in Arduino and ESP (ESP8266 and ESP32)

1 Like

Hello guys .. thanks a lot for your anwer ... really appreciate it .
The AVR is a tn25 .. I found out what was wrong and will deleate this post.
A few hours to double check the code and the Atmel userguide bring me the solution ... Anyhow .. i heart for each of u :slight_smile:

1 Like

Aw... tell us what was wrong! It'll help the next person.

3 Likes

I have been waiting to receive the answers of my questions of post #2 and then will prepare a precise short tutorial that will provide you a solution.

3 Likes

Hello .. sorry for late replay, i am quite busy at the moment .. 8pm and have not even taken my breakfast :slight_smile:
So what when wrong is actualy that Microchip studio 7 does not indicate the value I am sending in the EEprom even after the 3.2ms to make the Atomic erase and write .. therefore, i was thinking the writting in the EEprom was not working. I have so made a read function after the writ one and i saw the value was chnaged.

not sure this can help for a forum, just a noob issue ..

1- The AVr is A tiny25 20U chip used on a home made PCB
2-
3- I do use micochip studio 7 and an UNO as programmer
4- I was checking with the EEprom Value of Studio 7 .. but seems it is not updating correctly .. At least on my computer.
Other check was to add a read function to a variable after the Write function

Please, show the connection you have made between ATtiny25 and ICSP Port of UNO for storing program codes into the flash of Attiny25 using Arduino UNO as a Programmer.

1 Like

@online67
1. Before I birng you in AVR Assembly Programming for Atiny25/85 using Microchip Studio, I would like to suggest you to practice the following UNO based "EEPROM Register Level codes" to understand the procedures of data read/write operation with EEPROM Memory.

In this program, 5 is being written into EEPROM location 0x0010; the data (n = 5) is read back and the onboard LED (L) is blinked for n times at 1-sec interval as validity check.

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  EEARL = 0x10;  //EEPROM location: 0x0010
  EEARH = 0x00;
  //----------------
  EEDR = 0x05;    //data to be written
  //------------------
  EECR &= (0 << EEPM1);  //EEPROM programming Mode; Erase and Write
  EECR &= (0 << EEPM0);
  //--------------------
  EECR |= (1 << EEMPE); //Master Programming Bit is active
  EECR |= (1 << EEPE);  //EEPROM programming is enabled
  //--------------------
  while (bitRead(EECR, EEPE) != LOW)  //wait until data write is done
  {
    ;  //wait until writing is done; about 3.4 ms
  }
  //--------------
  EECR |= (1 <<EERE); //data read enabled
  byte n = EEDR;      //n = 5
  Serial.print("Read from EEPROM Location, 0x0010: ");
  Serial.println(n);

  for (byte i = 0; i < n; i++)
  {
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);
  }
}

void loop() {}

2. This is the Assemble Program for the sketch of Step-1 usig ATtiny85 device and Microchip Studio Assembler: (assembly successful)

		.cseg
		.org	$0000			;External Pin, Power-on Reset, Brown-out Reset, Watchdog system Reset
RESET:	nop
		rjmp	START

		.org	$0010			;application space	
START:	ldi		r16, 0x00		; stack top initialize at 0x2000
		out		spl, r16
		ldi		r16, 0x20		; 
		out		sph, r16		; Attiny85

		sbi		DDRB, DDB0		;PB0-pin is output

		ldi		r16, 0x10		;loading low-byte of EEPROM address
		out		eearl, r16
		ldi		r16, 0x00		;loading high byte of EEPROM address
		out		eearh, r16

		ldi		r16, 0x05		;data for EEPROM location
		out		eedr, r16

		cbi		eecr, EEPM1		;EEPROM Programming Mode; erase/write
		cbi		eecr, EEPM0

		sbi		eecr, EEMPE		;setting up EEPROM Master programmin Enable bit
		sbi		eecr, EEPE		;EEPROM programming enable

L1:		sbis	eecr, EEPE		;skip next line if EEPE-bit of eecr register is HIGH
		rjmp	L2				;data write into EEPROM complete
		rjmp	L1				;data is not yet written into EEPROM location
		
L2:		sbi	eecr, EERE			;data read enable active
		in	r16, EEDR			; data read
		
L3:		;blink LED at PB0-pin for n = (r16) times
		sbi		PORTB, PB0
		rcall	DELAY
		cbi		PORTB, PB0
		rcall	DELAY
		dec		r16
		brne	L3

L4:		rjmp	L4				;wait here for ever
			
DELAY:	ldi		r18, 30			;time delay subroutine
cagain:	ldi		r19, 30
magain:	ldi		r20, 30
fagain:	dec		r20
		brne	fagain
		dec		r19
		brne	magain
		dec		r18
		brne	cagain
		ret		
				
		.exit

3. Given below is the Intel-Hex formatted file for the program of Step-2, which bears the binary codes of the program. The AVR Programmer of Fig-1 will extract the binary codes from the received hex file and then it will store the binary codes into the flash of ATtiny85.

:020000020000FC
:0400000000000EC02E
:1000200000E00DBF00E20EBFB89A00E10EBB00E099
:100030000FBB05E00DBBE598E498E29AE19AE19BDD
:1000400001C0FDCFE09A0DB3C09A05D0C09803D08F
:100050000A95D1F7FFCF2EE13EE14EE14A95F1F747
:0A0060003A95D9F72A95C1F70895E3
:00000001FF

image
Figure-1:

4. Place the ATtiny85 in the ZIF socket of Fig-1 and fuse the Hex-file of Step-3.

5. Testing for Data write validiy into EEPROM location.
(1) Take out the Attiny85 from ZIF socket.

(2) Place the ATtin85 on the Breadboard.

(3) Build circuit on Breadboard as per Fig-2.


Figure-2:

(4) Connect GND-pin of UNO (or -side of 5V Battery/Adopter) with Pin-4 of ATtiny85.

(5) Connect 5V-pin of UNO (or +side of 5V Battery/Adopter) with Pin-8 of Attiny85.

(6) Press the RESET Button, K1.

(9) Check that RLED blinks for five times.
The RLED is not blinking!!

6. Storing sketch (comment the Serial commands) Step-1 into the flash memory of ATtiny85 using Arduino UNO as Programmer.
This is working having followed the steps of this link.

So this was all a problem with the debugger not properly retrieving the updated values?

I have carried out all the steps of post #11; where --
Step-1 is working in Arduino UNO Platform.

Step-2 to 4 are done.

Step-5(9) is not working. The RLED is not blibking. It is just ON. I have tried on two chips, bu the result is the same.

Would apreciate to receive your help to make Step-5 of post #11 working.

Note: I have been able to program (uploading sketch (after commenting the Serial commands) of Step-1 of post #11) the same ATtiny85 chip following sub-steps of Step-6 of post #11. The RLED of Fig-2 blinks for five times indicating that data read/write at the target EEPROM location of ATtiny85 has happened correctly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.