我正在使用具有 16kb 闪存和 1kb Sram 的 AVR 控制器 atmega16。我已将数据存储在静态数组中,即static char raw_data[15361];
并尝试使用以下功能通过 usart 发送它:
void USART_TxChar( char data) /* Data transmitting function */
{
UDR = data; /* Write data to be transmitting in UDR */
while (!(UCSRA & (1<<UDRE))); /* Wait until data transmit and buffer get empty */
}
void USART_SendString( char *str) /* Send string of USART data function */
{
int i=0;
while (str[i]!=0)
{
USART_TxChar(str[i]); /* Send each char of string till the NULL */
i++;
}
}
我的问题是,当我将数组放入 usart 时,它显示内存已满。 USART_SendString(raw_data);
.我在网上搜索,发现我的函数正在将所有数组加载到 RAM 中,因此导致错误。我发现有一种方法可以通过 usart 发送存储在闪存中的数据,PROGMEM attribute
但它仅适用于const string type
. 那么我应该如何通过usart发送存储在闪存中的数据而不会导致内存满错误?