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 CCS Technical Support

HW & SW rs232 baudrate error?

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







HW & SW rs232 baudrate error?
PostPosted: Sat Nov 22, 2008 7:09 pm     Reply with quote

Hi,

I'm trying to use 2 rs232 link on a 18f452 (one hard and one soft), yet I can't make it work Sad The SW works fine, but the HW receive just trash.
I dont have any idea left, what am I doing wrong?

Code:

#include <18F4520.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES H4                       //High speed Osc (> 4mhz) + PLL (x4)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV25                   //Brownout reset at 2.5V
#FUSES PUT                      //Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=38000000,RESTART_WDT)
#use rs232(baud=4800,parity=N,uart1,bits=8,stream=GPS,errors)
#use rs232(baud=4800,parity=N,xmit=PIN_D3,rcv=PIN_D2,bits=8,stream=PC,restart_wdt)

char Ch2;
int1 new;


#int_RDA
void  RDA_isr(void)
{
   Ch2=fgetc(GPS);
   new=true;
}


void main()
{

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_PLL_ON);

   while(1)
   {
   
      if(new==true)
      {
         fprintf(PC," => %c \n\r",Ch2);
         new=false;
      }
   
   }
}


here is what the pic receive (sent back with the SW)

a => ü
b => ü
c => ü
h => |
i => |
j => |
o => |
p => ü
q => ü
r => ü
s => ü
1 => ð
2 => ð
3 => ð
7 => |
8 => ð
9 => ð
A => ü
B => ü
C => ü
O => p
P => Œ
Q => Œ
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Nov 22, 2008 8:15 pm     Reply with quote

Is this a simple human interactive test program?

The reason I ask is you are responding with 8 characters for a single received character.

You are certain to have a rx overrun since both ports are @ 4800 for a full speed receive operation.

Despite that, are you certain the terminal software on your PC is set to 4800N81 also?

Ray
Thoman
Guest







PostPosted: Sat Nov 22, 2008 8:57 pm     Reply with quote

I have simplified my program hoping to find the problem ... in this form it is just a test program.
For the matter of the baudrate; I have put the same on the HW and SW to be able to send data on one uart (HW) with the terminal, and receive data from the second (SW).
Honestly I have put my entire day on this matter and I'm still not remotely close to find a solution Sad . I'll be grateful for any help!

(But for the moment I'm going to bed because it's 4am in France Wink )

ps: my terminal is correctly set to 4800N81 since I receive the other characters nicely ( " => " )
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sat Nov 22, 2008 10:24 pm     Reply with quote

I have experienced problems with occasional corrupt character, as described here http://www.ccsinfo.com/forum/viewtopic.php?t=35733.

But your corruption really looks like the bit rate is not being set correctly due to the pattern associated with the characters you send back, and the input you have sent.
I'd hazard a guess that you have a x4 error, and this may be related to the x4 PLL operation....

Have you tried simply a looping back with the same UART before trying the crossover from HW to SW?
Ttelmah
Guest







PostPosted: Sun Nov 23, 2008 3:59 am     Reply with quote

Obvious comment does apply. Do you really have a 9.5MHz crystal?. An 'odd' frequency, and if this is wrong, it'd exaplin everything.

Best Wishes
Thoman
Guest







PostPosted: Sun Nov 23, 2008 7:05 am     Reply with quote

In fact I have a 10MHz crystal; but with the PLL activated the frequency isn't right, I had to adjust it a bit.
By the way I have removed the PLL to test, but it's the same ... The HW give just crap and the soft is ok
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Sun Nov 23, 2008 9:48 am     Reply with quote

Thoman wrote:
In fact I have a 10MHz crystal; but with the PLL activated the frequency isn't right, I had to adjust it a bit.
By the way I have removed the PLL to test, but it's the same ... The HW give just crap and the soft is ok

Here is a way to verify the hardware baudrate settings. Go into a tight loop sending the character '@' over and over. This character is very easy to decode on a scope. Then look at the signal on the scope to see how long the character is. Each character is 10 bit times (assuming 8 bits, 1 stop bit). If you don't have a scope, or you don't trust the sweep calibration of your scope, then do this, which can be much more accurate: As you send out characters at full speed, count the characters and toogle a separate diagnostic output (perhaps on an LED) every 4000 characters. Use a stopwatch to measure the length of time for so many toggles (about 1 minute). Calculate baud rate from that. If you want more accuracy, count for 5 minutes.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Ttelmah
Guest







PostPosted: Sun Nov 23, 2008 1:53 pm     Reply with quote

The 'odds' are that if the PLL is giving the wrong frequency, it is because the crystal is a little overdriven. The PLL on older chips, was extremely sensitive to this. On latter chips it is better, but will still exhibit problems if the crystal is significantly overdriven.
You really should fix this first. I'd try adding a 100R in series with the crystal, and get your frequency right, before trying to chase more complex problems.

Best Wishes
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