View previous topic :: View next topic |
Author |
Message |
chandra
Joined: 19 Mar 2010 Posts: 18
|
PIC24HJ UART2 TX problem |
Posted: Tue Mar 30, 2010 1:09 am |
|
|
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
|
|
Posted: Tue Mar 30, 2010 3:03 am |
|
|
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
|
|
Posted: Tue Mar 30, 2010 7:30 am |
|
|
I am using MAX3232 for level converter. |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1636 Location: Perth, Australia
|
|
Posted: Tue Mar 30, 2010 9:55 am |
|
|
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
|
|
Posted: Tue Mar 30, 2010 3:20 pm |
|
|
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
|
|
Posted: Wed Mar 31, 2010 2:17 am |
|
|
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: 1636 Location: Perth, Australia
|
|
Posted: Wed Mar 31, 2010 2:32 am |
|
|
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
|
|
Posted: Wed Mar 31, 2010 2:57 am |
|
|
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: 19561
|
|
Posted: Wed Mar 31, 2010 3:40 am |
|
|
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
|
|
Posted: Wed Mar 31, 2010 4:51 am |
|
|
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.
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
|
|
Posted: Wed Mar 31, 2010 7:33 am |
|
|
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
|
|
Posted: Wed Mar 31, 2010 9:52 am |
|
|
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
|
|
Posted: Wed Mar 31, 2010 11:30 am |
|
|
#Fuses NOPUT
Now working fine.Thanks for all. |
|
|
|