我正在使用具有 16kb 闪存和 1kb Sram 的 AVR Controller 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,因此导致错误。我发现有一种方法可以发送存储在使用PROGMEM属性
闪过usart,但它仅适用于const字符串类型
。
那么我应该如何通过usart发送存储在闪存中的数据而不导致内存已满错误?
最佳答案
静态并不意味着PROGMEM。您需要将它们放入闪存中或从闪存中访问它们。从 gcc 4.8 开始,您可以使用命名地址空间
const __flash char raw_data[15361];
和
void USART_SendString(const __flash char *str)
关于c - 通过 usart 发送大数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46558391/