gpt4 book ai didi

c - 将数据存储在程序存储器(PROGMEM)中并通过USB串行通信发送到puTTY屏幕

转载 作者:行者123 更新时间:2023-11-30 19:29:21 25 4
gpt4 key购买 nike

我正在尝试将数据存储在 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);

这根本行不通。有什么建议或替代方案吗?干杯。

最佳答案

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);
}

关于c - 将数据存储在程序存储器(PROGMEM)中并通过USB串行通信发送到puTTY屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52983680/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com