Huge Array, main no longer executes

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So I have code that has two huge (129*20*2 = 5160 Bytes each) here is how it behaves:

#1) If I comment out the arrays the program runs as expected, and prints the status of a jumper to the UART. YAY, this is good.

#3) If I uncomment the large arrays the program does nothing. This is bad, not good... horrible.

I am looking at the assembler and I don't see anything too wacky. It places all the code in close proximity, so it doesnt seem like a relative jump issue.

Any ideas you might have would be greatly appreciated.

I am using an ATMEGA324p, compiled with:
CFLAGS=-g -Os -Wall -mcall-prologues -mmcu=atmega324p

Thanks,
Sam

#define F_CPU 8000000UL
#include 
#include 
#include 
#include 
#include 
#include 

void delayms(uint16_t millis);
void process_temp(uint16_t temp);
void uart_pstr(char str[]);


int main(void) {

//  uint16_t adc0;
  char buffer[6];
  UBRR0L = 12;  					// 38400 BAUD w/ 8 MHz Clock
  UCSR0B |= (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0);
  UCSR0C |= (1<<UPM01); 				// EVEN Parity... Just for fun.
  
  DDRB &= ~(1<<DDB0);                                   // Set PORTB0 to input
  PORTB |= (1<<PORTB0);                                 // Enable PB0 pullup.

  // * Means that the defaults are fine, setting them to be anal.
  PRR0 &= ~(1 << PRADC);                                // * Disable ADC Power Reduction
  DDRA &= ~(1<<DDA0);                                   // * Make sure PORTA0 is an input.
  PORTA &= ~(1<<PORTA0);                                // * Disable internal pullup.
  ADMUX &= ~(1<<REFS0);                                 // * AREF reference.
  ADMUX &= ~(1<<REFS1);					// *  "       "
  ADCSRA |= (1<<ADPS2) | (1<<ADPS1);                    // 125000 Hz Conversion Rate.
  DIDR0 |= (1<<ADC0D);                                  // Disable Digital Input Buffer on ADC0.
  ADCSRA |= (1<<ADEN);                                  // Enable the AD Converter.

  //sei();  // Enable Global Interrupts.
  int i;
  while(1) 
  {
	  delayms(500);
  	  if ( bit_is_set(PINB, PINB0) )
		  uart_pstr("Off\n");
	  else
		  uart_pstr("On\n");
//
//	  ADCSRA |= (1<<ADSC);                          // Start a conversion.
//        loop_until_bit_is_clear(ADCSRA, ADSC);
//        adc0 = ADCW;
//	  uart_pstr( ltoa((long)adc0, buffer, 10) ); 
  }
  return 0;
}


