简体   繁体   English

AVR PROGMEM读取垃圾而不是字符串

[英]AVR PROGMEM reads garbage instead of string

I have some problem with reading string from program memory: 我从程序存储器中读取字符串时遇到一些问题:

const char str[] PROGMEM = "Test string here\r\n";

Here are my printing routines: 这是我的打印例程:

/** Send string over UART */
void uart_puts(char* str)
{
    while (*str) {
        uart_tx(*str++);
    }
}

/** Send progmem string over UART */
void uart_puts_pgm(const char* str)
{
    char c;
    while (0 != (c = pgm_read_byte(&str))) {
        uart_tx(c);
        str++;
    }
}

The normal one works just fine, but the progmem one prints infinite stream of 0xFF . 正常的一个很好,但是程序一打印出无限的0xFF流。 Where is the mistake? 错误在哪里?

I've worked with progmem before, and it always worked.. I can't seem to find the problem here. 我以前使用过progmem,并且一直都能使用。.在这里我似乎找不到问题。

D'oh, I shouldn't dereference the pointer there... 噢,我不应该在那儿取消引用指针...

pgm_read_byte(&str)

should be just 应该只是

pgm_read_byte(str)

It's working now. 现在正在工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM