You need to log in to create posts and topics.

AVR Atmega128 sprintf sscanf not working

As states above, function sprintf (and scanf) works incorrect.  Functions seems to work except for copying to destination buffer. The latter only an assumption.

Hex compiled in Microchip Studio 7 with avr-gcc.exe (AVR_8_bit_GNU_Toolchain_3.6.2_1778) 5.4.0

Target device ATMega128A

SimulIDE-1.1.0-SR1. Also true for RC1

 

The functions works correct on real device.

Sample code:

 

#define F_CPU 7372800L

#include <avr/io.h>
#include <stdio.h>


#include "util/delay.h"


void USART_INIT(unsigned int chNo, unsigned int Baud)
{
	unsigned int ubrr = F_CPU/16/Baud-1;
	
	UBRR0H = (unsigned char)(ubrr>>8);
	UBRR0L = (unsigned char)ubrr;
	
	UCSR0B = (1<<RXEN0)|(1<<TXEN0);
	UCSR0C = (1<<USBS0)|(3<<UCSZ00);
}

void USART_Transmit( unsigned char data )
{
	/* Wait for empty transmit buffer */
	while ( !( UCSR0A & (1<<UDRE0)) )
	;
	/* Put data into buffer, sends the data */
	UDR0 = data;
}

void USART_Transmit( unsigned char data[] )
{
	int i = 0;
while(data[i]!='\0')
{
	USART_Transmit(data[i]);
	i++;
}
}

void USART_Transmit( const char data[] )
{
	USART_Transmit((unsigned char*)data);
}


int main(void)
{
	USART_INIT(0,19200);
	char buffer[10];
	/* Replace with your application code */
    while (1) 
    {
		_delay_ms(1000);
		sprintf(buffer, "\r\nTest %d", 10);
		USART_Transmit(buffer);
		USART_Transmit('.');
    }
}

 

Hi can you share your circuit and code to test it?

Here are sample circuit and hex file. Source code in first message.

Uploaded files: