-1

我正在尝试将数据存储在 PROGMEM 中并稍后检索它。然后通过 USB 串行通讯将它们发送到屏幕。

int8_t serial_comm_write(const uint8_t *buffer, uint16_t size){
    //Here contains the code from the lib which I don't understand.
    //Basically, it's sending data (char *data) thru to screen. 
}

//This char *data could simply be:
// char *line = "This is stored in RAM"
//usb_send_info(line); would send the "line" to the screen.
void usb_send_info(char *data){
    serial_comm_write((uint8_t *)data, strlen(data));
}

//This doesn't work. I got a squiggly line saying "unknown register name 
//'r0'
//have no idea what it means. 
void usb_send_info_P(const char *data){
    while(pgm_read_byte(data) != 0x00){
        usb_send_info((pgm_read_byte(data++))); 
    }
}

const static char line1[] PROGMEM = "This is stored in flash mem";

usb_send_info_P(line1);

它只是行不通。任何提示或替代方案?干杯。

4

2 回答 2

0

usb_send_info 需要一个指向 SRAM 的 char*,而不是 FLASH (PROGMEM)。

usb_send_info((pgm_read_byte(data++))); 

pgm_read_byte 从给定的 PROGMEM 地址读取单个字节/字符。它不返回指针。所以这个函数调用没有意义。

如果您像这样更改 usb_send_info,它应该可以工作:

void usb_send_info(char data) {
    serial_comm_write((uint8_t *)&data, 1);
}
于 2018-10-25T10:13:56.203 回答
0

得到了小伙伴的帮助。对于任何想知道的人,这里是问题的答案。特别感谢乔纳森。

int8_t serial_comm_transmit(uint8_t c)
{
    uint8_t timeout, intr_state;

    if (!usb_configuration) return -1;

    intr_state = SREG;
    cli();
    UENUM = CDC_TX_ENDPOINT;

    if (transmit_previous_timeout) {
        if (!(UEINTX & (1<<RWAL))) {
            SREG = intr_state;
            return -1;
        }
        transmit_previous_timeout = 0;
    }

    timeout = UDFNUML + TRANSMIT_TIMEOUT;
    while (1) {

        if (UEINTX & (1<<RWAL)) break;
        SREG = intr_state;

        if (UDFNUML == timeout) {
            transmit_previous_timeout = 1;
            return -1;
        }

        if (!usb_configuration) return -1;

        intr_state = SREG;
        cli();
        UENUM = CDC_TX_ENDPOINT;
    }

    UEDATX = c;

    if (!(UEINTX & (1<<RWAL))) UEINTX = 0x3A;
    transmit_flush_timer = TRANSMIT_FLUSH_TIMEOUT;
    SREG = intr_state;
    return 0;
}

void usb_send_info(const char *data){
    for (int i = 0; i < strlen_P(data); i ++){
        serial_comm_transmit(pgm_read_byte(&data[i]));
    }
}

static char line1[] PROGMEM = "This is stored in flash mem";

usb_send_info(line1);
于 2018-10-25T11:05:10.217 回答