Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with interfacing EUSART at 18F4550 with PC via RS232

Status
Not open for further replies.

Snail.cz

Newbie level 4
Joined
May 16, 2008
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,313
Hi,
I have a problem with EUSART(18F4550) Interface. I can't connect this MCU with PC via RS232. :cry:
When I transmit byte from MCU, the PC receive somethink else. For example: MCU transmit 0xaa and PC receive 0xff. So, I think it's problem with baudrate...

The problem isn't in hardware, because with 16F877A everythink works fine...

I'am using 20MHz crystal, and I want 20Mhz Fosc. So, configuration bits are:
CONFIG1L = 0b00100100;
CONFIG1H = 0b00001100;

Is that rigth ?

There is my code, i dont known what I doing wrong... :cry:
Code:
void serial_init(){
   TRISC7 = 1;									//Nastavení bran
   TRISC6 = 1;

   SPBRG = 64;
   BAUDCON = 0b00000000;
   TXSTA = 0b00100110;
   RCSTA = 0b10010000;
}

unsigned char RS232_send_byte(unsigned char data){
	while(TXIF == 0){};		// cekaci smycka
	TXREG = data;
	return(1);
}

void main(void){
   serial_init();

   while(1){
      DelayMs(300);
      RS232_send_byte(0xaa);
   }
}

Thanks, and excuse my poor english... :D
 

Re: EUSART at 18F4550

Snail.cz said:
When I transmit byte from MCU, the PC receive somethink else. For example: MCU transmit 0xaa and PC receive 0xff. So, I think it's problem with baudrate...

Hi,
why do you think it's a baudrate problem?
How are you displaying your sent (or received) data?
Isn't it a format problem? you may want to check the ASCII Table to be sure what your're sending (or receiving).

Best regards
Kabanga
 

Re: EUSART at 18F4550

why do you think it's a baudrate problem?
I don't known what else it could be...

How are you displaying your sent (or received) data?
I have my own RS232 "watcher" in C#, and it works great with 16F877A and the other devices...

Isn't it a format problem? you may want to check the ASCII Table to be sure what your're sending (or receiving)
My "watcher" displeys receive data in hex format...
 

Re: EUSART at 18F4550

Snail.cz said:
Send 0x00 ten(10) times and each time write down what you received.
Then send 0xFF ten times and write down again what you received.
Analysing the data you've written down, you may be able, I think, to understand what is going wrong.

Added after 47 seconds:

Send 0x00 ten(10) times and each time write down what you received.
Then send 0xFF ten times and write down again what you received.
Analysing the data you've written down, you may be able, I think, to understand what is going wrong.
 

Re: EUSART at 18F4550

Hi Kabanga,
So, I tried it, and this is result:

Code:
00 00 08 00 00 ff ef ef ef ff

I received only 10Byte..

Do you known, what's wrong ?

Thanks..
 

Re: EUSART at 18F4550

Snail.cz said:
Code:
00 00 08 00 00 ff ef ef ef ff

Hi,
is that what you are receiving sending 0x00 or 0xFF ?
Please post both results if the one for sending 0x00 are not zeros.
You may also want to check the format of your data on both PC's and MCU's sides: they must be the same.

Best regards
Kabanga
 

Re: EUSART at 18F4550

I do this:
Code:
void main(void){
   serial_init();

   while(1){

      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0x00);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      RS232_send_byte(0xff);
      DelayMs(300);
   }
}

When I send 0x00 ten times, i receive:
Code:
00 00 08 00 00

When I send 0x00 ten times, i receive:
Code:
ff ef ef ef ff

I don't known whats wrong, my PC sofware, hardware works fine with 16f877A...

Thanks for helping me...
 

Re: EUSART at 18F4550

Snail.cz said:
........... my PC sofware, hardware works fine with 16f877A...

Hi,
I'd suggest, it could be a baudrate problem. Unfortunatly I don't know your PC Software and what are its configurations.

Anyway, I'd advise you checking the baudrate in your PC-Soft ( it should be 19200 like in your MCU)

Or may be you can try to send and receive your data using Hyper Terminal . Just to check if you get the same results as with your PC-Soft.

Best regards
Kabanga
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top