Blocking Serial Monitor

Hi,
for Debugging on an ATtiny84 I want to use SoftwareSerial to print to Serial Monitor. For programming the ATtiny I use an USBasp connected to MISO, MOSI, USCK. To save pins SoftwareSerial also shall use MISO and MOSI. On the ATtiny84 pin numbers are 5=MISO=RX and 6=MOSI=TX.
For testing I wrote the following sketch:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(5, 6);  // RX, TX

uint32_t baudrt;
uint16_t lcnt = 0;
uint8_t val8;
uint16_t val16;
uint32_t val32;

void setup() {
 // put your setup code here, to run once:
 baudrt = 38400;
 mySerial.begin(baudrt);
 mySerial.println();
 mySerial.print("Baudrate=");
 mySerial.println(baudrt);
 char vc = ' ';
 char vstrg[24];
 val16 = 134;
 strcpy(vstrg, "hello world!");
 
//  block 1:
//  while (1) {
//    mySerial.print(val16);
//    mySerial.print(vc);
//    mySerial.println(vstrg);
//  }
 
//  block 2:
 for (int i = 0; i < 3; i++) {
   mySerial.print(val16);
   mySerial.print(vc);
   mySerial.println(vstrg);
 }

//  block 3:
//  lcnt = 0;
//  while (1) {
//    if (lcnt == 0) mySerial.println("jetzt while");
//    lcnt++;
//    mySerial.print(val16);
//    mySerial.print(vc);
//    mySerial.println(vstrg);
//    if (lcnt == 5) break;
//  }
}

void loop() {
 // put your main code here, to run repeatedly:

}

Setup() contains 3 blocks of code. With block 1active (the others are commented out) Serial Monitor shows the outputs of this code. Because the screen fills so rapidly, I cannot see if output of baud rate is on the screen.

With only block 2 or alternatively only block 3 active there is no output at all.

When I close the Serial Monitor and show the outputs with a terminal program, e.g. Tera Term, everything is ok with all blocks.

I cannot understand what happens here. Can somebody explain it to me?

Curious, how can you interface the TTL serial signals? Did you connect an FTDI to the pins, or something like that?

yes, sorry forgot to mention that the pins 5 and 6 are linked via an FTDI back to the PC.

Try putting a delay after calling the begin() method.

Thank you, a delay(1) is sufficient.

No! A first test was ok with delay(1). Further trials with up to delay(10) failed.
Now, delay(50) seems to be stable.

1 Like

@SupArdu, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.