|
|
View previous topic :: View next topic |
Author |
Message |
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Software UART at 300 Baud corrupt data |
Posted: Tue Aug 08, 2006 8:29 am |
|
|
My circuit has two chips linked by CMOS level;
Chip#1 ---- Chip#2
Tx1(C2) to Rx2(A3)
Rx1(G4) to Tx1(A0)
As this link only needs to send 2 bytes and recieve 2 bytes I figured software
UART at 300 Baud should do the trick.
#use rs232(baud=300,parity=N,xmit=PIN_C2,rcv=PIN_G4,bits=8,FORCE_SW)
Chip #1 transmits a request byte and chip #2 replies. However the reply data is corrupt.
I tried using DISABLE_INTS in the #use RS232 statements, but the complier complains (PCH V3.249)
I tried to disable the interrupts, that did not help.
In the following code snippets, chip#1 sends a command byte 'b', I assume this has been received correctly by chip#2 because it replies everytime, the assumption is based upon if ( D == 'b' ) which must be true to ever send a reply, and it never fails to do that.
Speed is not the issue here, infact I could take the Baud rate down to 110 Baud or lower !
I have never liked software UARTS so I expected trouble !
What am I doing wrong here... ?
Thanks.
//////////////////////////////
Code for chips #1
#use rs232(baud=300,parity=N,xmit=PIN_C2,rcv=PIN_G4,bits=8,FORCE_SW)
int8 V1,V2;
putchar(0XFF); // use it as the wake up char for Chip #2
delay_ms(25); // may not be needed
putchar( 'b' ); // the command char request
V1 = getchar(); // will wait for next char
V2 = getchar();
/////////////////////////////
Code for chip #2
#use rs232(baud=300,parity=N,xmit=PIN_A0,rcv=PIN_A3,bits=8)
int8 D;
while(1)
{
if (kbhit() )
{
D = getchar(); // wait for command char
if ( D == 'b' )
{
putchar(0X55); // return test values
delay_ms(16);
putchar(0XAA);
}
D=0;
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 08, 2006 11:35 am |
|
|
What PICs are you using ?
What is the crystal frequency on each board ?
Have you tried having one PIC transmit at 300 baud to a terminal
window on a PC ? Does the PC receive characters correctly ? |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Answers |
Posted: Tue Aug 08, 2006 1:38 pm |
|
|
Thanks PCM programmer,
Q) What PICs are you using ?
A) #1 PIC16F6720 and PIC12F629
Q) What is the crystal frequency on each board ?
A) Chip #1 4.194304Mz using 4XPLL, and Chip #2 2MHz resonator (industrial 0.5%)
Q) Have you tried having one PIC transmit at 300 baud to a terminal
window on a PC ?
A) No because it's difficult. I put the code in a loop and transmited 0X55 the square wave indicates 301 Baud !
Q) Does the PC receive characters correctly ?
A) Not tested but may have to cut and jumper in a MAXnnn level shifter and try this.
Unless I'm mistaken the PIC12F629 8 pin chip does not allow debugging, so I'm kind of stuck on that side of it. I'd like to connect my second ICD-U40.
I may have to wire up another PIC device to test/debug the code, and then port it to the 12F629... !
I'm curious why the compiler complains about DISABLE_INTS ! I thought that item was intended to assit the use of software UARTs.
If this does not work out, I may have to go to some of two wire bit banger comm. that I have from way back. |
|
|
Ttelmah Guest
|
|
Posted: Tue Aug 08, 2006 3:01 pm |
|
|
You say 'by CMOS level'. What voltage is each chip actually running at?. How are they actually joined?.
With 3.249, 'DISABLE_INTS' in the RS232 line, works fine for me with this chip. What compiler version are you running?.
Best Wishes |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Same 3.3Volts |
Posted: Tue Aug 08, 2006 3:45 pm |
|
|
Ttelmah wrote: | You say 'by CMOS level'. What voltage is each chip actually running at?. How are they actually joined?.
With 3.249, 'DISABLE_INTS' in the RS232 line, works fine for me with this chip. What compiler version are you running?.
Best Wishes |
Both chips on the same PC board with the same 3.3V supply.
They are connected directly by pcb traces about 1" in length. tx to rx and rx to tx.
I have PCWH 3.249 |
|
|
Ttelmah Guest
|
|
Posted: Wed Aug 09, 2006 2:43 am |
|
|
The phrase 'puzzled', does leap out on this one.
Post the actual 'header' (the #use delay, fuses, and #use RS232), from each program. What is 'odd', is that:
Code: |
#include <12F629.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Resistor/Capacitor Osc with CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //Reset when brownout detected
#FUSES NOMCLR //Master Clear pin disabled
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#use delay(clock=2000000)
#use rs232(baud=300,parity=N,xmit=PIN_A0,rcv=PIN_A3,bits=8,DISABLE_INTS)
|
Compiles happily without complaint. I have also tested the output rate, and this is even closer to 300bps, than on your test.
Try a pull up resistor on the lines. The 6720, has an 'input high' spec, of 0.8Vdd, on a Schmitt input. With a 3.3v supply, this is 2.64v. The 629, only guarantees an output to pull up to 2.6v on the same supply...
Best Wishes |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Answers 2 |
Posted: Wed Aug 09, 2006 7:35 am |
|
|
Ttelmah wrote: | The phrase 'puzzled', does leap out on this one. |
Me too !
I do not like software uarts, I have never had reliable results.
My first thought was that corruption is happening because the interrupts are still turned on. That's when I tried DISABLE_INTS !
The error message reads USE parameter value is out of range "FORCE_SW|DISABLE_INTS" for the PIC18F6720
#include <18F6720.h>
#device *=16,adc=8, HIGH_INTS=TRUE, icd=true
#use delay(clock=16777216)
#fuses NOWDT,WDT128, H4, NOPROTECT, OSCSEN, NOBROWNOUT, BORV25, PUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOCPB, NOEBTR, NOWRTD, NOWRTC, NOWRTB
#include <12F629.h>
#FUSES HS, NOMCLR, NOPROTECT, NOWDT, NOBROWNOUT, PUT #use delay(clock=2000000)
#use rs232(baud=300,parity=N,xmit=PIN_A0,rcv=PIN_A3,bits=8)
I did not use the FORCE_SW becasue this chip does not have a hardware UART, and the compiler will default to that anyway.
PIC12F629: I just tried FORCE_SW | DISABLE_INTS and got the same eror. I then tried only DISABLE_INTS and it compiled!
It appears to be the combination of FORCE_SW | DISABLE_INTS that generates the error!
Pull ups should not be needed, at least not at room temperature. Scope shows signals are going rail to rail. I'll do temperature testing at a later stage.
My conclsuion:
The only thing that's strange is that you do not get that error message!
If you get a minute could you please try the combination of FORCE_SW | DISABLE_INTS
I have several unresolved Tech. Support issues where I can reproduce stuff and CCS never could. !
Until PCWH version 3.249 I could not compile a known working source, I had to go back about 8-9 revisions. ! Let me correct that: it compiled but would never run on the hardware. With V3.249 everything works.. !
As there appears to be nothing wrong in the hardware. and I have to move on, I'm digging up some old two wire bit banger code that I know works.
Data rate is not important, the code sends a few bytes of "setup data" which can be sent a 20 bps !
Thanks for the help...
I have to hit the road, so it may be a day or two before I visit this thread again.
Hans W |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 09, 2006 9:41 am |
|
|
There is no OR symbol. It all has to be done with commas. |
|
|
Hans Wedemeyer
Joined: 15 Sep 2003 Posts: 226
|
Thanks |
Posted: Thu Aug 10, 2006 6:24 pm |
|
|
PCM programmer wrote: | There is no OR symbol. It all has to be done with commas. |
OK I'll try that when I get back to the US. |
|
|
|
|
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
|