• AVR Freaks

Helpful ReplyHot!HOW TO COFIGURE UART FOR PIC18F47Q43?

Author
zoopi
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2020/03/28 04:39:38
  • Location: 0
  • Status: offline
2020/03/30 21:15:25 (permalink)
0

HOW TO COFIGURE UART FOR PIC18F47Q43?

Trying to use UART of latest PIC18F47Q43. I have done some configurations according to the datasheet, But it's not giving any output, I think there is something more to add to the code. Am adding the code below. It would be great if somebody can help. Thanks in advance.
 
 
 
#1
pcbbc
Super Member
  • Total Posts : 1691
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 07:15:45 (permalink)
+3 (3)
You haven't set any PPS mapping for the output pins.
RxyPPS = 0x20; //UART1 TX PPS output

Replace x with the port letter and y with the pin number.
Edit: The default for all RxyPPS registers is 0x00 = LATx output (i.e. not the specialist hardware peripheral).
 
This code...
PIE4bits.U1TXIE = 1;

...is pointless/unnecessary, and will cause a lockup if you ever enable interrupts (as you don't have an ISR enabled).
post edited by pcbbc - 2020/03/31 07:20:25
#2
zoopi
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2020/03/28 04:39:38
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 22:06:31 (permalink)
0
@pcbbc Thanks for your support. The interrupt was one problem like you said. I just disabled it. Now the transmitter is trying to emit something but its not in a readable format. I think there is some more error with baud rate section.  Attaching the screenshot of Uart terminal and the updated code.

Attached Image(s)

#3
ric
Super Member
  • Total Posts : 27115
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 22:15:58 (permalink) ☄ Helpfulby zoopi 2020/04/01 02:08:03
+2 (2)
You did not show any CONFIG settings.
How fast is your PIC running?
 
What hardware do you have connected from your PIC to your PC?
I hope there is a MAX232 style buffer between your PIC's TX pin and an RS232 type connector.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
zoopi
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2020/03/28 04:39:38
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 23:22:11 (permalink)
0
it's running on 16Mhz External oscillator. Posting the configuration below.
 
#pragma config FEXTOSC = ECH // External Oscillator Selection (EC (external clock) above 8 MHz)
#pragma config RSTOSC = EXTOSC // Reset Oscillator Selection (EXTOSC operating per FEXTOSC bits (device manufacturing default))
// CONFIG2
#pragma config CLKOUTEN = OFF // Clock out Enable bit (CLKOUT function is disabled)
#pragma config PR1WAY = ON // PRLOCKED One-Way Set Enable bit (PRLOCKED bit can be cleared and set only once)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
// CONFIG3
#pragma config MCLRE = EXTMCLR // MCLR Enable bit (If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR )
#pragma config PWRTS = PWRT_64 // Power-up timer selection bits (PWRT is disabled)
#pragma config MVECEN = ON // Multi-vector enable bit (Multi-vector enabled, Vector table used for interrupts)
#pragma config IVT1WAY = ON // IVTLOCK bit One-way set enable bit (IVTLOCKED bit can be cleared and set only once)
#pragma config LPBOREN = OFF // Low Power BOR Enable bit (Low-Power BOR disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bits (Brown-out Reset disabled)
// CONFIG4
#pragma config BORV = VBOR_1P9 // Brown-out Reset Voltage Selection bits (Brown-out Reset Voltage (VBOR) set to 1.9V)
#pragma config ZCD = OFF // ZCD Disable bit (ZCD module is disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON)
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit (PPSLOCKED bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle)
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON // Low Voltage Programming Enable bit (Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Extended Instruction Set and Indexed Addressing Mode disabled)
// CONFIG5
#pragma config WDTCPS = WDTCPS_31// WDT Period selection bits (Divider ratio 1:65536; software control of WDTPS)
#pragma config WDTE = OFF // WDT operating mode (WDT Disabled; SWDTEN is ignored)
// CONFIG6
#pragma config WDTCWS = WDTCWS_7// WDT Window Select bits (window always open (100%); software control; keyed access not required)
#pragma config WDTCCS = SC // WDT input clock selector (Software Control)
// CONFIG7
#pragma config BBSIZE = BBSIZE_512// Boot Block Size selection bits (Boot Block size is 512 words)
#pragma config BBEN = OFF // Boot Block enable bit (Boot block disabled)
#pragma config SAFEN = OFF // Storage Area Flash enable bit (SAF disabled)
#pragma config DEBUG = OFF // Background Debugger (Background Debugger disabled)
// CONFIG8
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block not Write protected)
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers not Write protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not Write protected)
#pragma config WRTSAF = OFF // SAF Write protection bit (SAF not Write Protected)
#pragma config WRTAPP = OFF // Application Block write protection bit (Application Block not write protected)
// CONFIG10
#pragma config CP = OFF // PFM and Data EEPROM Code Protection bit (PFM and Data EEPROM code protection disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 16000000
#include <xc.h>
#include "uart.h"
 
 
   
