Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic12f1840 uart not working

Status
Not open for further replies.

burrow

Full Member level 2
Joined
Dec 15, 2014
Messages
147
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
1,148
Hai,
I am not able to make UART module of PIC12F1840 work, I have tried all possible way outs.But it simply doesnt seem to work.. I have attached my code below

Code:
void main() {

TRISA.TRISA0=0;
TRISA.TRISA1=1;

ANSELA=0;
ANSELA.ANSA0=0;
ANSELA.ANSA1=0;


OPTION_REG.TMR0CS=0;
OPTION_REG.PSA=0;
OPTION_REG.PS2=1;
OPTION_REG.PS1=1;
OPTION_REG.PS0=1;

APFCON.TXCKSEL=0;
ADCON0.ADON=0;
DACCON0.DACEN   =0;
SRCON0.SRLEN=0;
CM1CON0.C1ON=0;
MDCON.MDEN=0;

TXSTA.SYNC=0;
TXSTA.TXEN=1;
TXSTA.BRGH=0;
RCSTA.SPEN=1;
TXSTA.TX9=0     ;
BAUDCON.BRG16=1;
SPBRG=207;
 
 

UART1_Init(9600);                         // initialize UART1 module
Delay_ms(100);

       while(1)
       {
          UART1_WRITE_TEXT("hello");
          Delay_ms(100);
       
       }

 


}

I am using internal clock set to 32.000 Mhz
 

As you are using mikroC PRO PIC the
Code:
UART1_Init()
function will configure the UART module (registers). You don't have to configure them manually. Remove your manual configurations and in project settings check whether you have selected the right type of Oscillator. Have you turned OFF Comparators ?
 

Hai...thanks for the reply.. I found out the bug.. Seems like the serial communication is working. But its taking hell lot of time..I just gave delay of 100 ms but its taking much more time.. a couple of seconds actually..

And i tried debugging in proteus The Baudrate seems to get reset to 150bps
 
Last edited:

Problem is with Oscillator Configuration. Whay OSC type you are using ? Internal RC ? What is the FOSC ?
 

Yea iam using internal Osc.
Fosc=32.000Mhz

- - - Updated - - -

I changed it to 8mhz now.. debug.jpg
 

You have to enable PLL and configure
Code:
OSCCON
register. First line of
Code:
void main() { ... }
should be OSCCON configuration. Additionally you can also configure
Code:
OSCTUNE
register.

See if there is option to Enable 4x PLL in project settings. Try these.

Code:
OSCCON = 0x6F;
OSCTUNE = 0x00;
 
Last edited:

Are you sure i have to specify it if iam using Mikroc, I think Mikroc does it by default
 

If your PIC has OSCCON register then you have to configure it manually. Check datasheet Oscillator section. In that check registers section. If there is no option to enable 4x PLL in project properties dialog then you have to do it in code. Also even if you enable PLL in project settings you have to configure OSCCON manually. You can choose 8 MHz Internal Oscillator with 4x PLL to get 32 MHz. Not all baudrates are generated for all FOSC. There will be baudrate error. In Proteus even if you use 32 MHz FOSC you have to set it to 8 MHz.
 

hello,


you can find many (tested in real world ) examples **broken link removed** .
 
  • Like
Reactions: burrow

    burrow

    Points: 2
    Helpful Answer Positive Rating
Thanksfor the link.. and sorry for late reply.. was away from forum for few weeks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top