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

Dynamic adjustment UART

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Dynamic adjustment UART
PostPosted: Mon Aug 06, 2012 10:03 pm     Reply with quote

Hi! I have a 18F66J60 controller connected to MAX232. The controller must only read the input data. The problem is the pcb could be connected to different devices with different baud rate. So I need to know how to make my controller to take sample and adjust baud rate to the line.
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Tue Aug 07, 2012 1:24 am     Reply with quote

Do you have control of what is sent from the other end?.

The PIC AutoBaud feature, only works reliably,, if 0x55 is sent as the first character after it is enabled. Basically all you do, is set the ABDEN bit, and then the BRG automatically synchronises to the next character received. You can test the ABDOVF bit to verify that a legitimate rate was seen, and test the ABDEN bit (which goes clear when the detection is finished). The fact that the BRG contents get changed, the compiler doesn't care about, and existing code carries on happily working at the new rate.
So:
Code:

//For UART1
#byte BAUDCON1=(getenv("SFR:BAUDCON1")
#bit ABDOVF1=BAUDCON1.7
#bit ABDEN1=BAUDCON1.1

#define trigger_baud_detection1() ABDEN1=1
#define baud_has_been_found1() (ABDEN1==0)
#define baud_error1() (ABDOVF1==1)

//Basic usage as:
  int8 ctr='0', tick=255;
 
  while (TRUE) {   
    printf(lcd_putc,"\fAttach serial");
    trigger_baud_detection();
    while (!baud_has_been_found()) {
       lcd_gotoxy(1,1);
       printf("waiting %c");
       delay_ms(1);
       if (tick) --tick;
       else {
          tick=255;
          if (++ctr==':') ctr='0';
       }
    }
    if (!baud_error()) break;
    else {
       printf(lcd_putc,"\fError try again");
       lcd_gotoxy(1,2);
       printf(lcd_putc,"# to continue");
       do {
       } while (kchr!='#');
    }
  }


No guarantees.
This is 'snipped and trimmed' from some existing code I use on a different PIC with the same feature. This has it's own keypad, and lcd, and in the code, if an error occurs in the baud detection, asks you to press '#' to try again. The system at the other end, has 'break' detection on the serial, and automatically sends a 0x55 sync character, when the cable is attached.
I think I have left all the bits that matter.

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