Go Down

Topic: A better SoftwareSerial for ATtiny45/85? (Read 182 times) previous topic - next topic

blahop

Sep 19, 2019, 01:57 pm Last Edit: Sep 19, 2019, 02:46 pm by blahop
Hello,
I'm using an ATtiny45 with https://github.com/SpenceKonde/ATTinyCore

I'm doing a MIDI 1 in/1 out event processor.

I've tried many Serial solutions:

  • SoftwareSerial (=NewSoftSerial)
  • Serial (seems to be =TinySoftSerial on ATtiny45 since there is no hardware UART)
  • NeoSWSerial (https://github.com/SlashDevin/NeoSWSerial/) but no luck with it until now
  • AltSoftSerial won't work because it requires a 16 bit timer (not available on ATtiny45 IIRC)
  • very promising "Full duplex software serial port" https://www.avrfreaks.net/projects/full-duplex-software-serial-port or https://github.com/flo90/USIUART but I haven't been to compile this code, it doesn't seem to be Arduino-like. Maybe it could work but haven't been able to compile from Arduino IDE: "PORTD not defined" or similar errors
  • https://hackaday.com/2019/03/13/attiny-gets-a-tiny-software-uart/



but always, at the end, some MIDI messages were badly read and written when too many MIDI messages were arriving at the same time. The electronic part (optocoupler etc.) is double checked and ok.

Question: is there a better SoftwareSerial on ATtiny45 that could read all the bytes, wait 1 ms, write the bytes?

Attempt1 (writing just after reading, maybe not a good idea!) of echo RX to TX

Code: [Select]
#include "SoftwareSerial.h"
SoftwareSerial Serial2(3,4);

void setup() {
  Serial2.begin(31250);
  Serial2.write(255);
}

void loop() {
  while (Serial2.available())         
    Serial2.write(Serial2.read());
}


Attempt2 (reading all available bytes, wait, and write) of echo RX to TX

Code: [Select]
#include "SoftwareSerial.h"
SoftwareSerial Serial2(3,4);

void setup() {
  Serial2.begin(31250);
  Serial2.write(255);
}

byte buf1[64] = {0};
byte num = 0;

void loop()
{
  while (Serial2.available()) {
    buf1[num] = Serial2.read();
    num += 1;
  }
  delay(1);
  for (int i = 0; i < num; i++)
    Serial2.write(buf1[i]);
  num = 0;
}


Thanks in advance

Go Up