const uint16_t scurv25[129][20] = 
{{18,9,6,4,4,3,3,2,2,2,2,2,1,1,1,1,1,1,1,1},
{23,11,7,6,5,4,3,3,3,2,2,2,2,2,2,2,1,1,1,1},
{29,14,10,7,6,5,4,4,3,3,3,3,2,2,2,2,2,2,2,2},
{37,18,12,9,7,6,5,5,4,4,4,3,3,3,3,3,2,2,2,2},
{48,23,15,12,9,8,7,6,5,5,4,4,4,4,3,3,3,3,3,3},
{61,29,19,15,12,10,8,7,7,6,6,5,5,4,4,4,4,4,3,3},
{78,37,24,18,15,12,11,9,8,8,7,6,6,6,5,5,5,4,4,4},
{100,46,30,23,18,15,13,12,10,9,9,8,7,7,7,6,6,6,5,5},
{129,58,38,28,23,19,16,14,13,12,11,10,9,9,8,8,7,7,7,6},
{165,73,48,35,28,24,20,18,16,15,13,12,11,11,10,9,9,8,8,8},
{213,92,59,44,35,29,25,22,20,18,16,15,14,13,12,12,11,10,10,9},
{275,116,74,55,44,36,31,27,24,22,20,19,17,16,15,14,13,13,12,12},
{358,145,92,68,54,45,38,34,30,27,25,23,21,20,18,17,16,16,15,14},
{469,183,114,84,66,55,47,41,37,33,30,28,26,24,23,21,20,19,18,17},
{620,230,142,103,82,68,58,51,45,41,37,34,31,29,27,26,24,23,22,21},
{831,289,177,128,100,83,71,62,55,50,45,41,38,36,33,31,30,28,27,25},
{1133,365,219,158,123,102,87,75,67,60,55,50,47,43,41,38,36,34,32,31},
{1581,463,273,194,151,124,106,92,82,73,67,61,57,53,49,46,44,41,39,37},
{2273,590,339,239,186,152,129,112,99,89,81,74,68,64,59,56,53,50,47,45},
{3387,755,423,295,228,185,157,136,120,108,98,90,83,77,72,67,64,60,57,54},
{5209,974,529,364,279,226,191,165,146,131,118,108,100,93,86,81,76,72,69,65},
{8026,1269,663,450,342,276,232,200,176,158,143,131,120,112,104,98,92,87,82,78},
{11785,1673,835,557,419,337,282,243,213,191,172,157,145,134,125,117,110,104,99,94},
{16037,2238,1057,691,515,411,343,294,258,230,207,189,174,161,150,140,132,125,118,112},
{20336,3046,1346,860,633,502,416,356,312,277,250,227,209,193,180,168,158,149,141,134},
{24438,4217,1729,1075,780,613,506,431,376,334,300,273,250,231,215,201,189,178,168,160},
{28241,5913,2242,1349,964,751,616,522,454,402,361,327,300,277,257,240,225,212,201,190},
{31716,8278,2938,1702,1195,921,750,633,548,484,433,393,359,331,307,287,269,253,239,227},
{34870,11317,3894,2163,1486,1132,915,768,662,583,521,471,430,396,367,342,320,301,284,269},
{37722,14842,5211,2770,1858,1395,1117,933,801,702,626,564,514,473,437,407,381,358,338,320},
{40294,18576,7002,3577,2335,1726,1369,1134,969,846,752,676,615,564,521,485,453,425,401,379},
{42613,22292,9340,4653,2953,2145,1681,1382,1174,1021,904,811,736,674,622,577,539,505,476,450},
{44703,25854,12199,6083,3758,2677,2072,1689,1425,1233,1088,973,881,805,741,687,640,600,564,533},
{46586,29195,15438,7945,4809,3358,2563,2069,1733,1492,1310,1168,1054,961,883,817,761,712,669,631},
{48285,32288,18859,10278,6174,4233,3183,2542,2113,1808,1580,1404,1263,1148,1053,972,904,844,792,747},
{49818,35131,22293,13038,7918,5355,3970,3134,2583,2196,1909,1689,1514,1373,1256,1158,1074,1002,939,883},
{51202,37732,25621,16106,10075,6784,4967,3877,3167,2673,2311,2035,1818,1643,1499,1379,1276,1189,1112,1045},
{52453,40106,28778,19328,12625,8567,6225,4810,3893,3261,2803,2456,2185,1968,1791,1643,1518,1411,1318,1237},
{53584,42269,31732,22566,15481,10726,7792,5976,4797,3989,3406,2969,2631,2361,2141,1959,1806,1675,1562,1464},
{54608,44238,34472,25722,18520,13229,9699,7420,5918,4888,4148,3597,3172,2836,2564,2339,2151,1991,1853,1733},
{55536,46030,37000,28734,21618,16000,11944,9174,7296,5994,5058,4363,3831,3411,3073,2795,2563,2367,2199,2053},
{56377,47662,39324,31572,24679,18930,14483,11248,8962,7343,6171,5298,4631,4107,3687,3343,3058,2817,2611,2433},
{57140,49147,41455,34220,27633,21914,17232,13615,10929,8964,7518,6433,5601,4950,4428,4003,3650,3354,3102,2885},
{57833,50499,43409,36676,30442,24866,20097,16213,13180,10870,9125,7796,6771,5965,5320,4795,4361,3997,3688,3422},
{58464,51731,45197,38947,33084,27724,22988,18960,15664,13047,11002,9411,8166,7180,6388,5743,5210,4764,4386,4062},
{59037,52855,46833,41040,35551,30451,25831,21770,18312,15452,13137,11284,9805,8618,7658,6872,6222,5677,5216,4821},
{59559,53879,48330,42966,37843,33025,28579,24569,21044,18023,15491,13401,11691,10294,9149,8204,7419,6758,6199,5720},
{60035,54814,49700,44736,39967,35437,31199,27301,23788,20688,18005,15724,13806,12204,10870,9755,8819,8028,7356,6779},
{60469,55668,50954,46363,41929,37686,33673,29928,26487,23377,20614,18198,16113,14330,12814,11527,10434,9502,8704,8016},
{60866,56449,52102,47856,43739,39776,35995,32427,29098,26034,23253,20762,18560,16632,14958,13511,12263,11186,10254,9446},
{61228,57162,53153,49228,45407,41712,38164,34784,31595,28617,25867,23355,21088,19060,17262,15678,14289,13072,12008,11075},
{61559,57816,54117,50488,46944,43504,40182,36995,33962,31096,28414,25926,23640,21558,19676,17988,16481,15141,13952,12899},
{61862,58414,55001,51645,48360,45159,42056,39062,36190,33455,30866,28435,26169,24072,22147,20390,18796,17357,16062,14899},
{62139,58962,55811,52708,49663,46688,43792,40986,38280,35683,33204,30853,28637,26560,24626,22836,21188,19678,18300,17046},
{62393,59465,56556,53685,50863,48099,45400,42775,40232,37777,35418,33163,31017,28986,27073,25280,23609,22057,20623,19301},
{62626,59926,57239,54583,51968,49401,46888,44436,42050,39738,37504,35354,33293,31326,29456,27686,26018,24452,22988,21622},
{62840,60349,57867,55409,52986,50602,48263,45975,43742,41569,39460,37420,35453,33563,31752,30025,28382,26825,25354,23969},
{63036,60738,58444,56170,53923,51710,49535,47401,45313,43275,41290,39361,37493,35687,33947,32276,30674,29145,27688,26304},
{63216,61096,58975,56870,54787,52733,50710,48722,46772,44863,42998,41180,39411,37695,36032,34426,32878,31390,29963,28597},
{63382,61424,59464,57514,55584,53677,51796,49944,48124,46338,44590,42879,41210,39584,38003,36468,34982,33546,32160,30825},
{63534,61727,59914,58109,56319,54548,52799,51075,49378,47709,46071,44465,42893,41357,39859,38399,36979,35601,34265,32972},
{63675,62006,60328,58657,56997,55353,53727,52122,50539,48981,47448,45942,44465,43018,41601,40218,38867,37551,36270,35025},
{63804,62263,60711,59162,57622,56096,54585,53091,51616,50161,48728,47318,45931,44570,43234,41926,40645,39393,38171,36979},
{63923,62499,61063,59628,58200,56783,55378,53988,52614,51256,49917,48597,47297,46018,44761,43527,42316,41129,39967,38830},
{64032,62718,61389,60059,58734,57418,56112,54818,53538,52272,51021,49787,48569,47369,46188,45025,43882,42760,41658,40578},
{64134,62919,61689,60457,59228,58005,56791,55587,54395,53214,52046,50892,49753,48628,47519,46426,45349,44290,43248,42224},
{64227,63105,61966,60824,59684,58548,57420,56300,55189,54088,52998,51920,50854,49800,48760,47733,46720,45722,44739,43771},
{64313,63277,62223,61164,60106,59051,58002,56960,55925,54899,53882,52875,51878,50892,49917,48953,48002,47062,46135,45221},
{64393,63436,62460,61478,60496,59516,58541,57571,56608,55651,54702,53762,52830,51907,50994,50091,49197,48314,47442,46581},
{64466,63583,62679,61769,60857,59947,59041,58138,57241,56349,55464,54586,53716,52853,51998,51151,50313,49484,48664,47853},
{64534,63718,62882,62038,61192,60347,59504,58664,57828,56997,56172,55352,54539,53732,52932,52139,51354,50576,49805,49043},
{64597,63844,63070,62288,61502,60717,59933,59151,58373,57599,56829,56064,55305,54551,53802,53060,52324,51594,50871,50154},
{64655,63960,63244,62518,61790,61060,60331,59604,58879,58158,57440,56726,56017,55312,54612,53918,53228,52544,51866,51193},
{64708,64068,63405,62732,62056,61378,60700,60024,59349,58677,58007,57342,56679,56021,55367,54717,54071,53430,52794,52163},
{64758,64168,63554,62931,62303,61673,61043,60413,59785,59159,58535,57914,57295,56680,56069,55461,54857,54257,53661,53069},
{64804,64260,63692,63115,62532,61947,61361,60775,60191,59607,59025,58446,57869,57294,56723,56154,55589,55027,54469,53914},
{64847,64345,63821,63286,62745,62202,61657,61112,60567,60024,59481,58941,58402,57866,57332,56800,56272,55746,55223,54703},
{64886,64425,63940,63444,62942,62438,61931,61424,60917,60411,59905,59401,58899,58398,57899,57402,56908,56415,55926,55439},
{64923,64498,64050,63591,63126,62657,62186,61715,61243,60771,60300,59830,59361,58893,58427,57963,57501,57040,56582,56126},
{64956,64567,64153,63728,63296,62861,62423,61985,61545,61106,60667,60229,59791,59355,58919,58486,58053,57623,57194,56767},
{64988,64630,64248,63854,63454,63050,62644,62236,61827,61418,61009,60600,60192,59784,59378,58973,58569,58166,57765,57365},
{65017,64689,64336,63972,63601,63226,62849,62469,62089,61708,61327,60946,60565,60185,59805,59427,59049,58673,58297,57923},
{65044,64743,64418,64081,63738,63390,63039,62687,62333,61978,61623,61268,60913,60558,60204,59850,59497,59146,58794,58444},
{65069,64794,64494,64183,63865,63542,63217,62889,62560,62229,61899,61568,61237,60906,60575,60245,59916,59587,59258,58931},
{65092,64840,64565,64278,63983,63684,63382,63077,62771,62464,62156,61847,61539,61230,60922,60613,60305,59998,59691,59385},
{65113,64884,64631,64365,64093,63816,63535,63252,62968,62682,62395,62108,61820,61532,61244,60957,60669,60382,60095,59809},
{65133,64924,64692,64447,64195,63938,63678,63415,63151,62885,62618,62350,62082,61814,61546,61277,61009,60740,60473,60205},
{65151,64962,64749,64523,64290,64052,63811,63567,63322,63074,62826,62577,62327,62077,61827,61576,61326,61075,60825,60575},
{65168,64997,64801,64594,64379,64159,63935,63709,63481,63251,63020,62788,62555,62322,62089,61855,61621,61387,61154,60920},
{65184,65029,64850,64659,64461,64258,64050,63841,63629,63415,63200,62985,62768,62551,62333,62115,61897,61679,61461,61242},
{65199,65059,64896,64721,64538,64350,64158,63963,63767,63568,63369,63168,62966,62764,62561,62358,62155,61951,61747,61544},
{65212,65087,64938,64777,64609,64435,64258,64078,63896,63711,63526,63339,63152,62963,62775,62585,62395,62205,62015,61825},
{65225,65113,64978,64830,64675,64515,64351,64185,64016,63845,63672,63499,63324,63149,62973,62797,62620,62443,62265,62088},
{65236,65137,65014,64879,64737,64590,64438,64284,64127,63969,63809,63648,63486,63323,63159,62995,62830,62665,62499,62334},
{65247,65159,65048,64925,64795,64659,64519,64377,64232,64085,63936,63787,63636,63485,63332,63179,63026,62872,62718,62563},
{65257,65180,65080,64968,64848,64723,64595,64463,64329,64193,64055,63917,63777,63636,63494,63352,63209,63066,62922,62778},
{65266,65199,65109,65007,64898,64783,64665,64543,64420,64294,64166,64038,63908,63777,63645,63513,63380,63246,63112,62978},
{65274,65217,65137,65044,64944,64839,64730,64618,64504,64388,64270,64151,64030,63909,63786,63663,63540,63415,63291,63166},
{65282,65233,65162,65078,64988,64891,64791,64688,64583,64476,64366,64256,64144,64032,63918,63804,63689,63573,63457,63341},
{65289,65249,65185,65110,65028,64940,64848,64754,64656,64557,64457,64354,64251,64147,64041,63935,63828,63721,63613,63505},
{65296,65263,65207,65140,65065,64985,64901,64814,64725,64634,64541,64446,64351,64254,64156,64058,63959,63859,63759,63658},
{65302,65276,65228,65167,65100,65027,64951,64871,64789,64705,64619,64532,64443,64354,64264,64172,64080,63988,63895,63801},
{65307,65288,65246,65193,65132,65066,64997,64924,64849,64771,64692,64612,64530,64448,64364,64279,64194,64108,64022,63935},
{65312,65299,65264,65217,65162,65103,65039,64973,64904,64833,64761,64687,64611,64535,64458,64379,64300,64221,64141,64060},
{65317,65310,65280,65239,65190,65137,65079,65019,64956,64891,64824,64756,64687,64616,64545,64473,64400,64326,64252,64177},
{65321,65319,65295,65259,65216,65168,65116,65062,65004,64945,64884,64821,64757,64693,64627,64560,64492,64424,64355,64286},
{65325,65328,65309,65278,65240,65198,65151,65101,65049,64995,64939,64882,64823,64764,64703,64642,64579,64516,64453,64388},
{65329,65336,65322,65296,65263,65225,65183,65138,65091,65042,64991,64939,64885,64830,64774,64718,64660,64602,64543,64484},
{65332,65344,65334,65312,65284,65250,65213,65173,65130,65086,65039,64991,64942,64892,64841,64789,64736,64682,64628,64573},
{65335,65351,65344,65327,65303,65274,65241,65205,65167,65126,65084,65041,64996,64950,64903,64855,64807,64757,64707,64657},
{65338,65357,65355,65341,65321,65296,65267,65235,65200,65164,65126,65087,65046,65004,64961,64917,64873,64827,64781,64735},
{65340,65363,65364,65354,65338,65316,65291,65263,65232,65199,65165,65129,65092,65054,65015,64975,64934,64893,64851,64808},
{65342,65368,65373,65366,65353,65335,65313,65288,65261,65232,65202,65169,65136,65101,65066,65029,64992,64954,64915,64876},
{65344,65373,65381,65377,65367,65353,65334,65313,65289,65263,65235,65207,65176,65145,65113,65080,65046,65011,64976,64940},
{65346,65377,65388,65388,65381,65369,65353,65335,65314,65291,65267,65241,65214,65186,65157,65127,65096,65064,65032,64999},
{65347,65381,65395,65397,65393,65384,65371,65356,65338,65318,65296,65273,65249,65224,65198,65171,65143,65114,65085,65055},
{65349,65385,65401,65406,65404,65398,65388,65375,65360,65343,65324,65304,65282,65260,65236,65212,65186,65161,65134,65107},
{65350,65388,65406,65414,65415,65411,65403,65393,65380,65365,65349,65332,65313,65293,65272,65250,65227,65204,65180,65155},
{65351,65391,65411,65421,65424,65423,65417,65409,65399,65387,65373,65358,65341,65323,65305,65285,65265,65244,65223,65200},
{65352,65394,65416,65428,65433,65434,65430,65425,65417,65406,65395,65382,65368,65352,65336,65319,65301,65282,65263,65243},
{65353,65396,65420,65434,65441,65444,65443,65439,65433,65425,65415,65404,65392,65379,65365,65350,65334,65317,65300,65282},
{65353,65399,65424,65440,65449,65453,65454,65452,65448,65442,65434,65425,65415,65404,65391,65378,65365,65350,65335,65319},
{65354,65400,65428,65445,65455,65462,65464,65464,65462,65458,65452,65445,65436,65427,65416,65405,65393,65380,65367,65353},
{65354,65402,65431,65449,65462,65469,65474,65475,65475,65472,65468,65463,65456,65448,65440,65430,65420,65409,65397,65385},
{65354,65404,65434,65454,65467,65477,65483,65486,65487,65486,65483,65479,65474,65468,65461,65453,65445,65435,65425,65415},
{65355,65405,65436,65458,65473,65483,65491,65495,65498,65498,65497,65495,65491,65487,65481,65475,65468,65460,65452,65443},
{65355,65406,65438,65461,65477,65489,65498,65504,65508,65510,65510,65509,65507,65504,65500,65495,65489,65483,65476,65468},
{65355,65407,65440,65464,65482,65495,65505,65512,65517,65520,65522,65522,65522,65520,65517,65513,65509,65504,65498,65492},
{65355,65408,65442,65467,65486,65500,65511,65519,65526,65530,65533,65535,65535,65534,65533,65531,65528,65524,65519,65515}};


