CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC24HJ UART2 TX problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chandra



Joined: 19 Mar 2010
Posts: 18

View user's profile Send private message

PIC24HJ UART2 TX problem
PostPosted: Tue Mar 30, 2010 1:09 am     Reply with quote

I am using pic24HJ128GP306 and send "HELLO" characters to PC rs232.
It is working but when I start power on, it send many 00000s and then the word HELLO comes. I want to remove the 0000s. The code is:
Code:

#include <24HJ128GP306.h>
#fuses PR,HS,NOIESO,NOOSCIO,NOCKSFSM,PROTECTH,NOWDT
#use delay(crystal=14745600)
#use rs232(baud=115200, UART2)

void main()
{
while(1){
printf ("HELLO");
while(1);
}
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 3:03 am     Reply with quote

I don't think that the problem is related to your code. Simply the unconfigured pin has a high impedance
state which may be sensed as low level (UART break state) by the driver chip.

You can place a hardware pull-up resistor at the TX pin to change the unconfigured level.
chandra



Joined: 19 Mar 2010
Posts: 18

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 7:30 am     Reply with quote

I am using MAX3232 for level converter.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Mar 30, 2010 9:55 am     Reply with quote

chandra wrote:
I am using MAX3232 for level converter.


Is this a 3.3volt compatible part?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 3:20 pm     Reply with quote

Quote:
I am using MAX3232 for level converter.

Yes, I expected a similar driver. It has a high input impedance. Before the TX pin is configured by start of
main(), the output level is undefined and typically at low level, not the required UART high idle level.
chandra



Joined: 19 Mar 2010
Posts: 18

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 2:17 am     Reply with quote

I tried #define PIN_F5=low also. But the result is same.When power on it,I am getting the HEX 00 for 100ms.Then only the character is displaying.Any sugessions.
Thanks.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Mar 31, 2010 2:32 am     Reply with quote

chandra wrote:
I tried #define PIN_F5=low also. But the result is same.When power on it,I am getting the HEX 00 for 100ms.Then only the character is displaying.Any sugessions.
Thanks.


You needed to set it high not low.

I do this differently because I do not like the compiler determining what should be an input and what should be an output. I specify fast_io on all ports, set the default output levels (high for a serial TX output), set the tris accordingly.

HOWEVER....
.I have not read the device data sheet lately (that's your problem) but some of these driver chips must "wake up" is they have a power down mode. Wake up means that the +ve and -ve oscillators are not running and therefore the output level is zero until they start running and the charge pumps reach the required voltage levels. If this is the case then you need to either prevent these drivers from "sleeping" or initiate a power up sequence before you start transmitting data.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
chandra



Joined: 19 Mar 2010
Posts: 18

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 2:57 am     Reply with quote

U2STAbits.UTXEN = 1;
I need this.This is from c30 complier.How can we call this from CCs c.
UTEX bit to be 1 for TX pin idle state=0.
Anybodycan advice.
Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19366

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 3:40 am     Reply with quote

TXEN, is set for you by CCS.
What you are seeing, is happening _before_ the chip actually wakes up. No amount of code tweaking, can affect this.

Think about it for a moment, your code, sends 'HELLO', just once. You are seeing this, so the UART is enabled, idling correctly, and awake. What you are getting _before_ this, is when the chip has not yet actually started. At 115200bps, it doesn't take much time, to see several spurious characters.
When power is first applied to the chip, the TX pin, is set as an input (nothing you can do about this, it is a hardware feature). As such, the line has a PIC input, connected to the MAX input, and the line is floating. As soon as the chip actually wakes up, the pin is switched to an output for you (which is why you don't see more garbage _after_ the 'HELLO'), but you have to take the line to the idle state _using hardware_, to deal with the time involved in waking up.
A large pull-up resistor (22KR for example), ensures that the line wakes up, in the required 'high' state, while not using much power.
This type of thing is 'vital' in any circuitry, where different parts take different times to awaken. You have to make sure that lines are 'biased' to the off states, when nothing is driving them. It may in some cases only be for a few uSec, but it can make the difference between destroying hardware...

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 4:51 am     Reply with quote

Quote:
When power on it,I am getting the HEX 00 for 100ms.Then only the character is displaying.

This is the obviously the POR delay. Within this time amount, no programmed actions or processor configuration is in effect.
Quote:

Any sugessions.

I wonder, if you read my first response to your post? I'm under the impression, that nothing substantial has
been added to the thread since that. Ttelmah has explained it verbosely, if you possibly didn't understand it. But
there's no means to achieve the result without a hardware modification, except for disabling the POR timer, which
wouldn't be a good suggestion in my opinion.
chandra



Joined: 19 Mar 2010
Posts: 18

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 7:33 am     Reply with quote

I put a pullup resistor 15k at TX and it is working fine. But I don't want this hardware change. How can I disable the power on reset timing?
Thanks for all.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 9:52 am     Reply with quote

Quote:
I dont want this hardware change.
I already guessed this.

CCS has the "PUT" keyword for the PWRT fuses. PUT128 (128 ms) is the default.
You can either try PUT2 (2 ms) or NOPUT (PWRT disabled).
chandra



Joined: 19 Mar 2010
Posts: 18

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 11:30 am     Reply with quote

#Fuses NOPUT
Now working fine.Thanks for all.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group