Atmel studio Attiny44A

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void EEPROM_write(unsigned int ucAddress, unsigned char ucData
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE))
;
/* Set Programming mode */
EECR = (0<<EEPM1)|(0<<EEPM0)
/* Set up address and data registers */
EEAR = ucAddress;
EEDR = ucData;
/* Write logical one to EEMPE */
EECR |= (1<<EEMPE);
/* Start eeprom write by setting EEPE */
EECR |= (1<<EEPE);
unsigned char EEPROM_read(unsigned int ucAddress)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE))
;
/* Set up address register */
EEAR = ucAddress;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}

 When I enter the code for EEPROM in Atmel studio, this error occurs, although I took an example from the datasheet:

Expression cannot be used as a function  EEAR

Last Edited: Fri. Oct 18, 2019 - 12:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Post a small complete project that demos the problem, as that can not be the complete program, most likely you have left something out.

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define F_CPU 1000000UL  // устанавливаем рабочую частоту контроллера
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>

void EEPROM_write(unsigned int ucAddress, unsigned char ucData)
{

	while(EECR & (1<<EEPE))
	{}

	EECR = (0<<EEPM1)|(0<<EEPM0)
	EEAR = ucAddress;
	EEDR = ucData;
	EECR |= (1<<EEMPE);
	EECR |= (1<<EEPE);
}
unsigned char EEPROM_read(unsigned int ucAddress)
{

	while(EECR & (1<<EEPE))
	{}

	EEAR = ucAddress;
	EECR |= (1<<EERE);
	return EEDR;
}

int main(void)
{
	EEPROM_write(1,120);
    while(1)
    {
        //TODO:: Please write your application code
    }
}

 

Last Edited: Fri. Oct 18, 2019 - 12:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1
	EECR = (0<<EEPM1)|(0<<EEPM0)
	EEAR = ucAddress;

Did we miss a semi-colon perhaps?

 

Remember that when you can't spot a reported error then look at the line above. As it stands the C compiler see this as:

	EECR = (0<<EEPM1)|(0<<EEPM0) EEAR = ucAddress;

Also, why on earth are you writing EEPROM routines when the compiler already has:

 

https://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void EEPROM_write(unsigned int ucAddress, unsigned char ucData)
{

	while(EECR & (1<<EEPE))
	{}

	EECR = (0<<EEPM1)|(0<<EEPM0)   <-- missing a ";" at end of line!!!
	EEAR = ucAddress;
	EEDR = ucData;
	EECR |= (1<<EEMPE);
	EECR |= (1<<EEPE);
}

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I’ve been looking for an error for an hour

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Remember that when you can't spot a reported error then look at the line above.

Absolutely!

 

It can sometimes be a few lines.

 

And, if "the line above" is a #include, then you will have to look into the included file ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Attached is a tutorial that demonstrates how to use some (and the rest) of the routines in the eeprom.h standard library

provided in AtmelStudio.

 

Attachment(s): 

If the facts don't fit the theory, change the facts. ALBERT EINSTEIN