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

Rda interrupt only twice

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



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

Rda interrupt only twice
PostPosted: Wed May 21, 2008 3:49 am     Reply with quote

Hi, I'm doing a datalogger (RS232->SDCARD)
I'm using a SDCOM-5 module : I send commands and it's written on the sd card (stream SDCOM)
I receive data from rs232 (stream = gill) on the hardware port.
Data is arriving on a continous way : I put data on strings, message and message2. When a '+' (ascii) is detected, I send the string in the main function. I use two strings because I send it with the software port while I still receive data.

Code:
#include <project.h>
#include <STRING.H>

#define DELAI  200

int flag,flag_envoi;
int8 compteur;
char message[256];
char message2[256];

#INT_RDA
serial_isr()
{
if(flag==0) {
   message[compteur] = fgetc(GILL);
   compteur++;
   if (message[compteur-1]=='+') {
      message[compteur]='\0';
      compteur=0;
      flag=1;
      flag_envoi=1;
      }
 }else {
   message2[compteur] = fgetc(GILL);
    compteur++;
    if (message2[compteur-1]=='+') {
      message2[compteur]='\0';
      compteur=0;
      flag=0;
      flag_envoi=1;
      }
  }

}

void main(void)                                             
   {
char retour[20];
int16 i;
int j;
int nb_trame=0;
char tampon;

fprintf(SDCOM, "init \r\n");
delay_ms(DELAI);
fprintf(SDCOM,"fcreate gill.txt \r\n");
delay_ms(DELAI);
fprintf(SDCOM,"fopen gill.txt /a \r\n");
delay_ms(DELAI);
fprintf(SDCOM,"fputs2 \r\n");
delay_ms(DELAI);

compteur=0;
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

flag=0;
flag_envoi=0;
while(nb_trame<=5) {

   if (flag_envoi){

      if(flag==0)   fprintf(SDCOM,"0 %s \r\n",message);
      else fprintf(SDCOM,"1 %s \r\n",message2);
      flag_envoi=0;
      nb_trame++;
   }

}
fprintf(SDCOM,"%c",26);
fprintf(SDCOM,"fclose gill.txt \r\n");


while (1) {
delay_ms(500);
output_b(0xFF);
delay_ms(500);
output_b(0);
}

}
 


project.h :

Code:
#include <18F4620.h>


#fuses HS, NOWDT, NOPROTECT,NOLVP
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,stream=GILL)
#use rs232(baud=115200, xmit=PIN_C0,rcv=PIN_C1,stream=SDCOM)


The problem I have is that the rda interruption is active only twice, after it never interrupts on rda...

Anyone can help me?
Thanks

CCS 4.069 + MPLAB 7 + microchip ICD + "Picdem 2+rhos"
D-Kens



Joined: 09 May 2005
Posts: 35
Location: Toulouse (France)

View user's profile Send private message MSN Messenger

PostPosted: Wed May 21, 2008 4:01 am     Reply with quote

Oh yeah, someone from Toulouse !!! I'm not the only one... Wink

Well, I just had a quick look at your code, but I think you overflow the RS232 buffer, so it stops working after few charcters. In your Header file, you should add the ERRORS option in the definition of your RS232, to prevent the UART from stopping activity when an error occurs.

I don't have time now to look closely at what you wrote, but it seems like a common issue.

Good luck,
Christophe.
Ttelmah
Guest







PostPosted: Wed May 21, 2008 5:00 am     Reply with quote

As a 'separate' thing, I'd alter the serial receive code quite a bit. Array accesses, are quite slow (the compiler has to take the address of the start of the array, add the required offset, then transfer this value to the indirect addressing registers, to read/write the data..). Now it therefore is a lot quicker, to access arrays as little as possible, when storing data in the ISR. So:
Code:

#INT_RDA
void serial_isr(void) {
   int8 temp;
   temp=fgetc(GILL);
   if(flag==0) {
       message[compteur] = temp;
       compteur++;
       if (temp=='+') {
           message[compteur]='\0';
           compteur=0;
           flag=1;
           flag_envoi=1;
      }
   }else {
      message2[compteur] = temp;
      compteur++;
      if (temp=='+') {
         message2[compteur]='\0';
         compteur=0;
         flag=0;
         flag_envoi=1;
      }
  }
}

This 'saves' an array access on every pass through the ISR, which in some cases, may help.
Adding 'ERRORS', should be the default setting. However I can't see 'why' the UART would overflow with the given code. However there are other problems:
1) Are you really _sure_ that a '+', _will_ be received more often than every 256 characters, on the GILL stream?. If it is going to be exactly '256', there is a problem. Compteur, is only an 8 bit integer. As such, it can only hold values from 0 to 255. If there are 256 data bytes, _then_ the '+', Compteur needs to be able to reach 256, and the arrays need to be one character larger.
2) Add 'DISABLE_INTS' to the SDCOM declaration. Though this will _slow_the ability to respond to interrupts on the hardware UART it'll prevent the data corruption that will otherwise occur, if a character arrives, while one is being sent on the 'software' serial.

Best Wishes
gremi



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

PostPosted: Wed May 21, 2008 6:03 am     Reply with quote

D-Kens wrote:
Oh yeah, someone from Toulouse !!! I'm not the only one... Wink

Well, I just had a quick look at your code, but I think you overflow the RS232 buffer, so it stops working after few charcters. In your Header file, you should add the ERRORS option in the definition of your RS232, to prevent the UART from stopping activity when an error occurs.

I don't have time now to look closely at what you wrote, but it seems like a common issue.

Good luck,
Christophe.


It works !! I added ERRORS and it works perfectly ;)

Merci beaucoup Christophe ;)

Ttelmah, thanks for the tip, i've modified my soft ...
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