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.

Pic18fj10 usart problems

Status
Not open for further replies.

Stefanovic

Newbie level 6
Joined
Jun 11, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
France
Activity points
1,358
Hello everybody,

I'm facing some stranges troubles with my simple UART c code.
My problem is that the first while of bonjour(); never ends, thus i cant send even the first byte. (
Here is the code,(no reception, just transmission) i really need help
thanks a lot !! :)

Code:
#include <htc.h>
#include <pic18f87j10.h>
#include <stdio.h>
#include <stdlib.h>

//----PIC Configuration bits-----
#pragma config	DEBUG = OFF		// debugger off
#pragma config	XINST = OFF		// extended instruction set disabled
#pragma config	STVREN = OFF            // stack overflow interrupt disabled
#pragma config	WDTEN = OFF		// WDT disabled
#pragma	config	CP0 = OFF		// code protection disabled
#pragma	config	FCMEN = OFF		// fail safe clock monitor disabled
#pragma config	IESO = OFF		// internal/external clock switch disabled
#pragma config	FOSC = HSPLL		// HS oscillator (PLL enabled, software control)
#pragma config	MODE = MM		// Microcontroller mode
#pragma config	ECCPMX = DEFAULT        // Default setting for ECCP1
#pragma	config	CCP2MX = DEFAULT	// Default setting for ECCP2
#pragma	config	FOSC2 = ON		// Clock selected by OSCCON bits



void init_uart (void) {

    OSCTUNE=0x40; //PLL x 4 with primary crystal at 10Mhz ==> 40Mhz with PLL

//----config port I/O-----
    PORTB=0x00;
    LATD=0x00;
    TRISB=0x01;       //RB0 out

    PORTD=0x00;
    LATD=0x00;
    TRISD=0x00;

    PORTC=0x00;
    LATC=0x00;
    TRISC=0x90;   //RC7(RX) in, RC6(TX) out,  ...

    TXREG1=0x00;
    RCREG1=0x00;

//----config regsitres uart----
    TXSTA1=0x24;        //TXEN=1, BRGH=1 high speed
    BAUDCON1=0x08;      //BRG16=1  (using two register to calculate Baud Rate)
    SPBRGH1=0x00;
    SPBRG1=0xAC;        //
    RCSTA1=0x90;        // SPEN=1,  CREN=1     serial port enabled,
}


void bonjour (void){

    TXREG1='b';
    while(TX1IF!=1){}
    TXREG1='o';
    while(TX1IF!=1){}
    TXREG1='n';
    while(TX1IF!=1){}
    TXREG1='j';
    while(TX1IF!=1){}
    TXREG1='o';
    while(TX1IF!=1){}
    TXREG1='u';
    while(TX1IF!=1){}
    TXREG1='r';
    while(TX1IF!=1){}
    TXREG1=0x0A;  //line feed ascii
}


void main (void) {

    init_uart();
    while(1){
        bonjour();
    }
}
 

I don't know PIC, but isn't TX1IF an interrupt flag or something? Not sure if that's a good way to know if the byte has been transmitted.
I could be wrong...
 

Thank you for your answer, in fact yes TX1IF is an interrupt flag,
i tried some other flags, but still not working,
any suggestion ? thanks
 

Hello, In fact for those who still have thoses problems, try to check USART integity,
yes, for me it burnt :))
so i tried the same code with USART 2 and it works
best regards :)
 

USART integity means???
actually i could transmit by using printf. but i clouldnt read from keyboard..
 

Sorry, i meant integrity, my first USART (EUSART1) had burnt :D

USART integity means???
actually i could transmit by using printf. but i clouldnt read from keyboard..

why can't you read from keyboard ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top