SoftwareSerial TX produces garbled characters, while Serial TX works at 1 MHz (ATtiny84a)
Closed this issue · 2 comments
Hello,
I am encountering issues with serial communication on the ATtiny84a. SoftwareSerial
consistently produces garbled characters in the Serial Monitor, regardless of the pin or baud rate configuration. While Serial
works reliably on PA1 with the internal 1 MHz oscillator, it struggles with baud rate and clock accuracy under other configurations, limiting its usability in my setup.
I need a stable solution to enable TX on PA7 because I plan to use the serial connection via a WaveShare FTDI adapter for debugging and running unit tests. This functionality is essential for my workflow.
I have already performed the following steps to troubleshoot:
- Tested the same pin PA1: Both
Serial
andSoftwareSerial
were tested on PA1;Serial
works only at 1 MHz and 4800 baud.SoftwareSerial
also produces garbled characters. - Tried different clock sources:
- Internal 1 MHz oscillator:
Serial
on PA1 works. - Internal 8 MHz oscillator:
Serial
does not work.
- Internal 1 MHz oscillator:
- Varied the baud rate: Tested with 2400, 4800, 9600, 19200 baud; no improvement.
- I attempted to move the Serial port to PA7 using the
Serial.setTxBit()
method, but unfortunately, this method is only available starting from version 2.0.
Hardware:
- µC & Clock: ATtiny84a using the internal oscillator
- Pins used for TX:
- PA1 (Arduino pin 1): Works with
Serial
at 1 MHz clock. - PA7 (Arduino pin 7): Needed for TX with
SoftwareSerial
but produces garbled characters.
- PA1 (Arduino pin 1): Works with
- Adapter: WaveShare FTDI FT232 USB UART Board (mini)
- Wiring: TX (PA7 or PA1) → RX of the adapter ; GND is connected.
Software:
- Development environment: PlatformIO in VSCode
- ATTinyCore version: 1.5.2
- SoftwareSerial version: 1.0.0
Here my platformio.ini
configuration:
[env:attiny84]
platform = atmelavr
board = attiny84
framework = arduino
upload_protocol = usbasp
board_build.mcu = attiny84
board_build.f_cpu = 1000000L
board_build.variant = tinyX4_reverse
test_build_src = false
test_port = COM3
monitor_speed = 4800
lib_deps = SoftwareSerial@1.0.0
Example Code:
Using Serial
(working on PA1):
#include <Arduino.h>
void setup() {
Serial.begin(4800);
Serial.println("Hello from ATtiny84");
}
void loop() {
Serial.println("Ping...");
delay(1000);
}
Using SoftwareSerial
(not working on PA7 and PA1):
#include <Arduino.h>
#include <SoftwareSerial.h>
SoftwareSerial softSerial(99, 1); // RX (unused), TX (Pin PA1)
void setup() {
softSerial.begin(4800);
softSerial.println("Hello from ATtiny84");
}
void loop() {
softSerial.println("Ping...");
delay(1000);
}
Questions:
- Why does SoftwareSerial on PA7 produce garbled characters, regardless of baud rate or clock source?
- Why does Serial also struggle so significantly with baud rate and clock accuracy?
- What adjustments are required to achieve stable TX on PA7 with SoftwareSerial?
I would greatly appreciate any help or insights that could resolve this issue.
Best regards
My first guess is that this could be an internal oscillator calibration issue. Have you tried using an oscillator calibration sketch? Or using an external oscillator?
Yes, it was a problem with the chip, maybe with the oscillator. After switching to another µC, it works correctly. Really annoying mistake, because I wasted a lot time. Thank you.