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.

Serial communication with PIC12F675

Status
Not open for further replies.

eng1

New Member
I have often used the PIC12675 to send data to the computer, using both C and assembly languages. I've recently added a few lines to receive a character and this causes problems.
So I wrote a program to debug my project. It's based on Nigel's serial routines with minor changes (GPIO, TRISIO); it receives a character and sends it back to the computer. It works correctly with the PIC12F629. If I use it with the PIC12F675 it doesn't send the character I type :eek: It sends 'literals' correctly, though.
Has anyone experienced similar difficulties?
Thanks
 

Attachments

  • s629.txt
    3.6 KB · Views: 617
Sure, CLRF ANSEL in Bank1. I will use the A/D converters later.
It receives the character but it sends another one back. Then it sends ":Ok" correctly. Same problem with C.
 
As far as I am aware, a 675 is a 629 with A2D added. The only other explanation is the addition of the extra instructions to turn off the A2D causes a page fault elsewhere. Try replacing the ANSEL code with NOPs so that the following code is at the same address.

Mike
 
Are you sure the OSCCAL value is correct in the 12F675?, it hasn't inadvertently been changed?.

I would suggest the receive routine isn't working accurately enough?, presumably the timing is off a little?.
 
I've got an interrupt driven 9600 baud half duplex demo you're welcome to look at if it will help.

Code:
;******************************************************************
;*                                                                *
;*  Filename: 12F675 Serial Demo 3.asm                            *
;*    Author: Mike McLaren, K8LH   (k8lh@arrl.net)                *
;*      Date: 16-Jan-06  (last revision 17-Jan-06)                *
;*                                                                *
;*   Half Duplex Bit-Banged 9600 Baud Serial I/O Demo             *
;*    (2-Pin Version with 8-Byte Circular RX Buffer)              *
;*                                                                *
;*  ·Uses 12F675 INTOSC running at 4-MHz                          *
;*  ·Bit rate error 0.16% plus or minus 1.0% for INTOSC           *
;*  ·Bit-banged 9600 baud serial I/O                              *
;*    ·Half Duplex (should not TX and RX simultaneously)          *
;*    ·TMR0 interrupts at 104-usec intervals (every 104           *
;*     instruction cycles) and IOC (interrupt on change)          *
;*     for RX start bit leading edge detection on RXPIN           *
;*    ·Circular 8-byte RX character buffer                        *
;*    ·Inverted TX and RX signals (MAX232A or similar             *
;*     inverting RS-232 interface required)                       *
;*  ·Relatively small - the ISR and the support routines          *
;*   Init232, Put232, Get232, and PutString use 124 words         *
;*   of code space at locations 0004 through 007F and 20          *
;*   of 64 RAM locations for variables and RX buffer...           *
;*  ·Worst case 51% ISR instruction cycle 'overhead'              *
;*   (54-usecs) when a complete RX character is added to          *
;*   the circular buffer once every 1.04-msecs...                 *
;*                                                                *
;*     MPLab: 7.30    (tabs=8)                                    *
;*     MPAsm: 5.01                                                *
;*                                                                *
;******************************************************************
 

Attachments

  • 12F675 Serial Demo 3.txt
    13.1 KB · Views: 674
Last edited:
Nigel, I tried the program with a crystal and it's working as I expected :)
I also tried your routines, Mike :)
Can I still use GPIO3 as an input if I clear the MCLRE fuse, as I usually do when I choose the internal oscillator?
 
eng1 said:
I also tried your routines, Mike :)
Can I still use GPIO3 as an input if I clear the MCLRE fuse, as I usually do when I choose the internal oscillator?
That demo program is already using GP3 as an input for the RS232 port. You can change the pin assignments by changing the TXPIN and RXPIN defines but be sure to download the revised source file that I'll upload in a couple minutes (I needed to change 1 line of code to allow support for other TXPIN and RXPIN assignments. Sorry.)

Mike
 
I used GP3 as an input with your routines and I changed TXPIN to GPIO2 succesfully, since GPIO4:5 are connected to the crystal now.
Don't worry about the TXPIN assigment, I've found it :)
In my previous projects I always placed a pull-up resistor on the MCLR pin when the external oscillator was selected. I've never thought to use the crystal with MCLR tied to Vdd internally. It's working, I just want to be sure that it's correct. Thanks
 
Last edited:
So you've got it working then? That's great! I forgot to say that I also use a pull-up resistor on the GP3 RXPIN. Sorry...

Have fun. Regards, Mike

**broken link removed**
**broken link removed**
 
Last edited:
Yes :) I'll write the code to configure the analog inputs and read GPIO0, with Vref on GPIO1. It's the fisrt time I've had issues with the internal oscillator, but there are enough pins fortunately.
 
I've never had problems with the INTOSC and I've done several 12F675 and 12F683 projects. May I ask what problems you were having?
 
I was writing a program in C. When the PIC gets a character ('a') it has to start an A/D conversion and send the result. But it was looping continuosly and the conversion never started. In order to debug that program I used assembly routines, that are well documented. Transmission worked perfectly but the received characters were not sent back correctly:
Sent: a (97) received: 161 mainly and 225 sometimes
Sent: b (98) received: 162 mainly and 226 sometimes
...
Unfortunately I don't have another PIC12F675 or 683 handy.
 
Last edited:
And you think that has something to do with the INTOSC?

Bit-banged serial I/O at 9600 baud using the 4-MHz INTOSC is extrememly time critical. Are you sure the problem wasn't caused by normal timing anomolies in the C program itself?

Mike
 
Mike said:
And you think that has something to do with the INTOSC?

Bit-banged serial I/O at 9600 baud using the 4-MHz INTOSC is extrememly time critical. Are you sure the problem wasn't caused by normal timing anomolies in the C program itself?

He was also trying the serial routines from my tutorial, which are tried and tested using internal oscillators and have always worked fine - I would imagine he's corrupted the OSCCAL value somehow?.
 
Mike said:
And you think that has something to do with the INTOSC?
Yes.

Nigel Goodwin said:
He was also trying the serial routines from my tutorial, which are tried and tested using internal oscillators and have always worked fine - I would imagine he's corrupted the OSCCAL value somehow?
And I've always used them succesfully with the PIC16F628A, PIC16F88, PIC16F629 and their internal oscillator.

I could test this PIC12F675 with a known delay loop, but with the crystal the three programs work perfectly!
 
Status
Not open for further replies.

Latest threads

Back
Top