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

Enabling and Disabling Interrupts

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







Enabling and Disabling Interrupts
PostPosted: Tue Aug 05, 2003 2:50 am     Reply with quote

<font face="Courier New" size=-1>PCM 3.126
uP 16F874
4MHz

Dear all...I am slowly working through some problems I am encountering using streams on a hardware and software UART. The code is shown below. When I power up the processor it does not appear to trigger on the UART interrupt until the EXT interrupt has trigger first. Once the EXT interrupt has trigger then the rda interrupt will! Is this normal?

Have I declared the interrupts correctly and in the right order?

I read somewhere that the interrupts should be disabled when using putc and fputc. Do I need to do that?

Can the enable option of the #use rs232(...) be relied upon to control the write enable pin on an RS485 driver IC?

I am in the process of upgrading my complier so that should eliminate and issues with regards to early implementations of using streams.

Any help that you can offer would be greatly appreciated.

Many thanks,

Jason James

#include <16F874.h>
//------------------------------------------------------------------------------
// Set uses and fuses for RS232 and RS485
//------------------------------------------------------------------------------
#use delay(clock=4000000)

//------------------------------------------------------------------------------
// Bus stream uses hardware UART and PIN_C5 to enable writes on the RS485 driver
//------------------------------------------------------------------------------
#use RS232 (baud=4800, xmit=PIN_C6, rcv=PIN_C7, BITS=8, PARITY=N, STREAM=bus, ERRORS, enable=PIN_C5)

//------------------------------------------------------------------------------
// Controller stream uses software UART
//------------------------------------------------------------------------------
#use RS232 (baud=4800, xmit=PIN_B1, rcv=PIN_B0, BITS=8, PARITY=N, STREAM=controller, ERRORS)

#fuses NOWDT, XT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP

//------------------------------------------------------------------------------
// Global variables and PORT Definitions
//------------------------------------------------------------------------------
#define ALL_IN 0x0f
#define ALL_OUT 0x00
#define WRITE_ENABLE PIN_C5
#define TRAFFIC PIN_E1
#include "lcdlib.c"
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
int displaystring[32];
byte bus_key;
boolean bus_flag;
byte con_key;
boolean con_flag;

//------------------------------------------------------------------------------
// ISR for hardware UART
//------------------------------------------------------------------------------
#int_rda
RS485_Handler()
{
bus_key = fgetc(bus);
bus_flag = true;
}

//------------------------------------------------------------------------------
// ISR for PIN_B0 (EXT) used for software UART
//------------------------------------------------------------------------------
#int_ext
RS232_Handler()
{
con_key = fgetc(controller);
con_flag = true;
}

//------------------------------------------------------------------------------
// Main Routine
//------------------------------------------------------------------------------
void main(void)
{
bus_flag=false;
con_flag=false;
//------------------------------------------------------------------------------
// Enable global and specific interrupts
//------------------------------------------------------------------------------
enable_interrupts(global);
enable_interrupts(int_rda);
enable_interrupts(int_ext);
//------------------------------------------------------------------------------
// Loop forever
//------------------------------------------------------------------------------
while(1)
{
//------------------------------------------------------------------------------
// If a byte is received on bus stream
//------------------------------------------------------------------------------
if(bus_flag)
// Send byte to con
{
//------------------------------------------------------------------------------
// Disable global and specific interrupts
//------------------------------------------------------------------------------
disable_interrupts(global);
disable_interrupts(int_rda);
disable_interrupts(int_ext);
//------------------------------------------------------------------------------
// Send byte over controller stream
//------------------------------------------------------------------------------
fputc(bus_key, controller);
bus_flag = false;
//------------------------------------------------------------------------------
// Enable global and specific interrupts
//------------------------------------------------------------------------------
enable_interrupts(global);
enable_interrupts(int_rda);
enable_interrupts(int_ext);
}
//------------------------------------------------------------------------------
// If a byte is received on controller stream
//------------------------------------------------------------------------------
if(con_flag)
// Send byte to bus
{
//------------------------------------------------------------------------------
// Disable global and specific interrupts
//------------------------------------------------------------------------------
disable_interrupts(global);
disable_interrupts(int_rda);
disable_interrupts(int_ext);
//------------------------------------------------------------------------------
// Send byte ober bus stream
//------------------------------------------------------------------------------
fputc(con_key, bus);
con_flag=false;
//------------------------------------------------------------------------------
// Enable global and specific interrupts
//------------------------------------------------------------------------------
enable_interrupts(global);
enable_interrupts(int_rda);
enable_interrupts(int_ext);
}
}
}
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516666
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Enabling and Disabling Interrupts
PostPosted: Tue Aug 05, 2003 11:59 am     Reply with quote

