SpenceKonde / ATTinyCore

Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8
Other
1.57k stars 306 forks source link

Compiling with SoftwareSerial.h not possible (ATtiny2313, memory problem) #517

Closed Gehilfe closed 3 years ago

Gehilfe commented 3 years ago

Hi, I am trying to compile a very simple program with the library SoftwareSerial.h for an ATtiny2313 and I get the error message directly:

Sketch uses 2344 bytes (114%) of program storage space. Maximum is 2048 bytes.text section exceeds available space in board
Global variables use 144 bytes (112%) of dynamic memory, leaving -16 bytes for local variables. Maximum is 128 bytes.

The program code looks like this:

#include <SoftwareSerial.h>

SoftwareSerial device(3,4); //Rx,Tx
byte stunden = 0;
byte minuten = 0;
byte sekunden = 0;
byte startcode = B10101010;
byte empfangenercode = 0;

void setup() {
  device.begin(9600);
  device.println("Setup erledigt");
}

void loop() {
  if (device.available() > 0) {
    //Serial.println("Daten vorhanden");
    empfangenercode = device.read();
    device.println(empfangenercode,BIN);
    if (empfangenercode == startcode) {
      stunden = device.read();
      minuten = device.read();
      sekunden = device.read();
      device.println(stunden);
      device.println(minuten);
      device.println(sekunden);
    }
  }
}

I use the Arduino IDE 1.8.13 and the ATTinyCore 1.4.1. The same problem occurs when I try to compile the program with PlatformIO.

Am I doing something wrong? Do you have a tip for me? For the final program (a multiplexer for Nixie tubes) I only need the "serial read function", but for debugging it would be great for me to be able to read as well as write serially.

Would be great if you could help me.

SpenceKonde commented 3 years ago

Why software serial??? There is a real hardware serial port just sitting there.. hardware serial is generally less resource hungry than software serial and works better. That alone might save you enough to get in under the limit,, check also You can (and should) wrap any debugging strings in F() macro, but that only saves ram, whereas you're barely over the RAM limit, but way over the flash limit. I think printing strings is a luxury you can't afford . Maybe print char's (single quotes, like 'a', take 1 byte of storage; it takes 2 bytes to store "a" vs 1 t store 'a' because the one with double quotes is a null terminated char array,with 2 elements

byte stunden = 0;
byte minuten = 0;
byte sekunden = 0;
byte startcode = B10101010;
byte empfangenercode = 0;

void setup() {
  Serial.begin(9600);
  //Serial.println("Setup erledigt");
  //Serial.prrintln 
}

void loop() {
  if (Serial.available() > 0) {
    //Serial.println("Daten vorhanden");
    empfangenercode = Serial.read();
    Serial.println(empfangenercode,BIN);
    if (empfangenercode == startcode) {
      stunden = Serial.read();
      minuten = Serial.read();
      sekunden = Serial.read();
      Serial.println(stunden);
      Serial.println(minuten);
      Serial.println(sekunden);
    }
  }
}

Anyway, my other tip would be to use a part with more than 2k of flash. The 2313 is the lamest part supported by this core (okay, maybe the 24 is worse). I am amazed how many people are still using these dreadful ancient parts. They aren't even particularly cheap! digikey lists them for like 75 cents/ea in cheapest package that can be soldereed without advanced techniques, no minimum order, which would get you into 8k flash tinyAVR 0/1-series parts, and it's very close to the price of the stand-out ATtiny1614, with 16kl flash, 2k ram, and the "good set" of tinyAVR 1-series peripherals (the 16k and 32k 1-series have a second ADC, second type B timer, and some other goodies that I can't remember off hand atm).