Requesting assistance with PIC18F67K40 EUSART4 configuration

Requesting assistance with PIC18F67K40 EUSART4 configuration

Postby chrislong1234567890 » Fri Oct 05, 2018 8:34 pm

I tried to post this in the other forum without success. Many thanks to the admins of this site for hosting another place to seek help.

I am using the PIC18F67K40 on the MikroElectronika Clicker 2, and I am trying to configure EUSART4 to output a string to the terminal. As you can see in the Clicker 2 User Manual EUSART4 TX and RX are connected to the FT232RL chip.
I am using MPLAB X 4.20, XC8 v1.45 compiler, and the ICD3. I set "+NVMREG in the Project->Properties->XC8 Linker->Additional options->Errata box" as instructed in another post.

The following code is supposed to print to the terminal and toggle both of the LEDs on the Clicker 2. The LEDs toggle but nothing appears on the terminal (via Tera Term). I have not tried to probe these pins because they are not connected to any of the break out pins. I did try to setup EUART3 with the same settings as I set for EUSART4 (and made sure to edit my putchar() with the updated peripheral) and probed with a Digilent Analog Discovery 2 on RB5-RX and RB4-TX. I did not see any output. This leads me to believe that my understanding of the way the peripheral is configured is flawed, but there is a very good chance I am missing something else as well. Thank you for your help.


Code: Select all
#pragma config FEXTOSC = HS     
#pragma config RSTOSC = EXTOSC_4PLL

#define _XTAL_FREQ      64000000L
#define LED1            LATDbits.LATD7
#define LED2            LATHbits.LATH3

#include <xc.h>
#include <stdio.h>

void putch(char);

void main(void)
{

    INTCONbits.GIE = 0;
    INTCONbits.PEIE = 0;

    TRISCbits.TRISC0 = 0;   //TX4
    TRISCbits.TRISC1 = 1;   //RX4
    TRISDbits.TRISD7 = 0;   //LED1 on Clicker2
    TRISHbits.TRISH3 = 0;   //LED2 on Clicker2

    RC0PPS = 0x12;          //RC0->EUSART4:TX4
    RX4PPS = 0x11;          //RC1->EUSART4:RX4
   
   
    //*****USART4*********************************************************/
    SP4BRGH = 0x00; //64MHz Fosc and 9600 baud; SYNC = 0, BRGH = 0, BRG16 = 0
    SP4BRGL = 0x67;

    TXSTA4bits.BRGH = 0;    //High Baud Rate Select bit; 1 = High speed
    BAUDCON4bits.BRG16 = 0; //16-Bit Baud Rate Register Enable bit
    TXSTA4bits.SYNC = 0;    //EUSART Mode Select bit; 0 = Asynchronous mode
    RCSTA4bits.SPEN = 1;    //Serial Port Enable bit
    TXSTA4bits.TX9 = 0;     //8bit transmission
    TXSTA4bits.TXEN = 1;    //Transmit Enable bit

    RCSTA4bits.RX9 = 0;     //8bit reception
    RCSTA4bits.CREN = 1;    //Enables Receiver
   
    LED1 = 0;
    LED2 = 1;
   
    while (1) {
       
        printf("Hello World!");
        __delay_ms(1000);
       
        LED1 = ~LED1;
        LED2 = ~LED2;
    }
}

void putch(char data)
{
    while (!PIR4bits.TX4IF) //USART4 - Terminal
        continue;
    TXREG4 = data;
}


Edit: I applied all of the recommended changes. The code works as intended. Thank you all for your help.
Last edited by chrislong1234567890 on Mon Oct 08, 2018 6:31 pm, edited 2 times in total.
chrislong1234567890
 
Posts: 2
Joined: Fri Oct 05, 2018 7:50 pm

Re: Requesting assistance with PIC18F67K40 EUSART4 configura

Postby jtemples » Fri Oct 05, 2018 9:39 pm

I see 0x12 in the data sheet for TX4 PPS, not 0x10.

Unrelated to your problem: don't enable interrupts when you're not using them, there's no need to unlock PPS (it's unlocked by default), and there's no need to specify the DEBUG configuration fuse (you have no control over it).
jtemples
Verified identity
 
Posts: 173
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: Requesting assistance with PIC18F67K40 EUSART4 configura

Postby chrislong1234567890 » Fri Oct 05, 2018 9:53 pm

Thank you for your help. After I edited RC0PPS = 0x12; the program now works as expected.
chrislong1234567890
 
Posts: 2
Joined: Fri Oct 05, 2018 7:50 pm

Re: Requesting assistance with PIC18F67K40 EUSART4 configura

Postby ric » Fri Oct 05, 2018 11:02 pm

As jtemples pointed out, you don't need to enable interrupts to poll the TXIF flag.
The comments on these lines are wrong
Code: Select all
    PIE4bits.RC4IE = 0;     //ENABLE USART receive interrupt
    PIE4bits.TX4IE = 0;     //ENABLE USART TX interrupt

they are disabling, not enabling

Code: Select all
    /*Enable Global/Peripheral interrupts*/
    INTCONbits.GIE = 1;     //Enable global interrupts
    INTCONbits.PEIE = 1;    //Enable peripheral interrupts

and you should NOT enable GIE if you don't have in interrupt service routine in place. Just remove those two lines for now.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 454
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Requesting assistance with PIC18F67K40 EUSART4 configura

Postby AussieSusan » Mon Oct 08, 2018 2:44 am

I'm not sure what IDE and compiler you are using but i general you should never set the DEBUG config option. Let the IDE control that as needed - there are things that happen behind the scenes that need to be coordinated with that config setting.
Susan
AussieSusan
Verified identity
 
Posts: 93
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist


Return to SCI/USART/EUSART

Who is online

Users browsing this forum: No registered users and 2 guests