printf problem

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

Hello, I've open this new topic because I'm having problems trying to use the printf() and printf_P() function in my project's serial communication.
I'm using an atmega88pa, I've tried with the examples in the avrlibc page, and some from this forum, and got nothing.
The serial communication it's working fine, I can send and receive characters, I can send string chars too, with a puts function that I made.
I'm going crazy with this, if someone can help me I will totally grateful.

Regards.

P.S.: I apologize if it's not the correct subforum for this question, and for my english =).

P.S.2: I attached the code that I'm using to do the tests

Attachment(s): 

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

Tell us more about:

_STDIO_H_

The stdout stream is only set to mystdout if that define is made. Where do you think it is made? I'm guessing it's in stdio.h (seems like the obvious place!) yet I don't see you #include'ing stdio.h anywhere?

Why protect the code with that define anyway?

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

Personally, I always build buffer(s) with sprintf() and then send the resulting strings (as opposed to printf() directly). But I guess that is personal preference.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

clawson wrote:
Tell us more about:

_STDIO_H_

The stdout stream is only set to mystdout if that define is made. Where do you think it is made? I'm guessing it's in stdio.h (seems like the obvious place!) yet I don't see you #include'ing stdio.h anywhere?

Why protect the code with that define anyway?

I think it's a little messy the thing with the macros conditions, so I dump them and make some restructure in the code, no more _STDIO_H_.
I'm including the in the top of the usart.h

when I put all together, the code pass from 768 bytes to 2160 bytes and when the microcontroller send the routine with the printf_P(), it's like it jumps it and nothing happens, the micro still do the other things that it should do, but nothing out the serial communication.

I don't know what to do

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

xRockDx wrote:
when I put all together, the code pass from 768 bytes to 2160 bytes
By any chance is there a new variable length delay?
Quote:
and when the microcontroller send the routine with the printf_P(), it's like it jumps it and nothing happens, the micro still do the other things that it should do, but nothing out the serial communication.

I don't know what to do

Strip out most code except communication and try to make that work.
When you get that working, gradually add back the other code.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

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

Hello again, sorry for the time i've been away, I was in a travel with no wifi.

ok, what I did was the following, I strip off all the surrounding code except for the serial, I keep the configuration code of the serial and copied the example of the avr libc but still do the same, nothing from the serial.

I was wondering if I have to pass some flag to the linker, if it so, can anybody please tell me what it is.

I attached th main.c with the configuration code and the example from the library page and the make file, if someone want to see if there any error that I been missing.

Attachment(s): 

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

It's your Makefile - you made the classic objcopy error. Try:

avr-objcopy -j .text -j .data -O ihex  serial.bin serial.hex

(that is adding .data initialisers to the flash image so "Hello, world!\n" gets copied).

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

clawson wrote:
It's your Makefile - you made the classic objcopy error. Try:

avr-objcopy -j .text -j .data -O ihex  serial.bin serial.hex

(that is adding .data initialisers to the flash image so "Hello, world!\n" gets copied).

Thanks a lot clawson it totally worked!!!
thanks to everyone for the help.