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

Ttelmah please look this

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



Joined: 20 Oct 2006
Posts: 23

View user's profile Send private message

Ttelmah please look this
PostPosted: Mon Mar 19, 2007 9:10 pm     Reply with quote

my project must use 2 UART and now I can use it.
i'm using PIC18F452
my HW uart is C6 C7 and use INT_RDA. (9600)
SW UART is B0-->Rx,B3-->Tx and use INT_EXT(2400)
it work fine when i test by Hyperterminal.
HW uart connect to D.O.Meter and get value then print with SW uart to Hyperterminal when I hit my keyboard it show INT occurs.
but!! now when I connect SW UART to my Device(Embedded Ethernet Module)it doesn't work and i try connect it with HW uart my device can send and recv but D.O.meter can send Data witn SW Uart too.
This my code
Code:

#include <18f452.h>
#include <stdlib.h>
#include <CTYPE.h>
#include <STRING.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#use rs232(stream=CH1,baud=9600,xmit=PIN_C6,rcv=PIN_C7)//Hw UART-->INT RDA
#use rs232(stream=CH2,baud=2400,xmit=PIN_B3,rcv=PIN_B0,FORCE_SW,ERRORS)//SW UART-->INT EXT
#priority EXT,RDA

BOOLEAN RX=0,EXT_Hook=0;

int j,i,a,b,c;
float cTemp,mask=0.1;
float Ans,Inact_valve,act_valve;
int ptr,ptr2=0;
char command,array[12];
unsigned char recv1[5];
byte Temp[16],Temp2[8];
float MASK_value;

void CHECK_Valve(float);
int convHex(char);

/************************  INT Rx Service Routine  ***************************/

#INT_RDA  //Rx PIN Connect to D.O. Meter
void hw_uart_isr (){
      
      fgets(Temp,CH1);
                     
         a =convHex(Temp[12]);   //Convert Ten Digit
         b =convHex(Temp[13]);   //Convert Unit Digit
         c =convHex(Temp[14]);   //Convert .X Digit
                         
         a =a*10;                 //multiply 10 for TEN Digit
         cTemp =c*(mask);         //Assigned floating point Ctemp value
         Ans=a+b+cTemp;
         CHECK_Valve(Ans);
         RX=1;      //Set RX for INT Service finish
         
         for (i=0;i>15;i++){
               Temp[i]=0; //Clear value in Temp[]
         }
            return;
}

/**********************  INT EXT Routine  *************************/
#INT_EXT
void sw_uart_isr (){

      fprintf(CH2,"INT EXT Occurs in channel 2\n\r");
   disable_interrupts(INT_RDA);
         delay_us(200);
   enable_interrupts(INT_RDA);             
            return;

}

/********************************  MAIN Routine  **********************************/
void main ()
{
ext_int_edge(H_TO_L);

enable_interrupts(INT_EXT);
enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);

set_tris_d(0xFE);

for(;;){
      if (RX){
            RX=0;
         }
         delay_ms(3000);
         sprintf(array,"%3.1f",Ans );
         printf(puts(array,CH2));
   }
}

/*******************  convert Routine  ************************/
int convHex(char Data) {
      switch  (Data) {
         case '0' :
                return 0x00;
               break;
         case '1' :
                return 0x01;
               break;
         case '2' :
                 return 0x02;
               break;
         case '3' :
                 return 0x03;
               break;
         case '4' :
                return 0x04;
               break;
         case '5' :
                return 0x05;
               break;
         case '6' :
                return 0x06;
               break;
         case '7' :
                   return 0x07;
               break;
         case '8' :
                return 0x08;
               break;
         case '9' :
               return 0x09;
               break;   
         default :break;
      }
}
/*******************  CHECK_Valve Routine  ************************/
void CHECK_Valve(float Ans){
         if (Ans <act_valve>act_valve) & (Ans >= Inact_valve)){
            output_low(PIN_D0);
   }
}

Ttelmah
Guest







PostPosted: Tue Mar 20, 2007 3:18 am     Reply with quote

I'd say, start again!.....
Do _not_ use fgets, inside the RS232 interrupt. The interrupt means _one_ character is available. fgets, will wait for an entire string, and the whole time this is being done, nothing else will work. Look at ex_sisr.c, for how to handle int_rda. The processing of this incoming data, should be done in the main.
Then, do not disable the RDA interrupt in int_ext. This is pointless. Worse though, get rid of the delay in here. Repeat the mantra _keep interrupt handlers as short as possible_. The delay, is a 'killer', since it implies that interupts will be disabled in delays in the main code (to prevent re-entrancy).
Now, you are going to have a problem, if any data arrives n the 9600bps interface, while receiving the character at 2400bps. Potentially, four characters could arrive on the faster interface, in one 'character time' on the software interface, Since the hardware only buffers two characters, this will cause data loss.
There are quite a few more comments, but these are a starting point...

Best Wishes
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