avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FIXED: was avrdude prb [RE: [avr-gcc-list] printf_P + PSTR("\n\r") does


From: Bernard Fouché
Subject: FIXED: was avrdude prb [RE: [avr-gcc-list] printf_P + PSTR("\n\r") does not seem towork,however ("\r\n") is okay]
Date: Thu, 12 Aug 2004 18:26:21 +0200

Hi there.

Sorry to have polluted the list with that. I switched from binary format to
ihex format for
avrdude and the problem just vanished! I'm new to avr-gcc/avrduve, probably
to use the binary
format was stupid, I suppose there were some kind of communication problems
introduced by the '\r'!

I found the problem when I understood that the presence on '\r\n' in any
text was perturbating
the software, even when not referencing flash memory.

 B.

-----Message d'origine-----
De : address@hidden
[mailto:address@hidden la part de Bernard Fouché
Envoyé : jeudi 12 août 2004 16:52
À : address@hidden
Objet : RE: [avr-gcc-list] printf_P + PSTR("\n\r") does not seem
towork,however ("\r\n") is okay


Well this is very strange.

If I take the problematic string from ram, then it works. If I take the
string from flash it does not. Now I don't run this on the STK500 but on the
final product. But, if I send the same string from flash from Iccavr, it
works also.

I changed of terminal emulator, moving from IVT (rather good) to
Hyperterminal and then to a term session under Linux. Changing this piece of
the communication chain gave the same results.

So I ended up with the a new listing that is focused only on the difference
between flash and ram: it dumps the hex value of the characters on the UART
instead of the characters themselves.

And then I now have something that produce things like "232323232323"
instead of "48656C6C6F20210A" when using flash and not ram! If you don't
send the \r then it works again!

That's so stupid that I must miss something really obvious, like compilation
flags or something else.

Here is the new listing:

#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>

/*
 * Select M_FLASH or MY_RAM to use ram or flash to store and retrieve the
string
 */
#define MY_FLASH
//#define       MY_RAM
/*
 * Uncomment to activate the problem. The problem shows if MY_FLASH and
MY_PROBLEM are defined together.
 */
//#define MY_PROBLEM

#ifdef  MY_RAM
#define MY_TEXT         "\r\nHello !\r\n"
#define MY_MEMORY       char Str[]
#define MY_FUNC         myputs(Str)
#endif

#ifdef  MY_FLASH
#ifdef  MY_PROBLEM
#define MY_TEXT         "\r\nHello !\r\n"
#else
#define MY_TEXT         "\nHello !\n"
#endif
#define MY_MEMORY       const char Str[] PROGMEM
#define MY_FUNC         myputs_P((PGM_P)Str)

#endif

MY_MEMORY = MY_TEXT;

// Instead of outputing char, we output hex value
int myputc(unsigned char c)
{
  static char HexTab[]="0123456789ABCDEF";
  char fn;
  char sn;

  fn=HexTab[(c&0xF0)>>4];
  sn=HexTab[(c&0x0F)];

  /* output character to UART0 */
  while ((UCSR0A & BV(UDRE0)) == 0)
    wdt_reset();
  UDR0 = fn;
  /* output character to UART0 */
  while ((UCSR0A & BV(UDRE0)) == 0)
    wdt_reset();
  UDR0 = sn;

  return 0;
}

int myputs_P(const char *s)
{
  unsigned char c;
  while((c=pgm_read_byte(s++)))
    myputc(c);
}

int myputs(const char *s)
{
  unsigned char c;
  while((c=(*s++)))
    myputc(c);
}

int main()
{
  wdt_enable(WDTO_2S);
  // Quartz is at 4Mhz, go down to 1Mhz
  cli();
  CLKPR=0x80;
  CLKPR=0x02;
  sei();
  // Setup UART
  UCSR0B = 0x00;
  UCSR0A = 0x00;
  UBRR0L = 0x0C;
  UBRR0H = 0x00;
  UCSR0A = 0x00;
  UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0);

  MY_FUNC;

  while(1)
    wdt_reset();
}


-----Message d'origine-----
De : address@hidden
[mailto:address@hidden la part de Joerg Wunsch
Envoyé : jeudi 12 août 2004 12:47
À : address@hidden
Objet : Re: [avr-gcc-list] printf_P + PSTR("\n\r") does not seem to
work,however ("\r\n") is okay


Bernard Fouché <address@hidden> wrote:

> If I do printf_P(PSTR("\r\n")); everything is okay, however if I
> switch it to "\n\r", I get no output. Did I miss something or is it
> a bug?

Perhaps a problem with your terminal emulator?

printf() doesn't care the least about the characters in the format
string, it simply passes everything that's not a format specification
on to putc() which in turn will call your supplied output routine.

--
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

[Prev in Thread] Current Thread [Next in Thread]