const uint16_t scurv30[129][20] = 
{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{2,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{2,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0},
{3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{4,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{5,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{8,3,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{11,4,3,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{17,5,3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
{27,6,4,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1},
{52,8,5,4,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2},
{134,11,6,5,4,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2},
{897,15,8,6,5,4,4,3,3,3,3,3,3,3,2,2,2,2,2,2},
{5726,21,10,7,6,5,4,4,4,4,3,3,3,3,3,3,3,3,3,3},
{11498,30,13,9,7,6,5,5,4,4,4,4,4,3,3,3,3,3,3,3},
{16796,46,17,11,9,7,6,6,5,5,5,4,4,4,4,4,4,4,4,3},
{21556,77,23,15,11,9,8,7,6,6,6,5,5,5,5,4,4,4,4,4},
{25812,153,32,19,14,11,10,8,8,7,7,6,6,6,5,5,5,5,5,5},
{29617,455,46,25,17,14,12,10,9,8,8,7,7,7,6,6,6,6,6,5},
{33019,2573,69,33,22,17,14,13,11,10,9,9,8,8,8,7,7,7,7,6},
{36064,7516,113,45,29,22,18,15,14,12,11,10,10,9,9,9,8,8,8,7},
{38792,12645,213,63,38,28,22,19,17,15,14,13,12,11,11,10,10,9,9,9},
{41238,17391,549,94,51,36,28,23,20,18,16,15,14,13,12,12,11,11,10,10},
{43435,21703,2290,151,70,47,36,29,25,22,20,18,17,16,15,14,13,13,12,12},
{45410,25601,6625,277,101,62,46,37,31,27,24,22,20,19,18,17,16,15,15,14},
{47187,29121,11469,660,155,85,60,47,39,33,30,27,24,23,21,20,19,18,17,16},
{48788,32299,16052,2290,261,122,80,60,49,42,36,33,30,27,25,24,22,21,20,19},
{50233,35170,20261,6239,528,185,110,79,63,52,45,40,36,33,31,29,27,25,24,23},
{51538,37766,24095,10848,1446,307,159,107,82,67,57,50,44,40,37,34,32,30,29,27},
{52718,40115,27580,15285,4322,599,243,150,109,86,72,62,55,49,45,42,39,36,34,33},
{53785,42242,30744,19395,8603,1513,411,219,149,114,92,78,68,61,55,51,47,44,41,39},
{54753,44170,33617,23163,12997,4179,821,346,213,154,121,101,86,76,68,62,57,53,50,47},
{55631,45921,36228,26603,17148,8247,2067,614,323,216,163,131,111,96,85,77,70,65,60,56},
{56428,47510,38602,29740,20987,12514,5063,1313,537,320,227,176,144,123,107,96,86,79,73,68},
{57153,48956,40761,32600,24512,16585,9099,3255,1035,513,331,243,193,160,137,121,108,98,90,83},
{57813,50272,42728,35208,27738,20370,13231,6742,2375,930,518,352,266,214,179,155,137,123,111,102},
{58413,51471,44521,37587,30689,23859,17162,10771,5246,1981,905,544,383,294,239,202,175,155,140,127},
{58961,52564,46156,39759,33387,27063,20823,14749,9056,4384,1830,930,588,424,330,271,230,200,178,160},
{59461,53562,47650,41743,35855,30000,24203,18506,13004,7940,3953,1819,995,652,477,376,310,264,230,204},
{59918,54474,49015,43557,38113,32693,27313,21998,16797,11811,7292,3811,1905,1099,736,546,432,357,304,266},
{60336,55308,50263,45218,40181,35162,30172,25226,20351,15598,11070,7005,3877,2078,1245,848,632,502,415,354},
{60719,56072,51406,46738,42076,37426,32797,28200,23650,19175,14824,10696,6999,4111,2338,1444,994,743,590,487},
{61069,56772,52454,48132,43813,39503,35209,30938,26699,22510,18395,14403,10620,7219,4493,2697,1709,1184,886,701},
{61391,57414,53415,49411,45407,41411,37425,33456,29512,25600,21738,17949,14274,10788,7628,5016,3169,2060,1435,1071},
{61686,58003,54297,50585,46872,43163,39462,35774,32104,28457,24844,21278,17781,14388,11159,8201,5677,3770,2519,1767},
{61957,58544,55108,51663,48217,44774,41336,37908,34493,31095,27721,24378,21081,17846,14703,11700,8916,6471,4509,3111},
{62206,59042,55853,52656,49455,46256,43061,39873,36694,33529,30380,27255,24159,21104,18106,15187,12385,9757,7389,5392},
{62436,59500,56539,53569,50595,47621,44650,41683,38724,35775,32838,29918,27020,24148,21314,18529,15812,13190,10706,8419},
{62647,59922,57171,54410,51645,48879,46114,43353,40597,37848,35109,32383,29671,26980,24313,21679,19088,16553,14096,11747},
{62842,60311,57754,55186,52613,50039,47465,44893,42325,39763,37208,34662,32128,29608,27106,24626,22174,19759,17392,15087},
{63021,60670,58291,55902,53507,51109,48711,46315,43921,41531,39147,36770,34402,32044,29700,27371,25062,22778,20524,18309},
{63187,61001,58788,56563,54332,52098,49863,47628,45396,43166,40941,38721,36508,34303,32107,29923,27754,25601,23470,21364},
{63340,61307,59247,57174,55094,53011,50927,48843,46760,44679,42601,40527,38458,36395,34340,32294,30258,28234,26226,24235},
{63482,61590,59671,57739,55799,53857,51912,49966,48022,46078,44137,42199,40265,38335,36411,34494,32585,30685,28796,26920},
{63613,61852,60063,58261,56452,54639,52823,51007,49190,47374,45560,43748,41939,40134,38333,36537,34747,32965,31190,29425},
{63735,62095,60427,58746,57057,55364,53668,51970,50273,48575,46879,45184,43492,41802,40116,38434,36756,35084,33418,31759},
{63847,62320,60764,59195,57617,56035,54451,52864,51277,49689,48102,46517,44933,43351,41771,40195,38622,37054,35490,33932},
{63952,62529,61077,59611,58137,56659,55177,53693,52208,50723,49238,47753,46270,44788,43309,41831,40357,38886,37418,35955},
{64049,62722,61367,59997,58620,57237,55851,54463,53073,51683,50292,48902,47513,46124,44737,43352,41970,40589,39212,37838},
{64139,62902,61636,60356,59068,57775,56477,55178,53877,52574,51272,49969,48667,47366,46066,44767,43470,42174,40881,39591},
{64223,63069,61887,60690,59485,58274,57060,55843,54624,53404,52183,50962,49741,48521,47301,46083,44866,43650,42436,41224},
{64300,63225,62120,61001,59873,58739,57601,56461,55319,54175,53031,51886,50741,49596,48452,47308,46165,45024,43884,42745},
{64373,63370,62337,61290,60233,59172,58106,57037,55966,54893,53820,52746,51671,50597,49523,48449,47376,46304,45233,44163},
{64440,63504,62539,61559,60570,59575,58575,57573,56569,55563,54555,53547,52539,51530,50521,49513,48505,47497,46491,45485},
{64503,63630,62727,61809,60883,59950,59013,58073,57130,56186,55241,54294,53347,52400,51452,50505,49557,48610,47664,46718},
{64562,63747,62903,62043,61175,60300,59421,58539,57655,56768,55880,54991,54101,53211,52321,51430,50539,49649,48759,47870},
{64617,63856,63067,62262,61448,60627,59802,58974,58144,57311,56477,55642,54805,53969,53131,52294,51457,50619,49782,48945},
{64668,63959,63220,62465,61702,60933,60158,59381,58600,57818,57034,56249,55463,54676,53889,53101,52313,51525,50737,49950},
{64715,64054,63362,62656,61940,61218,60491,59760,59027,58292,57555,56817,56078,55338,54597,53856,53114,52372,51631,50889},
{64760,64143,63496,62834,62162,61484,60802,60115,59426,58735,58042,57348,56652,55956,55259,54561,53863,53165,52466,51768},
{64802,64226,63621,63001,62370,61734,61093,60448,59800,59150,58498,57845,57190,56535,55878,55221,54564,53906,53248,52590},
{64841,64305,63738,63156,62565,61967,61365,60758,60149,59538,58924,58310,57693,57076,56458,55840,55220,54601,53981,53360},
{64877,64378,63848,63302,62748,62186,61620,61050,60477,59901,59324,58745,58165,57584,57002,56419,55835,55251,54667,54082},
{64912,64446,63950,63439,62918,62391,61859,61323,60784,60242,59699,59153,58607,58059,57511,56962,56411,55861,55310,54759},
{64944,64510,64047,63568,63079,62583,62083,61578,61071,60561,60050,59536,59021,58505,57988,57471,56952,56433,55913,55393},
{64974,64571,64137,63688,63229,62763,62293,61819,61341,60861,60379,59895,59410,58924,58437,57948,57459,56970,56479,55989},
{65002,64627,64222,63801,63370,62933,62490,62044,61594,61143,60688,60233,59775,59317,58857,58397,57935,57473,57011,56548},
{65029,64680,64301,63907,63503,63092,62676,62256,61832,61407,60979,60549,60118,59686,59252,58818,58383,57947,57510,57073},
{65054,64730,64376,64007,63627,63241,62850,62454,62056,61655,61252,60847,60441,60033,59624,59214,58803,58392,57979,57567},
{65077,64777,64446,64100,63744,63381,63013,62641,62266,61889,61509,61127,60744,60359,59973,59586,59198,58810,58421,58031},
{65099,64821,64513,64188,63854,63513,63167,62817,62464,62108,61750,61390,61029,60666,60302,59936,59570,59203,58836,58468},
{65120,64863,64575,64271,63958,63638,63312,62983,62650,62315,61977,61638,61297,60954,60611,60266,59920,59574,59227,58879},
{65139,64902,64633,64349,64055,63755,63449,63139,62825,62509,62191,61871,61549,61226,60902,60576,60250,59923,59595,59266},
{65158,64938,64688,64423,64147,63865,63577,63285,62990,62693,62393,62091,61787,61482,61176,60869,60561,60251,59941,59631},
{65175,64973,64740,64492,64234,63969,63698,63424,63146,62866,62583,62298,62012,61724,61435,61145,60853,60561,60268,59975},
{65191,65006,64789,64557,64316,64067,63813,63554,63293,63029,62762,62493,62223,61952,61679,61405,61129,60853,60577,60299},
{65207,65036,64836,64619,64393,64159,63920,63677,63431,63182,62931,62678,62423,62166,61909,61650,61390,61129,60867,60605},
{65221,65066,64879,64677,64465,64246,64022,63794,63562,63327,63090,62852,62611,62369,62126,61881,61636,61389,61142,60894},
{65235,65093,64920,64732,64534,64328,64118,63903,63685,63464,63241,63016,62789,62561,62331,62100,61868,61635,61401,61167},
{65248,65119,64959,64784,64599,64406,64209,64007,63802,63594,63383,63171,62957,62741,62525,62306,62087,61867,61646,61424},
{65260,65143,64996,64833,64660,64480,64294,64105,63912,63716,63518,63318,63116,62912,62708,62502,62295,62087,61878,61668},
{65271,65166,65031,64879,64718,64549,64375,64197,64016,63832,63645,63456,63266,63074,62881,62686,62491,62294,62097,61898},
{65282,65188,65063,64923,64772,64615,64452,64285,64114,63941,63765,63587,63408,63227,63044,62861,62676,62490,62304,62116},
{65293,65209,65095,64964,64824,64677,64524,64367,64207,64044,63879,63711,63542,63372,63199,63026,62852,62676,62500,62322},
{65302,65228,65124,65003,64873,64736,64593,64446,64295,64142,63987,63829,63669,63508,63346,63182,63018,62852,62685,62518},
{65312,65247,65152,65041,64919,64791,64658,64520,64379,64235,64089,63940,63790,63638,63485,63331,63175,63018,62861,62703},
{65320,65264,65178,65076,64963,64844,64719,64590,64458,64323,64185,64045,63904,63761,63617,63471,63324,63176,63027,62878},
{65328,65281,65203,65109,65005,64894,64777,64657,64533,64406,64277,64145,64012,63877,63741,63604,63465,63326,63185,63044},
{65336,65297,65226,65140,65044,64941,64833,64720,64604,64485,64363,64240,64115,63988,63859,63730,63599,63467,63335,63201},
{65344,65312,65249,65170,65082,64986,64885,64780,64671,64560,64446,64330,64212,64092,63972,63850,63726,63602,63477,63351},
{65351,65326,65270,65199,65117,65029,64935,64837,64735,64631,64524,64415,64304,64192,64078,63963,63847,63730,63611,63492},
{65357,65339,65290,65225,65151,65069,64982,64890,64796,64698,64598,64496,64392,64286,64179,64071,63961,63851,63739,63627},
{65363,65352,65309,65251,65183,65107,65026,64942,64853,64762,64668,64572,64475,64376,64275,64173,64070,63966,63860,63754},
{65369,65364,65327,65275,65213,65144,65069,64990,64908,64823,64735,64645,64554,64460,64366,64270,64173,64075,63976,63876},
{65375,65375,65344,65298,65242,65178,65109,65036,64960,64880,64798,64714,64629,64541,64452,64362,64271,64179,64085,63991},
{65380,65386,65361,65320,65269,65211,65147,65080,65009,64935,64859,64780,64700,64618,64535,64450,64364,64277,64189,64101},
{65385,65396,65376,65340,65295,65242,65184,65121,65056,64987,64916,64843,64767,64691,64613,64533,64453,64371,64288,64205},
{65390,65406,65391,65360,65319,65272,65218,65161,65100,65036,64970,64902,64832,64760,64687,64612,64537,64460,64382,64304},
{65395,65415,65405,65379,65343,65300,65251,65199,65142,65083,65022,64958,64893,64826,64758,64688,64617,64545,64472,64398},
{65399,65424,65418,65396,65365,65326,65282,65234,65183,65128,65071,65012,64951,64889,64825,64759,64693,64625,64557,64487},
{65403,65432,65430,65413,65386,65352,65312,65268,65221,65171,65118,65063,65007,64948,64889,64828,64765,64702,64638,64573},
{65407,65440,65442,65429,65406,65376,65340,65301,65257,65211,65163,65112,65059,65005,64950,64893,64834,64775,64715,64654},
{65410,65447,65454,65444,65425,65399,65367,65331,65292,65250,65205,65158,65109,65059,65007,64954,64900,64845,64789,64731},
{65414,65454,65464,65459,65443,65421,65393,65360,65325,65286,65245,65202,65157,65111,65063,65013,64963,64911,64858,64805},
{65417,65461,65475,65473,65461,65441,65417,65388,65356,65321,65284,65244,65203,65160,65115,65069,65022,64974,64925,64875},
{65420,65467,65484,65486,65477,65461,65440,65415,65386,65354,65320,65284,65246,65206,65165,65123,65079,65034,64989,64942},
{65423,65473,65494,65498,65493,65480,65462,65440,65414,65386,65355,65322,65287,65251,65213,65174,65133,65092,65049,65006},
{65426,65479,65502,65510,65507,65498,65483,65464,65442,65416,65388,65358,65327,65293,65258,65222,65185,65146,65107,65066},
{65428,65485,65511,65521,65522,65515,65503,65487,65467,65445,65420,65393,65364,65334,65302,65268,65234,65198,65162,65124},
{65431,65490,65519,65532,65535,65531,65522,65509,65492,65472,65450,65426,65400,65372,65343,65312,65281,65248,65214,65179}};

void delayms(uint16_t millis) 
{
//  uint16_t loop;
  while ( millis ) 
  {
    _delay_ms(1);
    millis--;
  }
}


void uart_pstr(char str[])
{
	unsigned int i = 0;
	size_t n = strlen(str);
	while ( i < (n + 1) )
	{
		loop_until_bit_is_set(UCSR0A, UDRE0);
		UDR0 = str[i++];
	}
}

void process_temp(uint16_t temp)
{
#if 0
	char numbuffer[6];
	int dindex = ((temp & 0xFE00) >> 9);
	int offset = (temp & 0x01FF);
	unsigned long add;
	uint16_t conc, res;
        
	ADCSRA |= (1<<ADSC);                          // Start a conversion.
        loop_until_bit_is_clear(ADCSRA, ADSC);
        conc = ADCW;				      // ADC selected concentration.
	
	add = (unsigned long)offset;
	if ( bit_is_set(PINB, PINB0) )		      // Jumper selects gas.
	{
		add *= (scurv30[dindex+1][0] - scurv30[dindex][0]);
		res = scurv30[dindex][0];
	}
	else
	{
		add *= (scurv25[dindex+1] - scurv25[dindex]);
		res = scurv25[dindex][0];
	}

	res += (uint16_t)(add/512);
	uart_pstr( ltoa((long)res, numbuffer, 10) );
#endif
}

ISR(USART0_RX_vect)
{
	static char buffer[6];  //enough for 65535 + NULL terminator.
	static unsigned char i = 0;
	uint16_t temp;

	buffer[i] = UDR0;
	if ( (buffer[i] == 0) || (buffer[i] == 13) )
	{	
		cli(); // Disable interrupts.  Brains shouldnt be sending anything anyways.
		buffer[i] = 0;
		temp = atoi(buffer);
		process_temp(temp);
		buffer[0] = UDR0; // If something was sent, discard it.  
		sei(); // Enable interrupts.
		i = 0;
	}
	else if (i == 5)
		i = 0;
	else
		i++;
}



  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your huge arrays must be in flash. Read here:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38003
/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From what I can see of the the 324 it only has 2048 bytes of ram, and you're trying to fit over 5000 bytes into it....

Edward

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon++;

Worked like a charm, thanks so much.

Makes a lot of sense too. Still it is strange that const doesnt do that for you. Hrmm, live and learn :)

Lajon wrote:
Your huge arrays must be in flash. Read here:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38003
/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

swinchen wrote:
Makes a lot of sense too. Still it is strange that const doesnt do that for you. Hrmm, live and learn :)

In some AVR specific compilers it is the case that 'const' puts data into code flash and any access to it then has "hidden" LPM code generated. But GCC is a multi-architecture compiler and it is not so hot on Harvard architecture (multiple memory space) processors - hence the need for the avr/pgmspace.h helper functions to assist the AVR version.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Specifically, the keyword "const" tells the compiler that the object is read-only, that the object will not be modified. That does NOT mean that the data should be automatically placed into the Program Memory (Flash). C Language was designed for Von Neumann architectures where there is only a single address space. It was not designed for Harvard Architecture processors with separate address spaces. There is some work going on with the standard to help introduce constructs to help with Harvard Architecture devices, but I have no idea what that schedule is, or when GCC will ever be modified to do this.

So, as Cliff said, there are some compilers that have overloaded the meaning of the keyword "const" to put the data in the Program Space, but strictly speaking this is against the C Standard. GCC has a tendency to more strictly adhere to the Standard.

Eric