• AVR Freaks

Hot!Serial communication between PIC16F877 and computer

Page: < 12345 > Showing page 3 of 5
Author
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:21:47 (permalink)
0
@ric:
PIC, interface and PC has common ground: hardware is powered by usb port.
#41
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:29:33 (permalink)
+1 (1)
This line
__CONFIG(0xd06);



Means that bit 2 is set, so the WatchDog Timer is enabled.
That is fatal, turn it off, as it will be regularly resetting your PIC.
Use
__CONFIG(0xd02);

or better still, using the newer syntax from post#26. That lets you see what you are doing.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#42
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:30:36 (permalink)
0
@ oliverb:
This is my interface TTL to USB, the hardware is powered by usb port and has a reset button.
 
 

Attached Image(s)

#43
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:39:24 (permalink)
0
For all:
- the code that use  print() work fine to send string by serial communication with my hardware,
- the code use pointer don't work, instead of a string it sends one or more unknown characters like in 34 post, with the same hardware.
#44
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:41:31 (permalink)
0
@ric:
OK, I'll try.
#45
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:47:29 (permalink)
+1 (1)
This is about the 4th time you have been asked.
Is there a ground connection from the USB-serial adaptor to your PIC''s ground?
I am NOT asking about the "USB power connection" you have mentioned several times.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#46
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:50:03 (permalink)
0
The bit is turned off but after reset I receive an unknown string(not Hello world).
#47
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:55:42 (permalink)
0
@ric:
No, on earth I have no connection, everything is disconnected from the earth.
And the PC's power outlet is not grounded.
 
#48
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re:Serial communication between PIC16F877 and computer 2019/11/11 04:57:17 (permalink)
+1 (1)
You misunderstand the point of my question.
You MUST have a ground connection between the USB-serial adaptor and the PIC.
There are three wires required.
TX, RX and ground.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#49
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 05:31:27 (permalink)
0
@pic:
Please see attached file.
#50
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 05:35:15 (permalink)
0
@ric...
#51
ric
Super Member
  • Total Posts : 24581
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re:Serial communication between PIC16F877 and computer 2019/11/11 12:13:10 (permalink)
0
ok, so you DO have a ground connection. You were not explicit that the "USB power" was coming from the USB-serial adaptor.
I would recommend adding a small delay (say 100 milliseconds) to your code before you send the string.
It would also be an idea to keep sending the string, with about a one second delay between each.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#52
AMPS
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 20:34:10 (permalink)
0
i would recommend you send full Schematic with PIC16F887. the code i shared its working code.
i have attached Schematic  for reference.
if u have USB to TTL converter Directly tap TX and RX and Make GND common.
In your schmatic there is no crystal oscillator. use proper ckts with 22pf capacitor.

Attached Image(s)


Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#53
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 23:02:42 (permalink)
0
@AMPS:
My laptop has no serial port but the usb / ttl adapter works fine. I did not receive your code
@ric:
OK, I'll try.
#54
AMPS
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/11 23:43:48 (permalink)
0
I have posted the code 
https://www.microchip.com/forums/m606767-p2.aspx
#33. 
USB to TTL is more than enough.The code written for 8Mhz 9600 baudrate. wiring simple shown in diagram
If using 11Mhz Crystal Kindly change
Use appropriate test condition in main while loop()
 
 
 #define _XTAL_FREQ 11.0592e6
 SPBRG=287; change in Init_uartfunction

Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#55
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/12 00:00:42 (permalink)
0
@ric:
With these delays, PIC don't send characters from the string (Hello World!), only the characters from the keyboard are echoed.
@AMPS:
Now I use 4Mhz, BRGH = 1 (HS), BR = 9600 -> SPBRG = 25; The echo character is sent correctly.
#56
AMPS
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/12 00:05:39 (permalink)
0
weather you get proper answer using my code. Now you modified the code as per requirement. there are various test example given where send and receive character, send and receive strings etc. That you can try it out.
 
if u getting garbage values
1) probably Gnd are not common
2) Serial Parameters are not set properly. The parameter INIT_UART()
3) Crystal oscillator ckt  where 22pf-30pf capacitor not used.
 
post edited by AMPS - 2019/11/12 00:07:54

Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#57
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/12 00:13:17 (permalink)
0
@RIC:
It sends string characters with delay(100, 1000), but more difficult, after PIC reset.
#58
AMPS
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/12 00:22:29 (permalink)
0
Now weather basic requirement is fulfilled, or still you have issue.
Now what exactly its doing and what problem ur facing. what is your expected answers.

Amps
*.*.*.*.*.*.*.*.*.*.*.*.*
#59
nidac
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2019/11/03 00:54:11
  • Location: 0
  • Status: offline
Re:Serial communication between PIC16F877 and computer 2019/11/12 00:31:01 (permalink)
0
@AMPS:
The problem is that I can't receive the whole string ("       Hello World!") on PC display, I only receive unknown characters, while the echo on the keyboard is received correctly.
#60
Page: < 12345 > Showing page 3 of 5
Jump to:
© 2019 APG vNext Commercial Version 4.5