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

标签 c gcc arduino avr avr-gcc

我在从程序内存读取字符串时遇到一些问题:

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

这是我的打印例程:

/** 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++;
    }
}

普通的工作得很好,但是程序会打印无限的0xFF流。哪里错了?

我以前使用过 progmem,它总是有效..我似乎找不到这里的问题。

最佳答案

哦,我不应该取消引用那里的指针...

pgm_read_byte(&str)

应该只是

pgm_read_byte(str)

现在正在运行。

关于c - AVR PROGMEM 读取垃圾而不是字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29832297/

相关文章:

-O3 与 -Ofast 优化之间的 gcc 差异

c++ - tbb::cache_aligned_allocator:使用 __m128i 获取 "request for member...which is of non-class type"。用户错误或错误?

arduino - XBee 发送给所有人

sockets - 将 ESP8266 连接到虚拟 IP 地址/网站

Arduino Nano无串口通信SIM800C

C HelloWorld exec 格式错误

c - 关于岗位增量

c - 如何在 C89 中将 boolean 值插入位域

c - 一直保持strtok_s的第一个参数为NULL对不对?

C 程序因大型数组而崩溃