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.

[SOLVED] problems when configuring pic18f26j50

Status
Not open for further replies.
hello again, I continue with the same project and is working well.
But now I can not UART2 work. I'll post the code that makes the UART1
work, I tried to do the same thing with the UART2 but got no results
Code:
/* 
 * File:   main.c
 * Author: Tiago Ribeiro
 *
 * Created on 25 de Novembro de 2013, 08:49
 */
#include <p18f26j50.h>
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
#include <string.h>
#include <usart.h>


#pragma config XINST = OFF // Extended Instruction Set (Enabled)
#pragma config WDTEN = OFF // Watchdog Timer (Disabled - Controlled by SWDTEN bit)
#pragma config OSC = HS
#pragma config STVREN = OFF
#pragma config DEBUG = OFF
#pragma config CP0 = OFF
#pragma config IESO = OFF

#define _XTAL_FREQ 12000000
/*
 *FOSC= 12MHZ
 * Tciclo=4/FOSC = 0,333 us
 */

    void inicia(void){

        LATCbits.LATC2 = 1;
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        LATCbits.LATC2 = 0;
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        LATCbits.LATC2 = 1;
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);

        TRISCbits.TRISC6 = 0;//saida = 0
	TRISCbits.TRISC7 = 1;//entrada = 1

	/***TX Configuration************/
	TXSTA1bits.CSRC  = 0;      //
	TXSTA1bits.TX9   = 0;      //Selects 8-bit transmission
	TXSTA1bits.TXEN  = 1;      //Transmit is enabled
	TXSTA1bits.SYNC  = 0;      //Asynchronous mode
	TXSTA1bits.SENDB = 0;      //dont Send Sync Break on next transmission (cleared by hardware upon completion)
	TXSTA1bits.BRGH  = 1;      //High speed
	/***RX Configuration************/
	RCSTA1bits.SPEN  = 1;      //Serial port is enabled
	RCSTA1bits.RX9   = 0;      //Selects 8-bit reception
	RCSTA1bits.CREN  = 1;      //Enables the receiver
	RCSTA1bits.ADDEN = 0;      //Disables address detection, all bytes are received and ninth bit can be used as parity bit
	/***BAUDRATE Configuration************/
	BAUDCON1bits.ABDOVF = 0;   //No BRG rollover has occurred
	BAUDCON1bits.RXDTP  = 0;   //Receive data (RXx) is not inverted (active-high)
	BAUDCON1bits.TXCKP  = 0;   //Idle state for transmit (TXx) is a high level
	BAUDCON1bits.BRG16  = 0;   //8-bit Baud Rate Generator ? SPBRGHx and SPBRGx
	BAUDCON1bits.WUE    = 0;   //RXx pin is not monitored or the rising edge detected
	BAUDCON1bits.ABDEN  = 0;   //Baufrate Measurement is Disable

	SPBRGH1 =  0;    //EUSART1 Baud Rate Generator Register High Byte
	SPBRG1	= 77;    //EUSART1 Baud Rate Generator Register Low Byte

                         //

        Open1USART(USART_TX_INT_OFF &
                   USART_RX_INT_OFF &
                   USART_ASYNCH_MODE &
                   USART_EIGHT_BIT &
                   USART_CONT_RX &
                   USART_BRGH_HIGH,77);   

