| Author |
Message |
|
|
Posted: Apr 13, 2009 - 06:43 PM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
Hi
My name is Yoni and I practical engineering from Israel
And sorry about my poor English
today i began to write interface progrem for LCD
the instruction strings I am going to store in the flase area for that I am use the avr/pgmspace/h librery and I red this great artical which help me a lot
http://www.avrfreaks.net/index.php?name ... mp;t=38003
but when I wrote this progrem the compiler didnt found any bug and sdidfnt show any warning but when I simulate the program the out port didnt show the right ascii value and show other one
this is the progrem
#include<avr/pgmspace.h>
#include<avr/io.h>
#include<avr/version.h>
void data_for_send(char *data)
{
while (pgm_read_byte(data) != '\0')
{
PORTD=pgm_read_byte(data);
data++;
}
}
void main()
{
asm("nop");
prog_char TestFlashStr[] = "Hello";
DDRD=0xff;
data_for_send(TestFlashStr[0]);
asm("nop");
}
if any one know what is the problem please notifi me what is it or may be there is a bug with my compiler
the compiler is the latest or almost the latest version of winavr
another question any one have another place which contain information about this librery which is not the avr reference where i can learn more about this librery
Thanks Yoni Spiegel |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 12:23 AM |
|


Joined: Jan 14, 2008
Posts: 764
Location: San Diego
|
|
You are not using the array correctly
Do not dereference the array.
Code:
void main()
{
asm("nop");
prog_char TestFlashStr[] = "Hello";
DDRD=0xff;
data_for_send(TestFlashStr);
asm("nop");
}
Edit: Removed incorrect info |
Last edited by atomicdog on Apr 14, 2009 - 04:47 AM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 01:02 AM |
|

Joined: Jul 23, 2001
Posts: 977
Location: Osnabrueck, Germany
|
|
|
atomicdog wrote:
You need to dereference the pointer.
No. His version of data_for_send is correct.
atomicdog wrote:
Do not dereference the array.
Yes, that's right.
@ Yehonatan:
Your major problem is that you try to put an automatic local variable into flash. That does not work. Make TestFlashStr global or static local. |
_________________ Stefan Ernst
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 09:46 AM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
Hi
I changed the string to global but it still doesn't work well
the first value that I receive in out put is 0xC
after that 0x94
and 0x5A
any one have an idea why the program still there is a bug
Yoni Spiegel |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 09:47 AM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
Hi
I changed the string to global but it still doesn't work well
the first value that I receive in out put is 0xC
after that 0x94
and 0x5A
any one have an idea why the program still there is a bug
Yoni Spiegel |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 09:48 AM |
|


Joined: Jul 18, 2005
Posts: 34712
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| So post the code you are now using. Also please do NOT cross post - I wasted my time answering your other copy of this same thread last night. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 10:07 AM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
the new code is
#include<avr/pgmspace.h>
#include<avr/io.h>
#include<avr/version.h>
prog_char TestFlashStr[10] = "Hello";
void data_for_send(char *data)
{
while (pgm_read_byte(data) != '\0')
{
PORTD=pgm_read_byte(data);
data++;
}
}
void main()
{
asm("nop");
DDRD=0xff;
data_for_send(TestFlashStr[0]);
asm("nop");
}
and sorry the mass that I done my laptop doing a lot of problems with this web site and I dont know why (may be buster or virous ) so if you can give me a link to the next post it would be helpful  |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 10:21 AM |
|


Joined: Jul 18, 2005
Posts: 34712
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
Would you PLEASE learn to use [ code ] tags - your code is virtually unreadable otherwise.
Anyway it would seem that you have completely ignored the advice given by atomicdog, Stefan and myself previously. As I told you in the other copy of this thread use:
Code:
data_for_send(&TestFlashStr[0]);
or
Code:
data_for_send(TestFlashStr);
but not:
Code:
data_for_send(TestFlashStr[0]);
You need to pass the ADDRESS OF the object, not the value of the first element as your receiving routine is defined to accept a pointer not a value. |
_________________
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 10:30 AM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
thanks a lot this really was my problem  |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 10:43 AM |
|


Joined: Jul 18, 2005
Posts: 34712
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| You do understand the change that has been made don't you? That is you do understand the purpose of '&' or the fact that specifying the name of an array passes a pointer to it? |
_________________
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 10:59 AM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
Yes I understand this change data_for_send(&TestFlashStr[0]); to send the adress to the pointer I think
but I dont understand why this is OK
data_for_send(TestFlashStr);
but I will be happy to read better explantion if someone have
I glad to learn new information especially with AVR |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 11:17 AM |
|


Joined: Jul 18, 2005
Posts: 34712
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
but I dont understand why this is OK
C just does you a favour of passing the address of an array if you specify nothing but the name without [] to pick out a specific element. When you do something like:
Code:
char text[] = {"Hello, world"};
char buffer[20];
...
strcpy(buffer, text);
UART_printstring(buffer);
then it acts the same as:
Code:
char text[] = {"Hello, world"};
char buffer[20];
...
strcpy(&buffer[0], &text[0]);
UART_printstring(&buffer[0]);
(just a bit easier to read). |
_________________
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 12:47 PM |
|

Joined: Nov 19, 2008
Posts: 14
|
|
| thanks a lot now I understand this topic much better than befor |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 05:11 PM |
|

Joined: Mar 12, 2004
Posts: 832
Location: Portland, OR, USA
|
|
|
sternst wrote:
Your major problem is that you try to put an automatic local variable into flash. That does not work. Make TestFlashStr global or static local.
It would seem that at least a warning would be appropriate here, perhaps even an error. Here are two pieces of test code, both of which compile without error/warning but only one produces code that comports with the specified attributes.
This one results in correct code:
Code:
#include <avr/pgmspace.h>
char b;
int main(void)
{
static prog_char data[] = "abcd";
b = pgm_read_byte(data);
}
This one results in incorrect code:
Code:
#include <avr/pgmspace.h>
char b;
int main(void)
{
prog_char data[] = "abcd";
b = pgm_read_byte(data);
}
|
_________________ Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 05:14 PM |
|


Joined: Jul 18, 2005
Posts: 34712
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
It would seem that at least a warning would be appropriate here, perhaps even an error
prog_char would need some serious re-work then - at present it's nothing more than a typedef. Also how can a macro tell if it's been invoked in the context of a local or a global? Or were you suggesting an actual modification to the linker? |
_________________
|
| |
|
|
|
|
|
Posted: Apr 14, 2009 - 05:38 PM |
|

Joined: Mar 12, 2004
Posts: 832
Location: Portland, OR, USA
|
|
|
clawson wrote:
Or were you suggesting an actual modification to the linker?
I wasn't suggesting an implementation - I don't know enough about the structure of the compiler/linker to do so.
I have seen a warning related to Flash data items. For example, the code below produces the message:"warning: '__progmem__' attribute ignored". In both cases the attribute indicating that the data item should be placed in Flash has to be represented somewhere along with the attribute indicating whether the data item is statically or dynamically allocated.
Code:
#include <avr/pgmspace.h>
char b;
int main(void)
{
char foo[] PROGMEM;
b = pgm_read_byte(foo);
}
|
_________________ Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net
|
| |
|
|
|
|
|