You need to log in to create posts and topics.

USART, Monitor serial Simulide, attiny2313 no work. But USART, Picocom, attiny2313 work.

Hi!

I hope my problem is understood; I used AI Qwen2.5-Max to translate it into English.

Basically, what my program does is display on the serial monitor the letter (twice, Tx, Rx) corresponding to each key I press, as well as turn an LED on and off. However, I can't get it to work in SimulIDE 1.1.0-SR1 at rev 2005 compiled on 17-10-2024. Even though I changed the baud rate to 4800, I can only see the letter I press on the output screen. But when I physically load the program onto an ATtiny2313 with an F_CPU of 1000000 and a baud rate of 4800 (which is how it works for me without using an external oscillator), I have no issues. I use picocom configured as follows: picocom -b 4800 --parity n --data 8 --stop1 --echo /dev/ttyUSB0. What am I doing wrong? Or what do I need to configure? My program, library, circuit, and makefile are as follows:

 

<circuit version="1.1.0-SR1" rev="2005" stepSize="1000000" stepsPS="1000000" NLsteps="100000" reaStep="1000000" animate="1" >

<item itemtype="MCU" CircId="tiny2313-1" mainComp="false" Show_id="true" Show_Val="false" Pos="-100,-128" rotation="0" hflip="1" vflip="1" label="tiny2313-1" idLabPos="0,-20" labelrot="0" valLabPos="-16,20" valLabRot="0" Frequency="1 MHz" Program="013UART_tx2.hex" Auto_Load="false" saveEepr="true" Logic_Symbol="false" Rst_enabled="false" Ext_Osc="false" Wdt_enabled="false" varList="DDRD,DDRD,PORTD,rxdata,UDR" MainMcu="true" SerialMon="-1" />

<item itemtype="SerialTerm" CircId="SerialTerm-2" mainComp="false" Show_id="false" Show_Val="false" Pos="-132,-64" rotation="-90" hflip="-1" vflip="1" label="SerialTerm-2" idLabPos="-20,-32" labelrot="0" valLabPos="-16,20" valLabRot="0" Baudrate="4800 _Bd" DataBits="8 _bits" StopBits="1 _bits" SerialMon="false" />

<item itemtype="Resistor" CircId="Resistor-3" mainComp="false" ShowProp="Resistance" Show_id="false" Show_Val="true" Pos="-48,-72" rotation="-90" hflip="1" vflip="1" label="Resistor-3" idLabPos="-16,-24" labelrot="0" valLabPos="-11.9448,-5.3605" valLabRot="0" Resistance="100 Ω" />

<item itemtype="Led" CircId="Led-4" mainComp="false" Show_id="false" Show_Val="false" Pos="-48,-108" rotation="-90" hflip="1" vflip="1" label="Led-4" idLabPos="-16,-24" labelrot="0" valLabPos="-16,20" valLabRot="0" Color="Yellow" Grounded="true" Threshold="2.4 V" MaxCurrent="30 mA" Resistance="0.6 Ω" />

<item itemtype="Connector" uid="Connector-3" startpinid="Led-4-lPin" endpinid="Resistor-3-rPin" pointList="-48,-92,-48,-88" />

<item itemtype="Connector" uid="Connector-7" startpinid="Resistor-3-lPin" endpinid="tiny2313-1-PORTD6" pointList="-48,-56,-48,-48,-60,-48" />

<item itemtype="Connector" uid="Connector-12" startpinid="SerialTerm-2-pin0" endpinid="tiny2313-1-PORTD0" pointList="-124,-40,-112,-40,-112,-112,-108,-112" />

<item itemtype="Connector" uid="Connector-13" startpinid="tiny2313-1-PORTD1" endpinid="SerialTerm-2-pin1" pointList="-108,-104,-120,-104,-120,-68,-132,-68,-132,-40,-140,-40" />

</circuit>

 

 

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "UART_LIB.h"

uint8_t letra;

int main(void){

  UART_Init(4800);
  DDRD |= (1<<DDD6);
  UCSRB |= (1 << RXCIE);
  sei();

	while(1){
  _delay_ms(100);
	}
}

ISR(USART_RX_vect){
  letra = UART_Receive();
  UART_Transmit_char(letra);
  PORTD ^= (1 << PD6);
}

 

 

#include "UART_LIB.h"