/**************************Config pin I/O USART2*****************************/
        ANCON0bits.PCFG0 = 1; //Setando pino AN0 (analogico) para Digital
        ANCON0bits.PCFG1 = 1; //Setando pino AN1 (analogico) para Digital
        
        TRISAbits.TRISA0 = 1;//entrada = 1
        TRISAbits.TRISA1 = 0;//saida = 0
        /***TX 2 Configuration************/
	TXSTA2bits.CSRC  = 0;      //
	TXSTA2bits.TX9   = 0;      //Selects 8-bit transmission
	TXSTA2bits.TXEN  = 1;      //Transmit is enabled
	TXSTA2bits.SYNC  = 0;      //Asynchronous mode
	TXSTA2bits.SENDB = 0;      //dont Send Sync Break on next transmission (cleared by hardware upon completion)
	TXSTA2bits.BRGH  = 1;      //High speed
	/***RX 2 Configuration************/
	RCSTA2bits.SPEN  = 1;      //Serial port is enabled
	RCSTA2bits.RX9   = 0;      //Selects 8-bit reception
	RCSTA2bits.CREN  = 1;      //Enables the receiver
	RCSTA2bits.ADDEN = 0;      //Disables address detection, all bytes are received and ninth bit can be used as parity bit
	/***BAUDRATE 2 Configuration************/
	BAUDCON2bits.ABDOVF = 0;   //No BRG rollover has occurred
	BAUDCON2bits.RXDTP  = 0;   //Receive data (RXx) is not inverted (active-high)
	BAUDCON2bits.TXCKP  = 0;   //Idle state for transmit (TXx) is a high level
	BAUDCON2bits.BRG16  = 0;   //8-bit Baud Rate Generator ? SPBRGHx and SPBRGx
	BAUDCON2bits.WUE    = 0;   //RXx pin is not monitored or the rising edge detected
	BAUDCON2bits.ABDEN  = 0;   //Baufrate Measurement is Disable

	SPBRGH2 =  0;    //EUSART2 Baud Rate Generator Register High Byte
	SPBRG2	= 155;    //EUSART2 Baud Rate Generator Register Low Byte
                         //

        Open2USART(USART_TX_INT_OFF &
                   USART_RX_INT_OFF &
                   USART_ASYNCH_MODE &
                   USART_EIGHT_BIT &
                   USART_CONT_RX &
                   USART_BRGH_HIGH,155);
        
        while(1){
        char dado[]="";
        char data[]="ATD";
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        puts1USART(data);
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        puts1USART(data);
        Delay10KTCYx(200);
        Delay10KTCYx(100);
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        gets2USART(dado,5);
        Delay10KTCYx(200);         // Delay de estabilização do circuito, tensões, etc....
        Delay10KTCYx(100);
        puts1USART(dado);
        }
}
    
    
    void main(void){
    inicia();
    
}
 

did not work...I tried using the function sw_uart.h modifying the pins patterns of function did not work..
you think the UART2 pic18f26j50 works with the function usart.h like the usart1?
I'm asking because this pic UART2 must be remapped between analog pins,
it does not come ready as come in usart1 .. what do you think?
thank you for helping me so much:-D
 

Nevermind, I found the solution to make usart2 work ... I'll post here what I did
Code:
    #include <pps.h>

     PPSUnLock();//FUNÇÃO DE REMAPEAMENTO DOS PINOS
     iPPSOutput(OUT_PIN_PPS_RP1, OUT_FN_PPS_TX2CK2);//CONFIGURA O PINO TX (RP1)
     iPPSInput(IN_FN_PPS_RX2DT2, IN_PIN_PPS_RP0); //CONFIGURA O PINO RX (RP0)
     PPSLock();
This function is to use the pin remapping available in pic ... so I used and configured according to my need and it worked ...
Thank you again. = D
 

Do you have working code for PIC18F4550 and software uart?
 

for PIC18F4550 is not much different ... functions as openUSART or baudUSART configuration MPLABX sometimes do not work right, then you need to configure the registers of the TX and RX pins and baud rate of each USART ... see datasheet to know the registers
Code:
/***TX 2 Configuration************/
	TXSTA2bits.CSRC  = 0;      //
	TXSTA2bits.TX9   = 0;      //Selects 8-bit transmission
	TXSTA2bits.TXEN  = 1;      //Transmit is enabled
	TXSTA2bits.SYNC  = 0;      //Asynchronous mode
	TXSTA2bits.SENDB = 0;      //dont Send Sync Break on next transmission (cleared by hardware upon completion)
	TXSTA2bits.BRGH  = 1;      //High speed
	/***RX 2 Configuration************/
	RCSTA2bits.SPEN  = 1;      //Serial port is enabled
	RCSTA2bits.RX9   = 0;      //Selects 8-bit reception
	RCSTA2bits.CREN  = 1;      //Enables the receiver
	RCSTA2bits.ADDEN = 0;      //Disables address detection, all bytes are received and ninth bit can be used as parity bit
	/***BAUDRATE 2 Configuration************/
	BAUDCON2bits.ABDOVF = 0;   //No BRG rollover has occurred
	BAUDCON2bits.RXDTP  = 0;   //Receive data (RXx) is not inverted (active-high)
	BAUDCON2bits.TXCKP  = 0;   //Idle state for transmit (TXx) is a high level
	BAUDCON2bits.BRG16  = 0;   //8-bit Baud Rate Generator ? SPBRGHx and SPBRGx
	BAUDCON2bits.WUE    = 0;   //RXx pin is not monitored or the rising edge detected
	BAUDCON2bits.ABDEN  = 0;   //Baufrate Measurement is Disable
these are the registers that I used registers for pic18f26j50
if you have any question back here to ask
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top