Problems with a string

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

Hello

I am working on transmission beetwen 2313 USART .
For the moment, i send a message from a PC, and i try to show it on a lcd.

I receive the string of character but i can't display it...

Declaration of the string

volatile char buf_rx [8];  

Construction of ths string (recption)

	if (debut==1 && rx!='D') {     /// a faire : si >6 alors reset
	  lcd_puts("D");
		if (rx!='F')
			{
			buf_rx[pos]=rx;
			pos++;
			putchr(rx);
			printstr_p(PSTR("=data\n"));
			}
		else {
			if (pos==6)
				{
				rx_buff_complete=1;
				UCSRB &= ~_BV(RXCIE);
				}
			}
	}

It's ok ...

But the following is no good : i can't display rx_buf, nor lcd, nor serial :

lcd_puts(buf_rx);
	printstr_p(PSTR("BUFRX="));
	printstr_p(PSTR(buf_rx));
	printstr_p(PSTR("\n"));

Compiling say
"warning, passing argument of "lcd_puts"make pointer from integer without a cast.
And :" invalid initializer".

I'm a not a crack with pointer.
If you could help me, thanks.
:)

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Is it possible you have more than one symbol called 'buf_rx'?

It would be true that if you used:

lcd_puts(12345);

you would get that warning. If you extended that and used:

int buf_rx = 12345;
lcd_puts(buf_rx);

you'd get the same warning (for basically the same thing).

But if buf_rx is really the name of a char array I don't see why the compiler would have produced the warning.

Of course I'm making the gross assumption that the prototype for lcd_puts() is:

void lcd_puts(char * str);

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
lcd_puts(12345); 

give the same problem.
The lib is from Fleury, i will verify if itis

void lcd_puts(char * str); 

.

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Quote:
void lcd_puts ( const char * s )

Display string without auto linefeed. void lcd_puts ( const char * s )

Display string without auto linefeed.


from http://homepage.hispeed.ch/peter...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Apparently it is:

D:\fleury>grep lcd_puts *.h
extern void lcd_puts(const char *s);

It's true that you are passing 'volatile' and losing 'const' but I'd expect a warning about "modifiers" not about converting an int to a pointer for this?

Can you make the shortest test program that demonstrates this and post the entire thing here (don't bother with the Fleury code - we've all got that).

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

What do you want me to demonstrate?

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

The smallest program possible in which

lcd_puts(buf_rx);

leads to:

warning, passing argument of "lcd_puts"make pointer from integer without a cast.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include 
#include 
#include "dm_lcd.h"
#include 
#include 


  
   
volatile char buffer[7]={ 'B', 'o', 'n', 'j', 'o', '\0' };


int main(void)
{


while (1){

	lcd_init(LCD_DISP_ON);


 	 lcd_puts("= GO GO GO =");
  	_delay_ms(2000);
 	 lcd_clrscr();
      
        lcd_puts(buffer);
 	}
}

I got this warning
"passing arguments 1 of lcd puts discards qualifier from pointer target".But, it compile it...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Quote:

It's true that you are passing 'volatile' and losing 'const' but I'd expect a warning about "modifiers" not about converting an int to a pointer for this?

So the warning wasn't the:

passing argument of "lcd_puts"make pointer from integer without a cast.

you said in the first post and the loss of "volatile" was expected to produce a warning.

So what exactly WAS the point of this thread?

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

Thanks for your following.
All this is complex for me : the problem and the language.

Lcdputs seems to not accept a volatile char, i think.
Because there is a pointer story....

The litle program give another warning.

So, i'm lost (more than the tv program).

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

But you said the warning was:

passing argument of "lcd_puts"make pointer from integer without a cast. 

If it really had been that would be an extremely worrying warning and something was seriously wrong with the code. But now you tell us the warning was:

passing arguments 1 of lcd puts discards qualifier from pointer target

which is almost completely benign and can be ignored at leisure.

All it's saying is that lcd_pus() expects a pointer to char and yet what's being passed is a pointer to volatile char. The fact that it won't be treated as volatile inside lcd_puts() as a consequence is no worries whatsoever and, indeed, I personally don't think it makes much sense to make an array volatile in the first place as the compiler will almost inevitably not optimise it anyway.

If you have any thinking to do here it's to consider what motivated you to make the array elements 'volatile' in the first place.

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

I use volatile because the variable is call in an interrupts.

I may convert the volatile in const char.
It's not a delicate way, for my RAM, i will say you if it'swork better.
Thanks for your patience.

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Dear Clawson,
Thank you for every thing.
I avoid my problem, i want my project to grown!!!

So i make a copy of my volatile string to a constant one.
Not very nice.
This show me i got to understand more and more the pointers...

computer : GNU Linux / e6750
ship : Attiny 2313 / ATmega8
compiler : avr-gcc 1:4.3.2-1

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

Question: Zettaman's code says "volatile char buf_rx [8];" which should put it in RAM but it's used like this later: "printstr_p(PSTR(buf_rx));"

Isn't PSTR a macro that defines static strings in Program Memory? Wouldn't it conk out on a pointer to ram?

If not, then that's pretty cool. Didn't know that.

odokemono. I try to entice electrons to do my bidding.