//static char _uart_buffer_[50];

void UART_Init(uint16_t baudrate){
	
		uint16_t regUBRR = F_CPU/(baudrate*16UL) - 1;
		
		// Cargamos los valores de BAUDRATE en los registros UBRR;
		UBRRH = (uint8_t) (regUBRR>>8);
		UBRRL = (uint8_t) (regUBRR);
		
		//Configuramos modo de operacion de 8 bits de datos;
		//UCSRB &= ~(1<<UCSZ2);
		UCSRC = (1<<UCSZ1)|(1<<UCSZ0);
		
		//Sin paridad;
		//UCSRC &= ~( (1<<UPM1)|(1<<UPM0) );
		
		//Modo asincrono;
		//UCSRC &= ~(1<<UMSEL);
		
		//Habilitamos los pines Tx Rx;
		UCSRB = ( (1<<RXEN)|(1<<TXEN) );
		
		
}

void UART_Transmit_char(uint8_t data){
	// Espera a que el registro de transmisión esté vacío
	while (!(UCSRA & (1 << UDRE)));
	// Carga el dato en el registro de transmisión
	UDR = data;
}


void UART_Transmit_Text(char *texto){
	while(*texto){
		UART_Transmit_char(*texto);
		texto++;
	}
}


/*void UART_Transmit_Printf(char *str, ...){
	
	va_list args;
	va_start(args,str);
	vsnprintf(_uart_buffer_, 50, str, args);
	va_end(args);
	UART_Transmit_Text(_uart_buffer_);
	
}*/

void UART_Transmit_Number(uint8_t number) {
    if (number == 0) {
        UART_Transmit_char('0');
        return;
    }

    char buffer[4]; // Buffer para almacenar dígitos (máximo 3 dígitos para uint8_t)
    uint8_t index = 0;

    while (number > 0) {
        buffer[index++] = (number % 10) + '0'; // Convierte el dígito a carácter ASCII
        number /= 10;
    }

    // Envía los dígitos en orden inverso
    for (int i = index - 1; i >= 0; i--) {
        UART_Transmit_char(buffer[i]);
    }
}

bool UART_DataAvailable(void){
	return ( UCSRA & (1<<RXC) );
}

uint8_t UART_Receive(void) {
	while (!(UCSRA & (1<<RXC))); // Espera hasta que se reciba un byte completo
	return UDR; // Retorna el byte recibido
}


#ifndef UART_LIB_H_
#define UART_LIB_H_

#define F_CPU 1000000UL
#include <avr/io.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>

void UART_Init(uint16_t baudrate);
void UART_Transmit_char(uint8_t data);
void UART_Transmit_Text(char *texto);
//void UART_Transmit_Printf(char *str, ...);
void UART_Transmit_Number(uint8_t number);
bool UART_DataAvailable(void);
uint8_t UART_Receive(void);


#endif /* UART_LIB_H_ */

 

#makefile attiny2313
AVR         = attiny2313
COMPILAR    = avr-gcc -Wall -O3 -mmcu=$(AVR)

FUENTES     = 013UART_tx2.c UART_LIB.c
SALIDA_HEX  = 013UART_tx2.hex
OBJETOS     = $(patsubst %.c, %.o, $(FUENTES))
SALIDA_ELF  = $(patsubst %.hex, %.elf, $(SALIDA_HEX))

all: $(SALIDA_HEX) size  # <-- Añade 'size' como dependencia

%.o: %.c
	$(COMPILAR) -c $<

$(SALIDA_HEX): $(OBJETOS)
	$(COMPILAR) $^ -o $(SALIDA_ELF)
	avr-objcopy -O ihex $(SALIDA_ELF) $@

# Comando para verificar el tamaño del firmware
.PHONY: size
size: $(SALIDA_ELF)
	@echo "=== Tamaño del firmware ==="
	avr-size --mcu=$(AVR) --format=avr $(SALIDA_ELF)

clean:
	rm -f *.o *.elf *.hex



Thank you, I will have a look.

Lazlo_lozla has reacted to this post.
Lazlo_lozla

Hi, this problem should be solved in last Tester build for 1.1.0:

https://simulide.com/p/testers/ 

Lazlo_lozla has reacted to this post.
Lazlo_lozla

I already tested rev-2051, and now the USART works fine. Thanks!

arcachofo has reacted to this post.
arcachofo