[Top][All Lists]

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

RE: [avr-gcc-list] printf_P + PSTR("\n\r") does not seem to work,howeve

From: Bernard Fouché
Subject: RE: [avr-gcc-list] printf_P + PSTR("\n\r") does not seem to work,however ("\r\n") is okay
Date: Thu, 12 Aug 2004 16:51:39 +0200

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
#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)

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



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


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

  return 0;

int myputs_P(const char *s)
  unsigned char c;

int myputs(const char *s)
  unsigned char c;

int main()
  // Quartz is at 4Mhz, go down to 1Mhz
  // Setup UART
  UCSR0B = 0x00;
  UCSR0A = 0x00;
  UBRR0L = 0x0C;
  UBRR0H = 0x00;
  UCSR0A = 0x00;
  UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0);



-----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

reply via email to

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