#5
zoopi
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2020/03/28 04:39:38
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 23:40:35 (permalink)
0
@ric it's running on 16Mhz External oscillator. And I am using MAX232 to communicate with PC. Posting the configuration below.
 
#pragma config FEXTOSC = ECH 
#pragma config RSTOSC = EXTOSC
// CONFIG2
#pragma config CLKOUTEN = OFF 
#pragma config PR1WAY = ON
#pragma config CSWEN = ON 
#pragma config FCMEN = ON
// CONFIG3
#pragma config MCLRE = EXTMCLR 
#pragma config PWRTS = PWRT_OFF 
#pragma config MVECEN = ON
#pragma config IVT1WAY = ON 
#pragma config LPBOREN = OFF 
#pragma config BOREN = OFF
// CONFIG4
#pragma config BORV = VBOR_1P9 
#pragma config ZCD = OFF 
#pragma config PPS1WAY = ON
#pragma config STVREN = ON 
#pragma config LVP = ON 
#pragma config XINST = OFF
// CONFIG5
#pragma config WDTCPS = WDTCPS_31
#pragma config WDTE = OFF
// CONFIG6
#pragma config WDTCWS = WDTCWS_7
#pragma config WDTCCS = SC
// CONFIG7
#pragma config BBSIZE = BBSIZE_512
#pragma config BBEN = OFF 
#pragma config SAFEN = OFF 
#pragma config DEBUG = OFF
// CONFIG8
#pragma config WRTB = OFF 
#pragma config WRTC = OFF 
#pragma config WRTD = OFF 
#pragma config WRTSAF = OFF 
#pragma config WRTAPP = OFF
// CONFIG10
#pragma config CP = OFF

#define _XTAL_FREQ 16000000
#include <xc.h>
#include "uart.h"
 
 
 
#6
pcbbc
Super Member
  • Total Posts : 1691
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 23:42:51 (permalink)
+1 (1)
16MHz and BRG = 103 would seem to indicate 9600 baud.
Why then does the terminal window say 14400 bps?
#7
zoopi
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2020/03/28 04:39:38
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/03/31 23:50:27 (permalink)
0
@pcbbc Sorry for that. Even if it's in 9600bits it's not in a readable format. attaching image below.

Attached Image(s)

#8
pcbbc
Super Member
  • Total Posts : 1691
  • Reward points : 0
  • Joined: 2014/03/27 07:04:41
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/04/01 00:02:21 (permalink) ☄ Helpfulby zoopi 2020/04/01 02:07:50
+2 (2)
Try adding a delay after you start before sending anything. Clock may not be up to speed and system may not be steady state.
Better still send repeatedly in the main loop (with a delay between each transmission).
I assume your 2 second period on port D outputs is working and so you have established PIC clock speed is correct?
#9
zoopi
New Member
  • Total Posts : 20
  • Reward points : 0
  • Joined: 2020/03/28 04:39:38
  • Location: 0
  • Status: offline
Re: HOW TO COFIGURE UART FOR PIC18F47Q43? 2020/04/01 02:06:49 (permalink)
+1 (1)
@pcbbc Its rectified now. When you reminded about clock speed. I just checked it. It was not the delay of 2 seconds that getting on PORTD. And the problem was I chose the wrong oscillator configuration in    #pragma config FEXTOSC  
it was                 #pragma config FEXTOSC = ECH
Changed it to      #pragma config FEXTOSC = HS
and the problem is solved now. 
Now I want to use 3 of those UART in this chip I will post if there is any help needed.
@pcbbc @ric Thanks for the support and helpSmile: Smile.

Attached Image(s)

#10
Jump to:
© 2020 APG vNext Commercial Version 4.5