将数据存储在程序存储器(PROGMEM)中并通过usb串行通信发送到puTTY屏幕
Posted
技术标签:
【中文标题】将数据存储在程序存储器(PROGMEM)中并通过usb串行通信发送到puTTY屏幕【英文标题】:Storing data in program memory(PROGMEM) and send it through usb serial communication to puTTY screen 【发布时间】:2018-10-25 07:28:54 【问题描述】:我正在尝试将数据存储在 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);
它只是不起作用。任何提示或替代方案? 干杯。
【问题讨论】:
对不起,我在这里错过了。问题仍然存在。 【参考方案1】: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);
【讨论】:
【参考方案2】:从朋友那里得到了一些帮助。对于任何想知道的人,这里是问题的答案。特别感谢乔纳森。
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);
【讨论】:
以上是关于将数据存储在程序存储器(PROGMEM)中并通过usb串行通信发送到puTTY屏幕的主要内容,如果未能解决你的问题,请参考以下文章
Arduino框架下ESP32/8266使用PROGMEM功能将数据存储到flash中的使用规范
如何在测量过程中将数据存储在 Keithley2400 缓冲区中并通过 rs232 检索?