Sending big array over usart

1.5k Views Asked by At

i am working with AVR controller atmega16 having 16kb of flash and 1kb of Sram.i have stored data in an static array i.e static char raw_data[15361];and trying to send it over usart using following function:

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

my issue is when ever i put my array in usart it is showing memory full. USART_SendString(raw_data);.i searched online and find out that my function is loading all of the array to RAM hence leading to an error.i found there is a way though which you can send data stored in flash over usart using PROGMEM attribute but it works only for const string type. so how should i send my data stored in flash memory over usart without leading to memory full error??

1

There are 1 best solutions below

12
On

static does not mean PROGMEM. You need to place & access them in/from the flash memory. From gcc 4.8 you can use named address spaces

 const __flash char raw_data[15361];

and

 void USART_SendString(const __flash char *str)