eeprom_rb() doesn't work

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello! I would be very glad if someone answered my stupid question.

This is a part of my code:
...
#include
...

...
SIGNAL (SIG_INTERRUPT0)
{
unsigned char temp = 0x00;

while (!eeprom_is_ready());
temp = eeprom_rb (ByteAddr);
...

When compiling avr-gcc tells me this:
C:\avr\C>avr-gcc program.c
C:\WIN\TEMP\ccjNd0cb.o: In function `_interrupt0_':
C:\WIN\TEMP\ccjNd0cb.o(.text+0xac): undefined reference to `eeprom_rb'
Would anebody please tell me what this means and what am I to do to get rid of it.
(Don't tell me RTFM. I don't have one:-)

admin's test signature
 

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

Hallo Vasya

In SIGNAL routine are all interrupts disabled (the CLI instruction is executed). But the eeprom_rb() needs the interrupts enabled.
I will not try to use this function in an interrupt routine. Just set some flag (as a global variable) and read the eeprom from the main.
Or you can enable the interrupts in the routine, but before this you should disable the int0 interrupt to prevent recursive calls.

Regards
Daniel

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

Thanks!
I didn't think of that, but I made my program work anyway: I compiled it with the "-lc" flag, it worked and the program seemed to work fine, but you're right: int0 should be disabled before executing the eeprom_rb () sub.

By the way, what does that flag (-lc) do?

Vasya.

admin's test signature
 

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

Hi There Daniel,

I don't think it's correct that interrupts must be enabled to use eeprom_rb(). The routine just loops waiting for EEWE.

Where in this routine must interrupts be enabled???

regards gtoo

(Cut from the library source)

8><-------------------------------------------------------------------------------
#ifdef L_eeprom_rb
/* read one byte from EEPROM */
/* unsigned char eeprom_rb(unsigned int addr); */
/* addr = r25:r24, result = r25(=0):r24 */

.section .text
.global _U(eeprom_rb)

_U(eeprom_rb):
sbic _SFR_IO_ADDR(EECR), EEWE
rjmp _U(eeprom_rb) /* make sure EEPROM is ready */
#ifdef EEARH
out _SFR_IO_ADDR(EEARH), addr_hi
#endif
out _SFR_IO_ADDR(EEARL), addr_lo
sbi _SFR_IO_ADDR(EECR), EERE
clr res_hi /* gcc wants result extended to "int"? */
in res_lo, _SFR_IO_ADDR(EEDR)
ret
#endif /* L_eeprom_rb */

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

Hi Gtoo

Sorry, it was my fault :-)
I've written my own routine to work offline (interrupt driven), but then stopped using it.

Thanks for your reply.

Daniel

admin's test signature