What you have written is not structured very well for the hardware.

This is what I use for hardware UART interupt driven packet transfers.


#int_TIMER1
TIMER1_isr() // comm timeout has expired
{ disable_interrupts(int_TIMER1); // disable interupt
PacketIndex=--PacketIndex; // Set index to last recieved byte
CommPacketIn=1; // Tag packet for processing
}

#int_RDA
RDA_isr() // BYTE RECIEVED
{ int8 x;
x = fgetC( chanA ); // place incomming byte in buffer
PacketBuffer[PacketIndex++] = x; // place incomming byte in buffer
set_timer1( 32088 ); // set timer to overflow when transmition stops
bit_clear( *0xF9E, 0 ); // Clear timer1 interupt
enable_interrupts(int_TIMER1); // activate timer1
}

#int_TBE
TBE_isr() // BYTE TRANSMITED
{ int8 x;
if ( PacketIndex <= PacketSize ) // Is last byte sent?
{ x=PacketBuffer[PacketIndex];
fputC( x,chanA); // If a byte is sent, send next byte
PacketIndex++;
}
else // Packet finished
{ disable_interrupts(INT_TBE); // Interrupt off
PacketIndex = 0; // Prepair to recieve
PacketSize = 0;
}
}

I would handel the software stream from within main. If the software stream is run at a higher baud rate the hardware UART can send and recieve while the software UART is transmitting by enabling interupts between software sent bytes. Recieving on the software UART is dificult any way you slice it given that you dont want to sit in a loop waiting for an incomming byte.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516682
jamesjl
Guest







Re: Enabling and Disabling Interrupts
PostPosted: Wed Aug 06, 2003 12:40 am     Reply with quote

Thanks for the help.

Can I do something similar for the software UART using int_ext? Do you have any more information on the isr for TIMER1? Do you isr routines handle the delivery of multiple byte packets? Some the variable names you are using suggest that they do but I can't quite follow the flow of the code. Any help you can give me would be greatly appreciated.

Many thanks,

Jason.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516700
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Enabling and Disabling Interrupts
PostPosted: Wed Aug 06, 2003 9:28 am     Reply with quote

:=Thanks for the help.
:=
:=Can I do something similar for the software UART using int_ext? Do you have any more information on the isr for TIMER1? Do you isr routines handle the delivery of multiple byte packets? Some the variable names you are using suggest that they do but I can't quite follow the flow of the code. Any help you can give me would be greatly appreciated.
:=
:=Many thanks,
:=
:=Jason.

What is the end goal that you wish to achieve. The routines I posted work with variable length packets. I use Modbus packet formating but that is independent from transmitting and recieving packets. If you are sending and recieving single bytes that are not part of a packet those routines are not much use.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516715
jamesjl
Guest







Re: Enabling and Disabling Interrupts
PostPosted: Wed Aug 06, 2003 9:36 am     Reply with quote

:=:=Thanks for the help.
:=:=
:=:=Can I do something similar for the software UART using int_ext? Do you have any more information on the isr for TIMER1? Do you isr routines handle the delivery of multiple byte packets? Some the variable names you are using suggest that they do but I can't quite follow the flow of the code. Any help you can give me would be greatly appreciated.
:=:=
:=:=Many thanks,
:=:=
:=:=Jason.
:=
:=What is the end goal that you wish to achieve. The routines I posted work with variable length packets. I use Modbus packet formating but that is independent from transmitting and recieving packets. If you are sending and recieving single bytes that are not part of a packet those routines are not much use.

The data is sent in packets of 11 bytes on the bus stream (used for RS485) and the controller stream (used for RS232). The application simply forwards these packets from bus to controller or controller to bus picking out any information from the packet for itself to display on an LCD, such as source addr, destination addr, etc.

Since the PIC only has one hardware UART I am having to use a software UART to handle the other stream.

I hope that this answers your question, and many thanks for the continuing support.

Jason.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516717
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