Sign In

Trouble In Sending Character From Pc

Kich Dumchi Korea, Republic of

Hardware: AT90CAN128 Running On My Own Board Software: AVR Studio 4

I am trying to run a sample UART code for AT90CAN128. I couldn’t see any thing on Hyper-terminal while sending character. I have checked all my hardware working properly. pin 0 and pin 1 of PORTE sre configured as input(Rx) and output(Tx) respectively. I have also tried to display a char received on LCD and it shows unreadable characters.



/*	Sample program for Olimex AVR-CAN with AT90CAN128 processor
 *	Echoes back the received characters on the USART0.
 *	Compile with AVRStudio+WinAVR (gcc version 3.4.6)

#define	__AVR_AT90CAN128__	1
#define OSCSPEED	16000000		/* in Hz */

#include "avr/io.h"

void PORT_Init()
	PORTA = 0b00000000;
	DDRA = 0b00000000;

	PORTB = 0b00000000;
	DDRB = 0b00000000;

	PORTC = 0b00000000;
	DDRC = 0b00000000;

	PORTD = 0b00000000;
	DDRD = 0b00000000;

	PORTE = 0b00010000;		//Turn Led off (Bit4 = 1)
	DDRE = 0b00010010;		//Led set as output (Bit4 = 1), TX set as output (Bit1 = 1)

	PORTF = 0b00000000;
	DDRF =  0b00000000;

void WDT_Off(void)
	asm("push r30");	// using GCC without optimizations results in
	asm("ldi r30, 0x18");	// a code not meeting the requirements
	asm("sts 0x60, r30");	// of the datasheet.
	asm("ldi r30, 0x7");
	asm("sts 0x60, r30");
	asm("pop r30");
	WDTCR = (1<<WDCE) | (1<<WDE);
	WDTCR = 0x07;					//increase Watchdog time-out period (Bit0,1,2 = 1)

void UART_Init(uint32_t Baud)
	unsigned int BaudRate = OSCSPEED / (16 * Baud) - 1;	//calculate BaudRate
	//set BaudRate into registers
	UBRR0H = (unsigned char) (BaudRate>>8);
	UBRR0L = (unsigned char) BaudRate;

	UCSR0B = 0b00011000;		//enable TX(Bit4 = 1), RX(Bit3 = 1)

	UCSR0C = 0b00000110;		//set frame format (8 bits, 1 stop bit)

unsigned char UART_Receive()
	if (UCSR0A & 0b10000000)
		return UDR0;
		return 0;

void UART_Transmit(unsigned char Data)
	while (!(UCSR0A & 0b00100000));
	UDR0 = Data;

int main()
	unsigned char Ch ;
	while (1)
		asm("WDR");				//avoiding reset of the program
		Ch = UART_Receive();	//receiving char
		if (Ch)
			UART_Transmit(Ch);	//returning char



R Avinash Gupta
2016-09-22 06:29:18
The most common reason of fault on serial communication system is of TIMING. So please tell us what value crystal you are using. Also read the values of HIGH and LOW fuse bytes and POST here. This will enable us to find out at what speed the ATmega is running.

Also provide details of the USB to serial adapter used by you and a photo of complete setup.
R Kich Dumchi
2016-09-22 07:41:16
Dear Avinash Gupta,
Thank you a lot for your immidaite response.

I have attached some pictures as you seggusted me to send.
The USB to serial Iam using is HL-340 converter as shown on the picture.
would you see the pictures for your information?
Thank you once again.
R Kich Dumchi
2016-09-22 07:43:55
Sorry, I forgot to mention the value of crystal I am using.
It is 8MHz
R Avinash Gupta
2016-09-23 04:30:47
From the image I guess that the signal available from the development board is TTL level but you have connected it to RS232 level.

Do you see any 16 pin IC like MAX232 near the RX/TX line of dev board?

Or it directly connect to the microcontroller's RX/TX pins?
R Kich Dumchi
2016-09-23 05:33:05
Thank you a lot Avinash Gupta,

It is intrefaced through MAX232AESE, not directly to RX/TX pins .
Now I could received some thing '[00]'as echo as seen in the attached figure while sending a charachter. As you mentioned before, the issue can be a fuse bytes issue. I just used defualt values mentionedint the datasheet. As my understanding, the default one is to use internal oscillator where as I am trying to use external oscillator. would you look in to it and help me in setting the fuse bytes?

FYI: External Crystal Oscillator : 8MHz
MCU : AT90CAN128
#define OSCSPEED 16000000

Thank you once again
R Avinash Gupta
2016-09-23 06:24:22
which programmer software you are using to flash the chip?

Also your terminal baud rate is also incorrect! Its 14400 while it should be 9600
R Avinash Gupta
2016-09-23 06:26:33
If you are sure its default fuse bytes then change line #define OSCSPEED 16000000


#define OSCSPEED 1000000
R Avinash Gupta
2016-09-25 04:21:03
Waiting for your reply ...
R Kich Dumchi
2016-09-25 23:30:32
Avinash Gupta,

Thanlk you a lot for your help.

I did as you had suggested me. Except the resulting charachter is changed, still I couldn't see the correct character. I have also tried with external oscillator as the result shown in the attached screen shot. still, the same.
do you have some other suggestion.
R Kich Dumchi
2016-09-26 02:25:19
Dear Avinash Gupta,

Finally I got it.
By setting CKDIV8 to binary 1(disabling), I have defined '#define OSCSPEED 8000000' insteady of '#define OSCSPEED 16000000' because my external oscillator is 8MHz.

Thank you for your help once again.
R Kich Dumchi
2016-10-11 00:02:46
dear Avinash Gupta,
while I am tryirng to send a command data from AT90CAN128 to renesas microcontroller through uart, the command couldn't reach to renesas microcontroller and vise versa. At both end there is max232 chip. When sending the same command from AT90CAN128 to pc it is received properly and also from PC to the renesas microcontroller, it does the same. would you suggested me some thing do? couldn't it be a hardware problem?
Thank you alot.

Post a reply to Kich Dumchi

Think you can help Kich Dumchi ? Then post your thoughts that might help Kich Dumchi. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.