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 CCS Technical Support

Multiplexing multiple #INT_RDA

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Multiplexing multiple #INT_RDA
PostPosted: Thu Jul 23, 2009 1:33 pm     Reply with quote

Hi, I am using the PIC18F452. This PIC has only one UART, and I need to capture the strings of three peripherals, they have different speeds (KB) and number of characters, the idea is multiplex the UART input by hardware, but the problem is that I will have three different routines interruption (#INT_RDA) .
How I can select the routine interruption according to peripheral selected Sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 1:58 pm     Reply with quote

You can only have one #int_rda routine in your program. You can
use if() statements inside the routine to execute different code.

Do you have some external hardware to select between the 3 rs232
signals coming into the PIC ?

You can use the setup_uart() function to change the baud rate of the
hardware UART from within the program.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 2:22 pm     Reply with quote

Hi, PCM programmer, yes I have a external hardware to select between the 3 rs232, I am use a multiplexer

My problem is how to do to select the correct subroutine in #int_rda routine?

sorry can you give an example?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 2:27 pm     Reply with quote

How do you control the external multiplexor circuit ? Probably, you use
two PIC i/o pins to select one of 3 different inputs.

In the code that controls the multiplexor circuit, you can set a global
variable that identifies the input signal which is currently in use.
Also setup the correct baud rate for the input signal.

Then read the global variable inside the #int_rda routine, and use if()
statements to execute the correct code.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 3:35 pm     Reply with quote

PCM programmer wrote:
Then read the global variable inside the #int_rda routine, and use if() statements to execute the correct code.


Or a switch/case statement setup.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 3:40 pm     Reply with quote

Hi PCM programmer, I am use a multiplexor and use two output of PIC, the PD0 PD1 to select the address of channel on the multiplexer.

Here is a sample how I want to do my code, I'm going on the right ?
Code:
#include <18F452.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT
#use delay(clock=20000000)
#use rs232(xmit=PIN_C6, rcv=PIN_C7)

#define AD0   PIN_D0
#define AD1   PIN_D1
#define High  output_high
#define Low   output_low

int8 UART_Modo = 0;

#INT_RDA
void serial_isr() {                       // Serial Interrupt
if ( UART_Modo = 1){
   ...............
   }

if ( UART_Modo = 2){
   ...........
   }

if ( UART_Modo = 3){
   .............
   }

}

void process0(){
...........
}

void process1(){
...........
}

void process2(){
...........
}

void Modo_Multimer(){

   UART_Modo = 1;            
   setup_uart(9600);
    enable_interrupts(global);
    enable_interrupts(int_rda);

    Low (AD0);               // Address selector Modo1
    Low (AD1);

    process1();

    disable_interrupts(global);
    disable_interrupts(int_rda);

}

void Modo_Ampmeter(){

   UART_Modo = 2;            
   setup_uart(4800);
    enable_interrupts(global);
    enable_interrupts(int_rda);

    Low  (AD0);               // Address selector Modo2
    High (AD1);

    process2();

    disable_interrupts(global);
    disable_interrupts(int_rda);

}

void Modo_Omhmeter(){

   UART_Modo = 3;            
   setup_uart(19200);
    enable_interrupts(global);
    enable_interrupts(int_rda);

    High (AD0);               // Address selector Modo3
    High (AD1);

    process3();

    disable_interrupts(global);
    disable_interrupts(int_rda);

}

void main() {
   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);

   delay_ms(500);

while (TRUE){

   Modo_Multimer();
   Modo_Ampmeter();
   Modo_Omhmeter();
  }
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 3:44 pm     Reply with quote

You didn't show most of the code inside the #int_rda routine.
But make sure that you don't enable Global interrupts inside that routine.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 3:47 pm     Reply with quote

I think I just need to tell my bud at Microchip that we need a PIC with like 8 serial ports or something. ;) hahahaha

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 3:58 pm     Reply with quote

Question I do not understand

but here is my code:


Code:
#INT_RDA
void serial_isr() {                       
if ( UART_Modo = 1){
    rcvchar=0x00;           
    rcvchar=getc();          
    addcbuff(rcvchar);       
   }


if ( UART_Modo = 2){
    int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;                       
   }


if ( UART_Modo = 3){
   Add_buffrec(getc());
   }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 4:06 pm     Reply with quote

Quote:
if ( UART_Modo = 1){

You need to use == for a test.

Also, what if 'UART_Modo' somehow becomes a number other than 1, 2
or 3 ? Your program will lock up, because it did not get the character
in the #int_rda routine.

It's better to call getc() one time, at the start of the #int_rda routine.
Put it in a local variable, such as 'c'. Then use 'c' in your if() code.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 4:10 pm     Reply with quote

pilar wrote:
Question I do not understand


Like this:

Code:
#INT_RDA
void serial_isr() {                       
    unsigned int t, c;

    c = getc();


    switch (UART_Modo) {

        case 1:  addcbuff(c);
                 break;

        case 2: buffer[next_in]=c;
                t=next_in;
                next_in=(next_in+1) % BUFFER_SIZE;
                if(next_in==next_out) {
                   next_in=t;
                }         
                break;


        case 3: Add_buffrec(c);
                break;
    }
}


I just edited this to reflect what PCM Programmer said.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 4:17 pm     Reply with quote

Can I use a break?


Code:
# INT_RDA
vacĂ­o serial_isr () (

buffer_temp = getc ();

if (UART_Modo == 1) (
Rcvchar = 0x00;
Rcvchar = buffer_temp;
Addcbuff (rcvchar);
)


if (UART_Modo == 2) (
Int t;

Buffer [next_in] = buffer_temp;
T = next_in;
Next_in = (next_in +1) BUFFER_SIZE%;
If (next_in == next_out)
next_in = t;
)


if (UART_Modo == 3) (
Add_buffrec (buffer_temp);
)
break;
)
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 4:18 pm     Reply with quote

not like that - no.

and you can say, buffer_temp = getc (); without defining buffer_temp first.

Before that line you should have

Code:

unsigned int buffer_temp;


-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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