PIC18 EUSART Rx Problem

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

PIC18 EUSART Rx Problem

Postby philipng86 » Wed Jan 19, 2011 8:57 pm

Hello everyone... i am facing one problem on PIC18 EUSART..
My EUSART Tx work great... can transmit string correctly
but the problem is Rx part...
It can receive as well... but i try to echo back (by code) ... i get the other things...
I check the RCREG via debug mode, i found weird data...

for example:
PC --> [0x80 - 10000000] --> USART
PC <-- [0x00 - 00000000] <-- USART

PC --> [0x40 - 01000000] --> USART
PC <-- [0x0D - 00001101] <-- USART

PC --> [0x20 - 00100000] --> USART
PC <-- [0x1D - 00011101] <-- USART

PC --> [0xF7 - 11110111] --> USART
PC <-- [0x40 - 01000000] <-- USART

PC --> [0xFB - 11111011] --> USART
PC <-- [0x02 - 00000010] <-- USART

PC --> [0xFD - 11111101] --> USART
PC <-- [0x01 - 00000001] <-- USART

PC --> [0xFE - 11111110] --> USART
PC <-- [0x00 - 00000000] <-- USART

PC --> [0x7F - 01111111] --> USART
PC <-- [0x40 - 01000000] <-- USART

PC --> [0xBF - 10111111] --> USART
PC <-- [0x20 - 00100000] <-- USART

PC --> [0xDF - 11011111] --> USART
PC <-- [0x10 - 00010000] <-- USART

curently i use EUSART interrupt to Rcv data...
when interrupt flag set, then jump into Rx routine...
then DATA = RCREG
then printf(DATA) to echo the Byte in DATA or RCREG..

Please help...

thanks...
philipng86
Greenhorn
 
Posts: 3
Joined: Wed Jan 19, 2011 8:43 pm

Re: PIC18 EUSART Rx Problem

Postby aurora » Wed Jan 19, 2011 10:12 pm

Which PIC are you using? Is it asynchronous or synchronous mode? Looks like there is a pattern with your data. Not sure if it is a typo or what, you are suppose to echo back the data to TCREG.
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: PIC18 EUSART Rx Problem

Postby philipng86 » Thu Jan 20, 2011 1:36 am

it is Async... and i am using PIC18F4410 (44pin package)
Datasheet: http://ww1.microchip.com/downloads/en/D ... 39636d.pdf
EUSART Doc: http://ww1.microchip.com/downloads/en/D ... /usart.pdf

from wat i understand and refering data sheet, as well as sample code around web...
once usart interruped, let say i send 0x80 to PIC..
this 0x80 will stored into a buffer and then transfer to RCREG
so, suppose this RCREG is 0x80 also...
so i jz do like this...
DATA = RCREG
TXREG = Data
So, i assume i will get 0x80... am i right??
philipng86
Greenhorn
 
Posts: 3
Joined: Wed Jan 19, 2011 8:43 pm

Re: PIC18 EUSART Rx Problem

Postby aurora » Thu Jan 20, 2011 10:36 am

Did you connect your ground between the PIC and PC?
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: PIC18 EUSART Rx Problem

Postby philipng86 » Thu Jan 20, 2011 11:23 am

Sure i connect gnd to pic...
if not, my transmit data sure incorrect also...
so any other possibility?
philipng86
Greenhorn
 
Posts: 3
Joined: Wed Jan 19, 2011 8:43 pm

Re: PIC18 EUSART Rx Problem

Postby aurora » Thu Jan 20, 2011 12:21 pm

I had similar experience before, because I just connect the Tx and Rx, and forget about the ground. In the end, I get garbage value.

Have you try using lower baudrate setting? Could be due to instability at high baudrate. Are you running any other code in the background? How about interrupts? I haven't use EUSART before, only USART. Not sure what is the different, so need some time to read and digest the info also... :oops: :lol:
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: PIC18 EUSART Rx Problem

Postby yonghui » Fri Jan 21, 2011 4:49 pm

hi,

i guess EUSART is almost same but with some enhancement for autobaud rate, address detection with 9bits things.
baudrate is correct?

why dont u try to test transmit and receive independently.


regards,
yh
thanks&regards,
yh
yonghui
Professional
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: PIC18 EUSART Rx Problem

Postby ober » Sat Jan 22, 2011 12:37 pm

philipng86 WROTE:Sure i connect gnd to pic...
if not, my transmit data sure incorrect also...
so any other possibility?


Hi, can you share your code of ISR and UART init using the code function here?
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron