Unexpected Serial.print Output with Attiny1607

I’m experiencing strange outputs when I attempt to print a string using the Attiny1607 MCU.
Here is example:
image

I’m using the megaTinyCore for development.
Here is my main.cpp:

#include <Arduino.h>

void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.println(“hello world”);
delay(1000);
}

Here is the .ini file:

[env:ATtiny1607_pymcuprog_upload]
platform = atmelmegaavr
board = ATtiny1607
framework = arduino
upload_speed = 115200
upload_flags =
–tool
Atmel-ICE
–device
attiny1607
–clk
$UPLOAD_SPEED
upload_command = pymcuprog write --erase $UPLOAD_FLAGS --filename $SOURCE

You must specify the baud rate to be used for the serial monitor.
Add the following line to your platformio.ini:

monitor_speed = 9600

I thought that was the issue as well. I actuallly tried that before posting. I inserted back for both of sanities. Still have the same issue.

[env:ATtiny1607_pymcuprog_upload]
platform = atmelmegaavr
board = ATtiny1607
framework = arduino
monitor_speed = 9600
upload_speed = 115200
upload_flags =
–tool
Atmel-ICE
–device
attiny1607
–clk
$UPLOAD_SPEED
upload_command = pymcuprog write --erase $UPLOAD_FLAGS --filename $SOURCE

When upload @ 115200 works: did you try this baudrate for serial communication?

main.cpp:

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

platformio.ini:

monitor_speed = 115200

No change unfortunately. I’m going to try a couple of different baud rates.

So here is my old code with microchip studio .cpp file that works:

#define F_CPU 3333333
#define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
#include <avr/io.h>
#include <util/delay.h>
#include <string.h>
#include <avr/interrupt.h>
#include “avr/sleep.h”

void USART0_init(void);
void USART0_sendChar(char c);
void USART0_sendString(char *str);

void USART0_init(void)
{
PORTB.DIR &= ~PIN3_bm; //RX line of the ATTINY 1607
PORTB.DIR |= PIN2_bm; //TX line of the ATTINY 1607

USART0.BAUD = (uint16_t)USART0_BAUD_RATE(9600);

USART0.CTRLB |= USART_TXEN_bm;
}

void USART0_sendChar(char c)
{
while (!(USART0.STATUS & USART_DREIF_bm))
{
;
}
USART0.TXDATAL = c;
}
void USART0_sendString(char *str)
{
for(size_t i = 0; i < strlen(str); i++)
{
USART0_sendChar(str[i]);
}
}

int main(void)
{
USART0_init();
USART0_sendString(“Hello World!\r\n”);
_delay_ms(500);
}

Looks like this program lowers the baud to ~1300 so I tried setting the baud rate in the platform.io project and it still doesn’t work. Is there something else that is configured in the microchip studio project that isn’t in the platform.io?

I guess that’s the root cause.
3.333 MHz is a bit strange in my opinion - but I’m not an expert here.
Suggestion: Try with 1 MHz

I think you have to add the F_CPU in your platformio.ini see here:

board_build.f_cpu = 1000000L

Still no change.

So apparently there is a default clock speed of 16 or 20 MHz on this MCU with a default clock divider of 6. Which I don’t know where it saids that in the datasheet.

I didn’t expect to have this much trouble with this haha. Thanks for helping out.

So it looks like I got it figured out. I really would like to know where the default prescaler/clock divider comes in when you use platformio. It’s probably in the auto fuse function that tinymegacore has. I basically followed this example:

I found that gibbish still exist on the 16MHz f_cpu option. I changed that 20MHz and eureka!
Here is the resulting ini file:

[env]
platform = atmelmegaavr
board = ATtiny1607
framework = arduino
board_build.f_cpu = 20000000L
board_hardware.oscillator = internal
monitor_speed = 115200

[env:Upload_UPDI]
upload_protocol = atmelice_updi ; Upload protocol for UPDI upload.

[env:set_fuses]
upload_protocol = ${env:Upload_UPDI.upload_protocol} ; Upload protocol for used to set fuses
upload_flags =
; Hardware settings
board_hardware.bod = 2.7v
board_hardware.eesave = yes
board_hardware.updipin = updi

Thanks for the help!