Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Reception time out query on serial communication using 19200 baud rates and 20MHz crys

Status
Not open for further replies.

Tushar0014

Newbie level 1
Joined
Apr 1, 2017
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
42
Reception time out query on serial communication using 19200 baud rate and 20MHz crys

i'm using the 20Mhz crystal in PIC18f26k22 controller fro serial communication program.
the aim of program is to receive data from the Hercules to PIC and send same data back to Hercules

while using serial communication i try to receive serial data at baud rate of 19200.
but as i use reception time out count value 866 (which is calculate based on crystal frequency and required baud rate) i get different resend data on hercules.

the code is something like this...


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
void init_io(void)
{
    ANSELCbits.ANSC6=0; // define the Pin 17 as digital pin
    ANSELCbits.ANSC7=0; // define the pin 18 as digital pin
    ANSELAbits.ANSA0=0; // define the pin 2 as digital pin
    ANSELAbits.ANSA1=0; // define the pin 3 as digital pin
    ANSELAbits.ANSA2=0; // define the pin 4 as digital pin
    ANSELAbits.ANSA5=0; // define the pin 4 as digital pin
    
    
    TRISAbits.TRISA0=0;// define pin as output pin
    TRISAbits.TRISA1=0;// define pin as output pin
    TRISAbits.TRISA2=0;// define pin as output pin
    TRISAbits.TRISA3=0;// define pin as output pin
    TRISAbits.TRISA4=0;// define pin as output pin
    TRISAbits.TRISA5=0;// define pin as output pin
    TRISAbits.TRISA6=0;// define pin as output pin
    TRISAbits.TRISA7=0;// define pin as output pin
    
    TRISBbits.TRISB0=0;// define pin as output pin
    TRISBbits.TRISB1=0;// define pin as output pin
    TRISBbits.TRISB2=0;// define pin as output pin
    TRISBbits.TRISB3=0;// define pin as output pin
    TRISBbits.TRISB4=0;// define pin as output pin
    TRISBbits.TRISB5=0;// define pin as output pin
    TRISBbits.TRISB6=0;// define pin as output pin
    TRISBbits.TRISB7=0;// define pin as output pin
    
    TRISCbits.TRISC0=0;// define pin as output pin
    TRISCbits.TRISC1=0;// define pin as output pin
    TRISCbits.TRISC2=0;// define pin as output pin
    TRISCbits.TRISC3=0;// define pin as output pin
    TRISCbits.TRISC4=0;// define pin as output pin
    TRISCbits.TRISC5=0;// define pin as output pin
    TRISCbits.TRISC6=1;//TX pin set as output
    TRISCbits.TRISC7=1; //RX pin set as input
   
}
 
void main()
{
   
    init_io(); //call to initialize i/o
  
    SPBRG=0x40; // 9600 baud rate 8 bit transmission mode value
    
    TXSTA1bits.CSRC=0; // don't care in asynchronous mode
    TXSTA1bits.TX9=0;// select 8 bit mode  
    TXSTA1bits.TX9D=0; // address or data
    TXSTA1bits.TXEN=1; // enable transmission enable
    TXSTA1bits.BRGH=1;  // select high speed baud   
    TXSTA1bits.SENDB=0; // send break character bit select sync break transmission complete bit to 0
    TXSTA1bits.SYNC=0;  // enable asynchronous mode
    
    RCSTA1bits.SPEN=1; // enable serial port
    RCSTA1bits.CREN=1; // enable continues receive bit
    RCSTA1bits.FERR=0;  // no framing   
    RCSTA1bits.OERR=0;  // no overrun bits  
    RCSTA1bits.RX9=0;   //  select 8 bit reception
    RCSTA1bits.RX9D=0; // either address or data
    RCSTA1bits.ADDEN=0; // disable address detection
    
    BAUDCON1bits.ABDEN=0; // auto baud rate detection mode disable
    BAUDCON1bits.ABDOVF=0;//  auto baud rate timer did not overflow
    BAUDCON1bits.BRG16=0; // use 16 bit baud rate generator 
    BAUDCON1bits.CKTXP=0; // idle state  of transmitter is high
    BAUDCON1bits.DTRXP=0; // disable inverted data reception
    BAUDCON1bits.WUE=0; // receiver is operating normally
    
    PORTAbits.RA0=0; // off the led at pin 2
    PORTAbits.RA1=0; // off the led at pin 3
    PORTAbits.RA2=0; // off the led at pin 4
    PORTAbits.RA5=0; // off the led at pin 4
    
 while(1)
 {
  if(PIR1bits.RC1IF==1||count<=866)  // wait till data not receive
  {
      if(PIR1bits.RC1IF==1) // if data is received 
      {
        data[j]=RCREG1; // store all received data in  string
        j++; // increment array index
        count=0;  // clear reception timeout
      }
      else
      {
          count++; // increase reception timeout
      }
  }
  if (count>866) // if timeout reception reach to maximum limit then stop the reception
      { 
      break; // stop 
      } 
   while(!TXSTA1bits.TRMT); // wait until TRMT register not get set
   TXREG =data[j] ; // send character     
   j++;
 }
     
}


i need help to find my mistake so that i get my desired output as per Program Aim.
 
Last edited by a moderator:

Re: Reception time out query on serial communication using 19200 baud rate and 20MHz

hello,



i use reception time out count value 866

What represent 866 value, how did you set this value ?

1 cycle= 4/20 µS
866x 4/20= 173,2µS

19200 bauds => 1 bit within 52µS
Start + 1 byte + Stop => uses 10 bit => 52x10=520 µS

9600 bds => 1 bit 104µS 1 byte => 1040µS


Code:
 SPBRG[COLOR=#339933]=[/COLOR][COLOR=#208080]0x40[/COLOR][COLOR=#339933];[/COLOR] [COLOR=#666666][I]// 9600 baud rate 8 bit transmission mode value[/I][/COLOR]

19200 bds in the title ?
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top