View previous topic :: View next topic |
Author |
Message |
Noland
Joined: 11 Dec 2011 Posts: 11 Location: Thailand
|
USART on PIC16F1947 |
Posted: Sat Jan 14, 2012 8:30 am |
|
|
Hello. If run 16F1947 at xtal 32MHz, USART error.
If run at xtal 8MHz or 4MHz USART work.
Code: |
#include <16F1947.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT
#use delay(clock=32M)
#use rs232(baud=9600, UART1, ERRORS)
int8 i;
int16 cnt;
#define delay_ms(x) \
cnt = x; \
while(cnt) \
{ \
for(i=0; i<8; i++) \
{ \
delay_cycles(250); \
delay_cycles(250); \
delay_cycles(250); \
delay_cycles(250); \
} \
cnt--; \
}
//====================================
void main()
{
int8 c;
printf("Start \n\r");
while(TRUE)
{
c = getc();
putc(c);
}
}
|
This code gives USART error. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sat Jan 14, 2012 10:01 am |
|
|
You have not setup the oscillator section ( the 'clock' ) correctly for 32MHz operation.
Please read the datasheet, and look at the diagram showing how the PIC can be configured for various 'clocks'.
The solution involves configuring the PLL into the clock section. |
|
|
Noland
Joined: 11 Dec 2011 Posts: 11 Location: Thailand
|
|
Posted: Sat Jan 14, 2012 12:00 pm |
|
|
the datasheet, page66
5.2.2.5 Internal Oscillator Frequency
Selection
32 MHz (requires 4X PLL)
but from http://www.ccsinfo.com/forum/viewtopic.php?p=154871#154871 Post reply by PCM programmer using, that code USART WORK
Code: | #include <16F1823.H>
#fuses INTRC_IO,NOWDT,NOPROTECT,MCLR
#use delay(clock=32M) |
What is so? the datasheet 16f1823 page61 Internal Oscillator Frequency 32 MHz (requires 4X PLL) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sat Jan 14, 2012 2:23 pm |
|
|
Those are two different PICs.......
You have to configure your PIC as per IT'S datasheet... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 16, 2012 2:37 pm |
|
|
If you need help with the UART on the 16F1947, then post your compiler version.
Also, in your post you refer to "xtal", which means a crystal, which means
this:
http://media.digikey.com/photos/ECS%20Photos/HC-49US.jpg
But your code shows "INTRC_IO" which is the internal oscillator, and does
not use a crystal.
But to repeat, make sure you post your compiler version. |
|
|
Noland
Joined: 11 Dec 2011 Posts: 11 Location: Thailand
|
|
Posted: Sun Jan 22, 2012 9:46 pm |
|
|
CCS V4.107 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 23, 2012 10:56 pm |
|
|
I was unable to make my 16F1947 breadboard work. Without that board,
it's not nearly as easy to find the problem. So I think I'm going to give up
on this problem. I'm just too busy at work to spend any more time on it. |
|
|
|