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.

[PIC] PIC24FJ258GB110 using USB-Host and UART simultaneously Baud Rate Issue

Status
Not open for further replies.

mandarsansare

Newbie level 6
Newbie level 6
Joined
Apr 28, 2012
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Thane,Maharashtra,IN
Visit site
Activity points
1,381
I am using USB host code from Microchip MLA.
The USB and LCD part is working fine but i want to add UART functionality in the project.
I want to send keyboard key-press to UART port.
I added UART code part from my previously working project. But after adding to the USB code it is not working faithfully . The baud rate setting collapse badly. I guess the problem is with Configuration bit settings.Here is my config bits

Code:
// CONFIG3
#pragma config WPFP = WPFP511
#pragma config WPDIS = WPDIS
#pragma config WPCFG = WPCFGDIS
#pragma config WPEND = WPENDMEM

//CONFIG2
#pragma config POSCMOD = XT
#pragma config DISUVREG = OFF
#pragma config IOL1WAY = ON
#pragma config OSCIOFNC = OFF
#pragma config FCKSM = CSECME
#pragma config FNOSC = PRIPLL
#pragma config PLL_96MHZ = ON
#pragma config PLLDIV = DIV2
#pragma config IESO = ON

// CONFIG1
#pragma config WDTPS = PS32768
#pragma config FWPSA = PR128
#pragma config WINDIS = OFF
#pragma config FWDTEN = OFF
#pragma config ICS = PGx2
#pragma config GWRP = OFF
#pragma config GCP = OFF
#pragma config JTAGEN = OFF

What else can cause problem? Please Help.
I am using 8MHz crystal.
Thanks in advance.
 

If USB is working fine, the problem isn't with your configuration, it's with CLKDIV register and baud rate generator settings.

Please consider that the peripheral clock with USB operation will be either 32, 16, 8 or 4 MHz, depending on CLKDIV. I believe there are UART examples for PIC24xxGB in Microchip application library.
 

I tried each frequency.
Default value of CPDIV=00 thus making system clock =32MHz and Fcy for UART=16MHz.
But when i try loading values into UxBRG according to this calculations it doesn't respond properly for that baud rate.
but it give response (some false value like 0XFF, 0XFB, 0XDB FOR ANY KEY-PRESS) to some other baud rate.. by considering this I back calculated the Fcy -> it is coming around 48Mhz.
e.g uxbrg=103 for BR=9600 @ 16mhz. but the time response of uart is coming at BR=28800.

one more doubt: is peripheral clock related to uart operation ?
 

peripheral clock and system clock are different in following document.
PIC24FJ256GB110 FAMILY DATA SHEET (DOCUMENT NO. DS39897C) PAGE NO: 121
https://ww1.microchip.com/downloads/en/DeviceDoc/39897c.pdf

observed clock frequency comes as 48MHz by reverse calculation
we are sending 16 characters in burst and receiving same number of bytes (not same value) at baud rate =14400
14400*16*104 ~ 24MHz *2= 48MHz
 

O.K. 48 MHz is what I also see in appplication library example "Device - CDC - Serial Emulator".

But I don't see it stated in the datasheet. E.g. the UART chapter is clearly referring to fcy rather than fusb.
 

You need to back up a little bit here. There are 4 completely separate areas that you need to get right and I think you might be getting some of these a bit confused.
The first is the config bits that you showed us in the first post. They tell us that you are using an XT crystal (you mention 8MHz in your post) as the primary source that is feeding the PLL with a divide by 2 feedback which is all correct to derive the 48MHz needed for the USB clock source.
The second part is the oscillator section setup. You mention above that you have CPDIV = 0 which means the PERIPHERAL clock will be 32MHz (see Figure 8-1). You don;t mention the DOZE setting but the power on default is 1:1 which means the CPU (Fcy) will be 32MHz as well and the CPU will operate at 16MIPS.
The 3rd part is the USB device but I'm not going to get into that as it does not really relate to the UART, and you are feeding it with the correct clock anyway.
The final part is the UART and I *think* you are wanting a baud rate of 9600 BAUD. The Fcy is 32MHZ and so, using equation 17-1, you should have
UxBRG = (32MHz/(16 * 9600)) - 1
= 207.333
which means that you would set BRGH to 0, UxBRG to 207 and you will be within 0.16% of the desired baud rate. That should be close enough for reliable communication.
My advice is to get the oscillator working correctly first - the REFO output will help you there. Then get the UART working - you can test it on its own by linking the Rx and Tx lines, sending a character and receiving the same character back again and then breaking the link and connecting to a PC (or whatever) and making sure that you are sending and receiving characters correctly.
Only then should you get into the USB side of things as it is (generally) an order of magnitude more difficult (even when you copy the example code it can be a bit hard to get your head around).
Susan
 

the problem is solved
I raised a ticket to microchip support, and in response they told me not to use their own plib functions.
i was using uart.h plib functions.
ticket response suggested to use individual sfr writing for initializations and operation.
I don't know what to say but it worked, which is absolutely fine for me.

Sorry for late reply.
thank you all for your valuable help and time!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top