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 support@ccsinfo.com

Interrupt rb in pic16f877a and send data in rs232

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



Joined: 11 Sep 2014
Posts: 3

View user's profile Send private message Yahoo Messenger

Interrupt rb in pic16f877a and send data in rs232
PostPosted: Fri Nov 23, 2018 2:37 pm     Reply with quote

Hello everybody
When i send some of data by using rs232 command,
( Interrupt rb in change ) work or stop while send data in tx ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 23, 2018 3:31 pm     Reply with quote

If you are using the hardware serial port in the PIC, and you have placed
a byte in the transmit buffer, the hardware will transmit the byte even if
int_rb interrupts occur.

However, if you get an int_rb interrupt before the byte is placed in the
transmit buffer, then the interrupt will be processed first. The byte will
only be placed in the transmit buffer after the interrupt processing is done.
So, there would be a short delay before transmitting the byte.
hesham



Joined: 11 Sep 2014
Posts: 3

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Nov 23, 2018 4:06 pm     Reply with quote

Code:
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,timeout=100,errors)

#INT_RB
void  RB_isr(void)
{
a=input_state(pin_B7);
if(a==1){if(aa==0){v+=1;aa=1;}}
if(a==0){aa=0;}
}

void main(){
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
WHILE(TRUE){
  printf("\finterrupter = \n%lu",v);
  Delay_ms(500);
  }
}


My question is ??
When micro executing this line ( printf("\finterrupter = \n%lu",v)) as order sequence program above.
Rb interrupt is work during micro send or stop automatic to let micro send data.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Nov 23, 2018 5:22 pm     Reply with quote

Learn by doing, learn by reading.
Seriously you should get the parts, though a newer, better cheaper PIC than the 877... and a 2 channel scope. Then you'll see what happens.
Yes, I know reading datasheets and application notes can be difficult BUT that's the way to learn and remember how a PIC works!
One problem with your code, as posted, is that I do not actually know HOW the printf(..) function was actually coded.
It may be that the FIRST instruction inside the function is to disable all interrupts, in which case, the sending of data would be done THEN interrupts would be reenabled. If done this way, then the printing function has the 'priority' over any interrupts.
However, it's equally possible that the printf() will be stopped if an interrupt occurs. However that opens the possibility that the code has a 'list' of allowed interrupts that stop the printing, yet other interrupts do not stop the printng from happening.
You can dump the program listing and see the actual printf() function machine code. That will tell you what is actually happening.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 23, 2018 7:10 pm     Reply with quote

Quote:

Interrupt rb in pic16f877a and send data in rs232.

#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,timeout=100,errors)

You are using a software UART. This will be a problem with your
#use rs232() statement above. An interrupt will disrupt the timing of
the "bit banged" transmitted characters. This will cause errors in the
data transmitted by the soft UART. One solution to this is to disable
interrupts while each byte is sent. The PIC can still get interrupts
between bytes. Add the parameter shown in bold below:
Quote:
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,timeout=100,errors, disable_ints)

Another solution is to use the hardware UART on pins C6 and C7, if these
pins are available in your design. Example:
Code:
#use rs232(baud=9600, UART1, timeout=100, errors)


Also, if you have an early version of the CCS compiler (before vs. 5.013),
there was a bug that will cause problems. The CCS versions page says:
Quote:

5.013 A problem with printf disabling interrupts on some parts is fixed
hesham



Joined: 11 Sep 2014
Posts: 3

View user's profile Send private message Yahoo Messenger

PostPosted: Sat Nov 24, 2018 12:53 am     Reply with quote

Hi pcm
What change when using c6 and c7 in my code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Nov 24, 2018 1:45 am     Reply with quote

In fact in your original code, there is no 'INT_RB'. INT_RB, is an interrupt saying that the _hardware UART_ has received a byte. Since you are not using the hardware, there is no INT_RB.
Switch to the hardware pins, and then INT_RB exists.

When using INT_RB, the handler for this interrupt, _must_ read the byte from the UART. It cannot exit, unless this is done, since the interrupt cannot be cleared until the byte has been read....
So your example handler, if it was used for INT_RB, can never exit.

Now PCM_Programmer has pointed out the only issue (with early V5 compilers). Otherwise, what happens is that printf, will sit 'polling' the transmit buffer empty bit, and whenever this goes 'TRUE' loading the next byte. If an INT_RB arrives, the handler will be called.

He also shows the 'easy' way of using the hardware UART. The shortcut 'UART1', means use the UART hardware pin for transmit, the hardware UART pin for receive, and force the hardware to be used. A very good way of being 'sure'. C6 & C7 on your chip.
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