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.

[SOLVED] sending data through hyper terminal not receive correctly in pic18f4520 (USART)

Status
Not open for further replies.

dhakeparag81

Full Member level 2
Joined
Jun 6, 2012
Messages
123
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
INDIA
Activity points
2,335
hi

my problem is i am trying to send data through hyper terminal to pic i m using USART
when i try to send character 'a' through hyper terminal it receives 0xB1 in hex i didnt get it what is the problem.
help me out
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
Hi,

If you have the correct settings in your code it should work ok.
Show your code so we can see how you have set things up
 

milind.a.kulkarni

Advanced Member level 3
Joined
Oct 6, 2011
Messages
923
Helped
214
Reputation
428
Reaction score
208
Trophy points
1,333
Location
Bangalore
Activity points
7,438
check the max232 IC circuit and the capacitor used.....also as wp100 mentioned .... First of all you need to try to bring up the board with LED toggelling ...then use interrupt timer... Many times I had faced the problem with configuration register setting in PIC18F family play a critical role.....Also I will recommend you check your external oscillator too in case your are using it.... Also please put your schematic and code on the forum so may people can able to help you out with this problem

Good Luck
 

yuvko

Member level 4
Joined
Sep 5, 2007
Messages
74
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,288
Activity points
1,596
check your stop bits configuration, it looks like you only missing the last bit (0xb1 instead of 0x61)
 

papunblg

Advanced Member level 3
Joined
Oct 22, 2010
Messages
726
Helped
172
Reputation
344
Reaction score
165
Trophy points
1,343
Location
Kolkata India
Activity points
6,437
Also check your PC's port settings are according to your code. If you are using XP check from device manager.

- - - Updated - - -

After modification(if needed), reboot.
 

dhakeparag81

Full Member level 2
Joined
Jun 6, 2012
Messages
123
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
INDIA
Activity points
2,335
tnx guys
actually the problem in usart configuration,
but now im enabling the rx interrupt and receive packet of data for that i have to wait (DataReady) function used but while i m using that function i didnt get Timer1 interrupt it stuck in wait and if i dont used wait function i didnt get whole data only first byte received.
I use MODSCAN for communication which send 8 byte of packet

Is there any method to get whole 8byte packet without waiting?
.......

Here is my interrupt code




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
#pragma interrupt chk_isr    
 
void chk_isr(void)
{
    if(INTCONbits.TMR0IF==1)        // Timer0 causes interrupt.....?
    {
       T0_ISR();                    // yes then execute Timer0 programe.
    }
 
    if(PIR1bits.TMR1IF==1)
    {
        T1_ISR();
    }
        
    if(PIR1bits.RCIF==1)
    {
        RX_ISR();
    }
                    
}
#pragma code HI_PRIO_INT=0x0008      // high priority interrupt location.
 
void HI_PRIO_INT(void)
{
  _asm
  goto chk_isr
 _endasm
} 
 
void T0_ISR(void)
{
 
    TMR0H       = 0xB1; 
    TMR0L       = 0xDF;
 
    INTCONbits.TMR0IF=0;
    
}   
 
void T1_ISR()
{
    rx_timeout = 0;
    
    TMR1H       =0xFC;
    TMR1L       =0xBD;  
        
    PIR1bits.TMR1IF=0;
}
 
void RX_ISR(void)
{
    unsigned char data;
    buffer = rec_buf;
    rx_timeout=1;
    
    T1CONbits.TMR1ON=1;
 
    if((qip==0) && (rx_state==RXTX_IDLE))
    {
        qip=1;
        
                
        do{
            while(!DataRdyUSART());     // Wait for data to be received
            data =getcUSART();          // Get a character from the USART
            *buffer = data;             // and save in the string
            buffer++;                   // Increment the string pointer
            rx_state += 1;
        
 
        }while(rx_timeout==1);
        
    }       
    
    qip=0;
    
    
    T1CONbits.TMR1ON=0;
    PIR1bits.RCIF=0;
}

 
Last edited by a moderator:

milind.a.kulkarni

Advanced Member level 3
Joined
Oct 6, 2011
Messages
923
Helped
214
Reputation
428
Reaction score
208
Trophy points
1,333
Location
Bangalore
Activity points
7,438
In my view one need to see your ISR first....you need to have priority assigned in the ISR....that should help you out with this ....

Good Luck
 

yuvko

Member level 4
Joined
Sep 5, 2007
Messages
74
Helped
19
Reputation
38
Reaction score
17
Trophy points
1,288
Activity points
1,596
if you received a byte, you do not need to wait for timeout. add a "rx_timeout = 0;" after reading the received byte
 

dhakeparag81

Full Member level 2
Joined
Jun 6, 2012
Messages
123
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
INDIA
Activity points
2,335
Thanks
when i assign high priority to rx isr it work.
but when it goes to

#pragma code High_Vector_Section=0x0008
void high_isr (void);

void high_vector (void)
{
_asm
goto high_isr
_endasm
}

it never came to the main function
it continuously checked the above lines

i checked for flag there is no flag set

then why program counter reload its previous address?
 

milind.a.kulkarni

Advanced Member level 3
Joined
Oct 6, 2011
Messages
923
Helped
214
Reputation
428
Reaction score
208
Trophy points
1,333
Location
Bangalore
Activity points
7,438
Hi Parag,

You need to understand bit more on the ISR .....and high_isr() and low_isr() function....

First of all you need to know that interrupt service rountine is never be the part of the main() function....it will never called in the main()....it is separate free running entity most of time based on the configuration of interrupt in main() function and equivalent event happen at run time ( mostly non-predictable activity)....Now let consider an example timer overflow interrupt and receive character interrupt can come at a time in system but ....your priority of interrupt will tell which one to serve first..... so that you have two mode one is high priority and second one is with low priority ISR.... So first understand and finalize the interrupt that you are planning to use ....then assign the priority of them....

the way that you are written the functions as and interrupt are appears to be fine but....I think you need to think a bit and then write the ISR low or high ISR.....

Good Luck
 

dhakeparag81

Full Member level 2
Joined
Jun 6, 2012
Messages
123
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
INDIA
Activity points
2,335
thanks to all guys
I m done with my project the problem was i am used 3 interrupt
timer0, timer1, receiver in which i configured t1,rx as high priority
i entertained t1 and rx but as t0 is in low interrupt vector address it never
go to that routine bcoz of this im stuck in higher isr.

there is one more question
if i used t0 as low priority and t1 and rx as high priority
is that necessary to write code for t0 like
.
.
.

void high_isr()
{
if(t0==1)
t0_isr();

if(rx==1)
rx_isr();

if (t1==1)
t1_isr();

}

above code is just a pseudo code

when i used t0 in another function it never go to that routine
 

milind.a.kulkarni

Advanced Member level 3
Joined
Oct 6, 2011
Messages
923
Helped
214
Reputation
428
Reaction score
208
Trophy points
1,333
Location
Bangalore
Activity points
7,438
the way that you are written is ok but that will not handle priority....

Try the code some thing like this....

Code:
void high_isr()
{
if((t0==1)&&(rx==1)&&(t1==1)) // t1 is highest priority 
{
t1_isr();
}
if((t0==1)&&(rx==1)&&(t1==0)) // rx has higher priority than t0
{
rx_isr();
}
followed with the cases that you have .........
}


I hope this will give you an idea based on your system ....

Good Luck
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top