Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

writing my own print function

Status
Not open for further replies.

hithesh123

Full Member level 6
Full Member level 6
Joined
Nov 21, 2009
Messages
324
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
lax
Visit site
Activity points
3,548
I want to write my own print function, something like printf_uart. What ever text string is the printf_uart("text") should be output on the serial port.
How do I pass the characters from the printf_uart to the function void printf_uart()?
 

What is the compiler and device to which you are referring?

Some compilers like KEIL already offer such a implementation.


BigDog
 

As you are not using printf() to send data to UART you can name it printf_uart() or send_uart(). It doesn't matter. First you have to write a function like printf_uart_byte('K'); which can send byte. You then use this function in a while loop which sends bytes till end of string is found.
 

u can use following function as

Code:
void print_uart(unsigned char *strng)
{
          while(*strng!='\0')
          {
                   tx(*strng++);
           }
}

now tx function will send one byte at a time. and u can use fun as

Code:
print_uart("Hello world");

which is same as printf.
 
Last edited by a moderator:

I don´t like too much work with printf function, due all processing stay locked there while all characters will be transmited.
Instead it, at some circumstances is prefereable manage a putc.


+++
 

Although you didn't specify it, perhaps you're interested in implementing additional parameters, like the real printf does:

printf("The result is %d.\n",i1);

In which case it would be helpful to examine an existing stand-alone implementation, like Kustaa Nyholm's "tiny printf", found here:

https://www.sparetimelabs.com/tinyprintf/index.html

Which calls a function with the output characters, one at a time; so it's easy to route to a UART or anything else you might like.
 
u can use following function as

void print_uart(unsigned char *strng)
{
while(*strng!='\0')
{
tx(*strng++);
}
}

now tx function will send one byte at a time. and u can use fun as

print_uart("Hello world");

which is same as printf.

I am using something very similar. But IAR throws weird error -

Error[e16]: Segment ISTACK (size: 0x40 align: 0) is too long for segment definition. At least 0x1
more bytes needed. The problem occurred while processing the segment placement
command "-Z(IDATA)ISTACK+_IDATA_STACK_SIZE#08-_IDATA0_END", where at the
moment of placement the available memory ranges were "IDATA:c1-ff"

It's really weird, if the string inside the printf function is small, I don't get this error. If the string is more than one alphabet, I get this error.
 

If it is one character then it is a character and not string. single characters should be enclosed in single quotes and strings should be enclosed in double quotes.

No, its not about single/double quotes. Something is weird in IAR or in my function. If I put a whole big sentence in my printf_uart function, then I get the same error. If I cut short the sentence then no error.

Here's my printf_uart function -

Code:
void printf_uart(char *strn)
{
  UTX0IF=0;			// RESET TX IF
    
    while(*strn!='\0')   
      {
        U0DBUF= *strn++;
        while(UTX0IF==0);
        UTX0IF=0;
      }  
}
 

Error[e16]: Segment ISTACK (size: 0x40 align: 0) is too long for segment definition.

I'm not familiar with your compiler or MCU, but this error message seems to indicate you've overflowed your stack. The conditions in which your problem occurs also point towards this.

Check its size. The stack must be large enough to hold all non-constant local variables in use at any instant, plus saved MCU registers and return addresses when functions are called.
 

I'm not familiar with your compiler or MCU, but this error message seems to indicate you've overflowed your stack. The conditions in which your problem occurs also point towards this.

Check its size. The stack must be large enough to hold all non-constant local variables in use at any instant, plus saved MCU registers and return addresses when functions are called.

I commented out 3 functions. I still get this error. But if I decrease the string length in printf_uart(), then I don't get the error!
 

What compiler are you using? IAR for ARM or AVR? Zip and post your IAR files so that it can be Compiled and tested. If you can't post you will not get much help and also quick solution.
 

What compiler are you using? IAR for ARM or AVR? Zip and post your IAR files so that it can be Compiled and tested. If you can't post you will not get much help and also quick solution.

I am uisng IAR for TI CC2510 RF SOC.

zip files attached.
 

Attachments

  • New folder.rar
    11.1 KB · Views: 112

it must be overflow of RAM so try to use ROM for your fix const. and also your strings.
i think ,it will help you.
n try to minimize your variables.
 

RFDATA_BUF[102]; Is there enough ram available?

Try const unsigned char for all your messages and use const unsigned char * as argument for your function. RFDATA_BUF[] has consumed 102 bytes of RAM. Remove your function and Compile and see how much RAM and ROM is left free.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top