Arduino Polska Forum

Pełna wersja: Zawieszanie wyświetlacza OLED
Aktualnie przeglądasz uproszczoną wersję forum. Kliknij tutaj, by zobaczyć wersję z pełnym formatowaniem.
Stron: 1 2 3 4 5 6 7 8
Ale on działa, tylko się zawiesza - to jest dziwne , kod jest przecież dobry - jeszcze sprawdzę zużycie pamięci według kodów "es2".
(26-10-2018, 16:53)Automatyk231 napisał(a): [ -> ]jeszcze sprawdzę zużycie pamięci według kodów "es2".

Jaksie okaże, że RAM nie brakuje, to zaczną się problemy. Bez debugera może być problem.
Najpierw muszę dojść dlaczego wyskakuje mi błąd przy tym RAM'ie Big Grin Nie poradzę sobie z tym RAM'em - na internecie brak wiadomości w ogóle o takich błędach. No cóż - widocznie za mało wiem aby móc to naprawić. Dzięki wszystkim za zainteresowanie Smile
Znalazłem kiedyś dwa przykłady jak sprawdzić wolny RAM, zapisałem sobie "na kiedyś", na razie nie miałem potrzeby testować. Możesz sobie sprawdzić:
Kod:
size_t freeRam ()
 {
 return RAMEND - size_t (__malloc_heap_start);
 } // end of freeRam

void setup ()
 {
 Serial.begin (115200);
 Serial.println ();

 Serial.print (F("Free memory = "));
 Serial.println (freeRam ());
 }  // end of setup

void loop () { }




/* This function places the current value of the heap and stack pointers in the
* variables. You can call it from any place in your code and save the data for
* outputting or displaying later. This allows you to check at different parts of
* your program flow.
* The stack pointer starts at the top of RAM and grows downwards. The heap pointer
* starts just above the static variables etc. and grows upwards. SP should always
* be larger than HP or you'll be in big trouble! The smaller the gap, the more
* careful you need to be. Julian Gall 6-Feb-2009.
*/
/*
void check_mem() {
 //uint8_t * heapptr, * stackptr;  // I declared these globally
 stackptr = (uint8_t *)malloc(4);  // use stackptr temporarily
 heapptr = stackptr;                  // save value of heap pointer
 free(stackptr);                        // free up the memory again (sets stackptr to 0)
 stackptr =  (uint8_t *)(SP);       // save value of stack pointer
 }

check_mem(); // heappstr, stackptr have been declared (as  uint8_t * heapptr, * stackptr;)
Serial.print(" heapptr: "); Serial.println(*heapptr);
Serial.print("stackptr: "); Serial.println(*stackptr);
Serial.println ((int) heapptr);


*/
Cytat:Znalazłem kiedyś dwa przykłady jak sprawdzić wolny RAM, zapisałem sobie "na kiedyś", na razie nie miałem potrzeby testować. Możesz sobie sprawdzić:
kaczakat czy do tych kodów nie należy użyć żadnych bibliotek? Pierwszy kod w zasadzie nie wyświetla mi nic (jeden znak zapytania jedynie). A z drugim jest problem z kompilacją.
(26-10-2018, 16:27)Automatyk231 napisał(a): [ -> ]błąd przy kompilacji : expected initializer before 'NOINIT' (niewiem co on znaczy Big Grin )

Przed użyciem NOINIT dopisz
Kod:
#define NOINIT __attribute__ ((section(".noinit")))
albo zastąp NOINIT przez "__attribute__ ((section(".noinit")))"

Ciesz się, ze to nie ARM, tam musiałbyś kombinować jeszcze w opcjach kompilatora.
Kod działa prawidłowo, jak czegoś nie wyświetlał to pewnie źle ustawiłeś baudrate w oknie terminala. Nic nie trzeba instalować dodatkowo, a jak użyjesz i co zobaczysz  oraz jakie wyciągniesz wnioski to już zależy od Ciebie. Te funkcje z komentarzy wymagały rozpisania kodu zgodnie z opisem. Na pewno działają na AVR (NANO, UNO, itp), nie potrzebują bibliotek.
Inaczej użyte:
Kod:
uint8_t * heapptr, * stackptr;
size_t freeRam ()
  {
  return RAMEND - size_t (__malloc_heap_start);
  } // end of freeRam

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  Serial.print (F("Free memory = "));
  Serial.println (freeRam ());
  }  // end of setup

void loop () {
  
    Serial.print (("Free memory = "));
  Serial.println (freeRam ());

  
  check_mem(); // heappstr, stackptr have been declared (as  uint8_t * heapptr, * stackptr;)
 Serial.print(" heapptr: "); Serial.println((int) heapptr);
Serial.print("stackptr: "); Serial.println((int) stackptr);
Serial.println ((int) stackptr-(int) heapptr);
 Serial.println();

  Serial.println( jakies_obliczenia(12));
 Serial.print(" heapptr: "); Serial.println((int) heapptr);
Serial.print("stackptr: "); Serial.println((int) stackptr);
Serial.println ((int) stackptr- (int) heapptr);
   delay(1000);

  }

uint32_t jakies_obliczenia(uint32_t sumka)
{
    Serial.println(F("Dane ze srodka funkcji"));
  Serial.print(F("Free RAM:"));
  uint32_t dana1=56, dana2=234234, dana4;
  uint32_t cosik=freeRam();
  dana4=dana1*dana2+sumka;
  check_mem();
  dana1=dana4-dana2;
  return cosik;
  
  
}

/* This function places the current value of the heap and stack pointers in the
* variables. You can call it from any place in your code and save the data for
* outputting or displaying later. This allows you to check at different parts of
* your program flow.
* The stack pointer starts at the top of RAM and grows downwards. The heap pointer
* starts just above the static variables etc. and grows upwards. SP should always
* be larger than HP or you'll be in big trouble! The smaller the gap, the more
* careful you need to be. Julian Gall 6-Feb-2009.
*/
 
void check_mem() {
  //uint8_t * heapptr, * stackptr;  // I declared these globally
  stackptr = (uint8_t *)malloc(4);  // use stackptr temporarily
  heapptr = stackptr;                  // save value of heap pointer
  free(stackptr);                        // free up the memory again (sets stackptr to 0)
  stackptr =  (uint8_t *)(SP);       // save value of stack pointer
  }
W wyniku działania programu ( dziękuje kaczakat) otrzymałem wynik iż wolna pamieć to 1422 RAM . Tylko dziwne okazało się dla mnie to że zawsze świeciła mi się dioda od strefy nieczułości , nawet w momencie gdy nie miała prawa świecić - np. przy warunku  "if(wartosc>(WILG+2))". Taka wolna pamieć ram jest chyba dopuszczalna.
(28-10-2018, 13:23)Automatyk231 napisał(a): [ -> ]W wyniku działania programu ( dziękuje kaczakat) otrzymałem wynik iż wolna pamieć to 1422 RAM .
Po kompilacji w raporcie jaki jest pokazane zużycie RAM?
(28-10-2018, 13:37)es2 napisał(a): [ -> ]Po kompilacji w raporcie jaki jest pokazane zużycie RAM?



Szkic używa 14708 bajtów (45%) pamięci programu. Maksimum to 32256 bajtów.

Zmienne globalne używają 625 bajtów (30%) pamięci dynamicznej, pozostawiając 1423 bajtów dla zmiennych lokalnych. Maksimum to 2048 bajtów.
Stron: 1 2 3 4 5 6 7 8