UART Software Interrupt

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

UART Software Interrupt

Postby shahrul » Fri May 27, 2011 7:44 pm

Hi,
I tried to do UART software. I have done the transmit code and receive code. It's like below
Transmit
CODE: SELECT_ALL_CODE
TX1=0;
for(j=0;j<baud_delay;j++) continue;
for(i=0;i<=7;i++){
   TX1=data;
   data=data>>1;
   for(j=0;j<baud_delay;j++) continue;}
TX1=1;
for(j=0;j<baud_delay;j++) continue;

Receive
CODE: SELECT_ALL_CODE
while(RX1==1) continue;
data=0;
for(j=0;j<baud_delay;j++) continue;   
for(i=0;i<=7;i++){
   data=(data>>1)|(128*RX1);
   for(j=0;j<baud_delay;j++) continue;}

Then I wan't to put the receive code into the RB0 Interrupt (INTF). I wan't do this because I don't want use while(RX==1).
This is interrupt part.
CODE: SELECT_ALL_CODE
if(INTF==1){
   GIE=0;
   data=0;
   for(j=0;j<baud_delay;j++) continue;   
   for(i=0;i<=7;i++){
      data=(data>>1)|(128*RX1);
      for(j=0;j<baud_delay;j++) continue;}
   GIE=1;
   INTF=0;
}

But, it's not running. Did somebody have explanation on this?
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: UART Software Interrupt

Postby robosang » Sat May 28, 2011 11:54 am

CODE: SELECT_ALL_CODE
if(INTF==1){
   GIE=0;
   data=0;
   for(j=0;j<baud_delay;j++) continue;   
   for(i=0;i<=7;i++){
      data=(data>>1)|(128*RX1);
      for(j=0;j<baud_delay;j++) continue;}
   GIE=1;
   INTF=0;
}


Not really try this before, but do the polling method works? The while (RX == 1). Another thing about RB0, the external interrupt, you can actually configure for falling edge or rising edge to interrupt right? Have you do that?

Another thing is GIE is not needed to clear in ISR. The GIE is automatically clear in ISR, the "RETFIE", return from interrupt will automatically set the GIE back. This is to prevent another interrupt flag disturb the current ISR if it happen. Since you are using C, the ISR routine in library will have RETFIE for you, you don need to do it. So in short, you can ignore the GIE in ISR.

So if nothing works mean the program stop at? Did program goes at least into ISR? If it does, did program come out from ISR and what is the data store compare to data you send?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: UART Software Interrupt

Postby shahrul » Sat May 28, 2011 2:58 pm

The UART Receive works with while (RX1==1). RX1 is port RB0. Data value is same as UART sent from hyperterminal.
Then, do for RB0 interrupt. Set at RB0 falling edge. I think, the program goes into interrupt function, but the data value is wrong.
I will try to take out the GIE.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor


Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 5 guests