我与有AVR控制器ATmega16的Flash和Sram.i的1KB的16KB已经存储的数据在一个静态数组即static char raw_data[15361];
,并试图在USART发送使用下列函数工作:发送过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中,因此导致错误。我发现有一种方法可以使用PROGMEM attribute
将数据存储在闪存中,但它仅适用于const string type
。 所以我应该如何发送我的数据存储在闪存上方,而不会导致内存满错误?
Store中的闪光灯(PROGMEM)阵列和重写你的SendString功能'无效USART_SendString(为const char * STR)'。顺便说一句,'静态字符'并不意味着它将闪光。 – tilz0R
@ tilz0R我也试过,但它说我必须使数组'const'.which我不能因为之前发送数据通过usart我将我的传感器数据存储在该数组中。制作它const我不会能够添加值到该阵列。 –
“Skb的1kb”,然后是“static char raw_data [15361];”。您的阵列比可用RAM大15倍。这对你看起来是否正确? – Lundin