Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic16f877 serial recieve acting screwy

Status
Not open for further replies.

masconejos

New Member
I am working on a project involving the pic16f877, programming using Hi-Tech C complier and MPLAB 6.x.

I have gotten the pic to send data just fine over the serial port. However, recieving is not working. When I first poer the pic on it will recieve several bytes of garbage and an overflow error on the serial recieve pin, even when the serial port to the computer is disconnected. Any attempts to actually recieve data do not work when polling the recieve register (interrupts disabled). When interrupts are enabled, when powering on the pic, it will generate exactly 3 interrupts, print off several bytes of garbage, and get an overflow error. This happens regardless of if it is connected to the serial or not. When it is connected to the serial, it won't generate or respond to serial data coming in. (This is after a lot of fuss to make sure all the error pins are clear, the recieve register, etc). It gets better though. In the interrupt, when I tell it to echo back serially to the computer what it receives, it generates exactly 12 interrupts of garbage, and a simple function I have at the very begining of the program to print a test string serially to the computer, which has been working fine all this time, no longer works correctly and will just print out garbage to the computer.

I've spent many hours trying everything I can think of to debug this, including using a second pic in-case mine is damaged (its not; second pic does the same thing). Any suggestions on solving this would be appreciated.
 
Have you tried clearing all error bits first before enabling CREN?

You have to read the RCREG register until the FERR bit is cleared.

To clear OERR bit, you have to clear the CREN bit.

You have to constantly monitor these bits or the UART stops receiving if any of them are set.
 
Yes I've tried that too, enabling and disabling CREN on error, and reading RCREG a multitude of times, and even after I've made absolutely sure everything is cleared, and running properly, it still misbehaves.
 
As far as the usart goes, I want to read from a ds1820 to get the temperature. I have looked over the datasheet and it seems fine but I was reading somewhere else that you have to disable interrupts to get the timing right. The USART is an interrupt right, do I need to disable it during reads?
 
Zacman said:
As far as the usart goes, I want to read from a ds1820 to get the temperature.

Does this mean you're trying to read from a ds1820 using the USART?, I don't know about this particular chip, but usually they don't output RS232 - does this one?.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top