View previous topic :: View next topic |
Author |
Message |
raffaele
Joined: 19 Feb 2010 Posts: 8
|
UART problem on PIC24 |
Posted: Wed Feb 24, 2010 5:36 am |
|
|
Hello,
I'm having problem receiving data with PIC24HJ64GP502, comp. v4.093. I found that the RX pin is always at 0V in idle mode, and not at 3.3V. The problem is on both UART, while no poblem to send data.
Here the testing code.
Code: | #include <24hj64gp502.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOWRTB //Boot block not write protected
#FUSES NOBSS //No boot segment
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES FRC //Internal Fast RC Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES OSCIO //OSC2 is general purpose output
#FUSES NOPR //Pimary oscillaotr disabled
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT128 //Power On Reset Timer value 128ms
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NORSS //No secure segment RAM
#FUSES NOSSS //No secure segment
#FUSES NOWRTSS //Secure segment not write protected
#FUSES NORBS //No Boot RAM defined
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOCOE //Device will reset into operational mode
#FUSES NOJTAG //JTAG disabled
#FUSES ICSP1 //ICD uses PGC3/PGD3 pins
#FUSES ALTI2C //I2C mapped to alternate pins
#use delay(clock=7370000)
#pin_select U1RX=PIN_B10
#pin_select U1TX=PIN_B11
#use rs232(UART1,baud=9600,bits=8, parity=N, stop=1,stream=u1)
#pin_select U2RX=PIN_B5
#pin_select U2TX=PIN_B6
#use rs232(UART2,baud=9600,bits=8, parity=N, stop=1,stream=u2)
char c;
void main()
{
fprintf(u2,"Start\r\n");
while(TRUE)
{
if (kbhit(u1))
{
c=fgetc(u1);
fputc(c,u2);
}
}
}
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Feb 24, 2010 6:18 am |
|
|
Quote: | I found that the RX pin is always at 0V in idle mode | You mean, it's driven externally to 'H' but sensed as 'L'?. How do you detect it? Do you see a break state at the UART? |
|
|
raffaele
Joined: 19 Feb 2010 Posts: 8
|
|
Posted: Wed Feb 24, 2010 6:31 am |
|
|
I had a Max3223 to connect PIC to PC and I noticed no received data on PIC. Then I've disconnected MAx3223 leaving free the pin, with scope I can see 0V. 0V means 1 logic with TTL UART. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Feb 24, 2010 8:55 am |
|
|
If you disconnect the MAX3223, the Rx input pin isn't driven. How should it have a different voltage than 0? |
|
|
raffaele
Joined: 19 Feb 2010 Posts: 8
|
|
Posted: Thu Feb 25, 2010 3:12 am |
|
|
Usually RX pin are at high voltage level and driven low by TX pin, to confirm this i've checked the RX pin of HW UART of a PIC16F689 leaving it disconnected.
I've tried also to set the inverting bit in the Uart register and it's the same. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Feb 25, 2010 11:22 am |
|
|
Quote: | Usually RX pin are at high voltage level and driven low by TX pin |
They have a high idle level. Some processors also have fixed pull-up resistors at all or a several I/O pins.
PIC24 hasn't. So the pin floats most likely low.
If I understand right, your real problem is no receive action of the UART. The test with Rx level and disconnected MAX
chip is meaningless in this regard, I think. If the level is 0V with MAX3232 connected, you have a problem with the MAX chip,
not the PIC24. Check, why the MAX chip isn't driving out high level in idle state. |
|
|
raffaele
Joined: 19 Feb 2010 Posts: 8
|
|
Posted: Fri Feb 26, 2010 5:01 am |
|
|
Thank you, it's working connected a 3.3V serial device, thank you for your advice. |
|
|
|