PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

General discussion on mikroC PRO for AVR.
Post Reply
Author
Message
Heaklig
Posts: 10
Joined: 20 Oct 2012 16:46

PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#1 Post by Heaklig » 15 Nov 2016 20:34

I have a problem with a simple led blinking project.

Ther MCU it's a ATmega644A @8MHz INT OSC. This MCU has TWO USART modules. The code is as follows:

Code: Select all

#define Tx_signal	PORTB.B0

void setup(void){
	DDRB.B0 = 1;
	DDRD.B6 = 1;
	Tx_signal = 0;

	UART1_Init(19200);
	UART2_Init(19200);

	Tx_signal = 1; Delay_ms(200); Tx_signal = 0;
}

void main(){
setup();
	while(1){
	//-----------------TRICKY PART---------------
		UART2_Write('A');
	//-------------------------------------------
		Tx_signal = 1; Delay_ms(200); Tx_signal = 0;
		Delay_ms(1000);
	}

}
When I delete the UART2_Write('A'); the led blinks without any problems, but when writing through the UART2 the program freezes. Please NOTICE that when using UART1 instead of UART2 it also works perfectly.

How can I handle that?

Thanks in advance.

Heaklig

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#2 Post by uros.cvetinovic » 16 Nov 2016 17:00

Hi,

I used this same code with ATMEGA644PA and it works without any problem.
PB0 blinks even that UART2_Write('A'); line is present.

What kind of hardware do you use?
Did you test this with any similar MCU?

Best regards,

Uros

Heaklig
Posts: 10
Joined: 20 Oct 2012 16:46

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#3 Post by Heaklig » 17 Nov 2016 04:35

Well, for now I just have the MCU on a breadboard with the LEDs and other stuff, but I also simulated it using Proteus and the same thing happened. It's just weird that it only happens when calling the UART2_Write function, but it works perfectly when I call the UART1_Write function. I already wrote a library using the datasheet's information and example codes, but it would be great if we could solve that.

***UDATE***
I tried with a ATmega1284P, changed the MCU in the mikroC IDE and re-compiled. It worked. Then, I changed the MCU to ATmega644A in the mikroC IDE again, re-compiled and loaded the the code into the ATmega1284P. It worked. So, I loaded the code into the ATmega644A. It didn't work. I tried with two just unpacked MCUs and with virtual simulations.

It's hillarious, the code for 644A works perfectly on the 1284P MCU, but it does not work on the 644A MCU.

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#4 Post by uros.cvetinovic » 17 Nov 2016 12:07

Hi,

I have found ATmega644A in DIP40 package, and tested on it, and it works.
PB0 blinks with UART2_Write('A'); line present.

Please find attached hex file for testing with your ATmega644A.
I can send you project if you want.

Best regards,

Uros
Attachments
test.rar
(502 Bytes) Downloaded 169 times

Heaklig
Posts: 10
Joined: 20 Oct 2012 16:46

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#5 Post by Heaklig » 18 Nov 2016 02:41

I tried the .HEX file you attached and it didn't work, no in my board neither in the Proteus simulation.
As you say it worked for you, I could think the problem is some configuration, but the thing is that it actually works with the UART1 library. The same thing happened with the .HEX file you attached: It works when I burn it into the ATmega1284P.

It's weird. I also have ATmega644A in DIP40 package.

Any other idea to face the problem?

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#6 Post by uros.cvetinovic » 18 Nov 2016 17:29

Hi,

Can you please tel me what kind of hardware do you use?
Can you give me the schematic and the picture of your hardware?

If you are using same MCU in same package, with same hex file as mine,
the only thing that is different is hardware, so that must be the source of the problem.

Best regards,

Uros

Heaklig
Posts: 10
Joined: 20 Oct 2012 16:46

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#7 Post by Heaklig » 18 Nov 2016 20:10

Please find attached the schematic, the code, the log file, the .HEX files I compiled with both UART1 and UART2 functions, the configuration file and the .HEX file provided by you.

Heaklig
Attachments
Uros.zip
(32.53 KiB) Downloaded 169 times

User avatar
uros.cvetinovic
mikroElektronika team
Posts: 803
Joined: 14 Dec 2015 09:24

Re: PROBLEM WITH ATMEGA644A UART LIBRARY ROUTINE

#8 Post by uros.cvetinovic » 22 Nov 2016 18:02

Hi Heaklig,

I don't know what is wrong here.

With all three hex files in my case PB0 blinks.

I am using this development board:
http://download.mikroe.com/documents/fu ... c-v101.pdf

The MCU is in DIP 40B soket.
The only difference I can see is the resistor which is 10k in my case, but I don't believe that could be the cause of this.

Best regards,

Uros

Post Reply

Return to “mikroC PRO for AVR General”