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

problem get a Sms, interrupt RDA

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



Joined: 02 Nov 2008
Posts: 4

View user's profile Send private message

problem get a Sms, interrupt RDA
PostPosted: Sun Nov 02, 2008 5:19 am     Reply with quote

Googler translator:

Hi, I have the following problem, Why do not interrupt the RDA works? Sorry for my English. Thank´s you.
Code:

#include "D:\PIC\movil\lcdtouch18f4525.h"
#define FAST_GLCD;
#include <HDM64GS12_easypic4.c> //Esta es la misma libreria HDM64GS12.C que trae el
                               //ccs pero con la asignacion de pines para la tarjeta
                              //easypic4.
#include "D:\PIC\movil\IMAGENES.h"
#include "D:\PIC\movil\imagen_inicio.h"
#include "D:\PIC\movil\pantalla_configuracion.h"
#include <graphics.c>
#include <string.h>
#include <stdlib.h>
#use rs232 (baud=9600 , xmit=pin_c6, rcv=pin_c7 , bits=8)

#use standard_io(C)
#use standard_io(B)

int16 tmp;
int16 y_min,y_max,x_min,x_max;
int16 y_loc,x_loc,y_rng,x_rng;
int1 touch_flag,line_flag;
char valor_x[5];
char valor_y[4];
char valor_m[9];
char caract[9];
char rx_buffer[100];         // Buffer de recepción
int8 next_rx=0;             // siguiente posición a utilizar
int1 flag_rx_complete=0;     // flag que indica recepción completa   
int1  flag_Writing_INTERNAL_EEPROM; // flag que indica fin de escritura de EEPROM
int8 posicion_memo;



 #int_eeprom
   void eeprom_isr(void){
      flag_Writing_INTERNAL_EEPROM=0;
   }
   
   void escribe_byte_en_EEPROM( char data, int8 memAddress){
   
      flag_Writing_INTERNAL_EEPROM=1;
      enable_interrupts(int_eeprom);
      write_eeprom (memAddress, data);
      while(flag_Writing_INTERNAL_EEPROM==1){/*Espera hasta finalizar la escritura*/}
      disable_interrupts(int_eeprom);
   }
   
   void escribe_buffer_en_EEPROM(void){
      int8 i;
      for(i=0;i< next_rx;i++){
         escribe_byte_en_EEPROM(rx_buffer[i],i);
      }
   }
   




#int_RDA
   RDA_isr(void){
      char c;
     
     if(kbhit()){                // Si hay algo pendiente de recibir ...
     c=getc();                // lo recogemos sobre la variable c
        if(c==0x0D){
                                // Si lo recibido es el carácter especial de fin ...
           flag_rx_complete=1;   // marcamos el fin de la recepción y no hacemos nada mas.
         }
           }
     
         else{                    // En caso contrario ...
        (rx_buffer[next_rx++])=c; // lo guardamos en la posición next_rx de rx_buffer e incrementamos next_rx
         }
       
      }
       


void inicializar_movil()
{

printf("ATE=0\r");   //para quitar el eco
retraso();
printf("AT+CPMS=");  //at+cpms="me" indica al movil donde se guardaran los sms
putc(0x22);  //simbolo comilla "
printf("ME");
putc(0x22);  //simbolo comilla "
putc(0x0D);
retraso();
printf("AT+CNMI=2,3,0,1,0\r");
retraso();
next_rx=0;
}



/**************************************************
*******  Lee la coordenada y   ********************
**************************************************/
int16 y_pos(void)
{
   int16 result;
   set_tris_a(0x04);
   output_a(0x0A);      //Energize X plate, RA1 and RA3
   set_adc_channel(2);   //Set AN2 as input
   delay_us(10);
   result = read_adc(); //get Y axis value
   if (result != 0)
   {
      set_tris_a(0x01);
      set_adc_channel(0);
      delay_us(10);
      tmp = (1023 - read_adc());
      result = (result + tmp) >> 1;   
   }
   Return(result);
}

/**************************************************
*******  Lee la coordenada x   ********************
**************************************************/
int16 x_pos(void)
{
   int16 result;
   set_tris_a(0x02);
   output_a(0x05);      //Energize X plate, RA1 and RA3
   set_adc_channel(1);   //Set AN2 as input
   delay_us(10);
   result = read_adc(); //get Y axis value
   if (result != 0)
   {
      set_tris_a(0x08);
      set_adc_channel(3);
      delay_us(10);
      tmp = (1023 - read_adc());
      result = (result + tmp) >> 1;   
   }   
   Return(result);
}

/**************************************************
***  Funcion para determinar si la pantalla     ***
***  ha sudo pulsada o no...                    ***
**************************************************/
int1 touch(void)
{
   int1 resp;
   int16 tmp,ty,tx;
   resp=false;
   ty = y_pos();
   if (ty > 0)
   {
      delay_ms(30);
      ty=y_pos();
      tx=x_pos();
      if (ty > y_min)
      {
         if(ty < y_max)
         {
            resp = true;
            tmp=(tx - x_min) << 7;
            x_loc =(int16)(tmp/x_rng);
            if(x_loc > 127)  x_loc = 127;
            tmp = (ty - y_min) << 6;
            y_loc = (int16)(tmp/y_rng);
            if(y_loc > 63)   y_loc = 63;
         }
      }
   }
   return(resp);
}

/*************************************************************
*****  Rutina para calibrar la pantalla                *******
*************************************************************/
void calibracion()
{
   int1 sw;
   glcd_fillScreen(OFF);
   glcd_update();
   sw=1;
   while(x_pos()==0)
   {
     glcd_rect(0,0,2,2,YES,SW);
      glcd_update();
      delay_ms(100);
      sw=!sw;
   }
   
 
   delay_ms(30);
   y_min = y_pos();
   x_min = x_pos();
   
   glcd_rect(0,0,2,2,YES,OFF);
   glcd_update();
   while(x_pos() > 0);
   delay_ms(30);
   while(x_pos()==0)
   {
      glcd_rect(125,61,127,63,YES,SW);
      glcd_update();
      delay_ms(100);
      sw=!sw;
   }
   delay_ms(30);
   y_max = y_pos();
   x_max = x_pos();
   y_rng = y_max - y_min;
   x_rng = x_max - x_min;
   while(x_pos() > 0);
   glcd_fillScreen(OFF);
   glcd_update();
 
 
 
 



/**********************************************************
****  muestra las coordenadas   ***************************
**********************************************************/
void print_xy_val()
{
   glcd_rect(13,40,29,57,YES,OFF);
   if(Touch()==true)
   { 
      touch_flag = true;
      sprintf(valor_x,"%lu",x_loc);
      valor_x[4]='\0';
      glcd_text57(13,40,valor_x,1,ON);
      sprintf(valor_y,"%lu",y_loc);
      valor_y[3]='\0';
      glcd_text57(13,50,valor_y,1,ON);
   }
   else
   {
      touch_flag = false;
      glcd_rect(13,40,29,57,YES,OFF);
   }
   //glcd_text57(1,40,x1,1,ON);
   //glcd_text57(1,50,x2,1,ON);
   glcd_update();   
   
}

/*****************************************************************
******  etermina sobre que boton se ha pulsado            ********
*****************************************************************/
int8 boton_act(void)
{
   int8 button;
   if(((x_loc>3) &&(x_loc<17)) &((y_loc>31) &&(y_loc<44))) button = '1';
   if(((x_loc>22) &&(x_loc<37))&((y_loc>31) &&(y_loc<44))) button = '2';
   if(((x_loc>49)&&(x_loc<58))&((y_loc>31) &&(y_loc<44))) button = '3';
   if(((x_loc>65) &&(x_loc<78)) &((y_loc>31)&&(y_loc<44))) button = '4';
   if(((x_loc>85) &&(x_loc<100))&((y_loc>31)&&(y_loc<44))) button = '5';
   if(((x_loc>107)&&(x_loc<121))&((y_loc>31)&&(y_loc<44))) button = '6';
   if(((x_loc>1) &&(x_loc<15)) &((y_loc>49)&&(y_loc<62))) button = '7';
   if(((x_loc>21) &&(x_loc<37))&((y_loc>49)&&(y_loc<62))) button = '8';
   if(((x_loc>42)&&(x_loc<58))&((y_loc>49)&&(y_loc<62))) button = '9';
   if(((x_loc>64) &&(x_loc<78)) &((y_loc>49)&&(y_loc<62))) button = '0';
   if(((x_loc>84) &&(x_loc<101))&((y_loc>49)&&(y_loc<62))) button = 'X';
   if(((x_loc>105) &&(x_loc<124))&((y_loc>49)&&(y_loc<62))) button = 'O';
   return(button);
}


void pitido()
{
//set_tris_a(0x20);
output_high(PIN_A5);
delay_ms(300);
output_low(PIN_A5);

}


void sin_calibrado()
{
y_max=640;
y_min=390;    //valores obtenidos con el archivo lcd_touch_prueba7.hex
x_max=722;    // valores leidos del adc
x_min=324;

y_rng =250;     // valor obtenido de y_max-ymin
x_rng =398;     //valor obtenido de x_max-xmin

glcd_fillScreen(OFF);
glcd_update();   
}   

void teclado()
{
int z;
int1 z2;
int z3;
int8 j;
int8 g2;
int8 g3;
int8 memAddress;

z = 10;
z2 = 0;
z3 = 19;
j=0;
g3=0;

 
  glcd_fillScreen(OFF);
  glcd_update();
  glcd_imagen();
  glcd_update();
  while(1){
 
  if(touch()==true){
  valor_x[0]=boton_act();
  valor_x[1]='\0';

if ((valor_x[0]=='X')&&((z>=13)&&(z<=130))&&((z3>19))&&(z3<=191)){
        delay_ms(100);// evita rebotes escritura     
        pitido();
        if(z2=1)
        {
        z=(z-13);
        z3=(z3-13);       
        z2=0;
         --j;
       
        }
       
        glcd_rect(z,9,z3,23,YES,OFF); //Borra el numero mostrado
               
               
     }
                 
      if ((valor_x[0]>='0')&&(valor_x[0]<='9'))
      {
                     
       if ((z<=117)&&(z3<=171)){
         pitido();                     
         glcd_text57(z,9,valor_x,2,ON); //escribir uno nuevo..
         valor_m[j] =valor_x;
                   
         delay_ms(100);// evita rebotes escritura
        caract[j]=valor_x[0];
        z2=1;
        z=(z+13);
        ++j;
       
        z3=(z3+13);
       
               
          }
      }
                 
      if (valor_x[0]=='O'){
        pitido();
        z=10;
        z3=19;
        if (j<9){
        j=0;
       
        glcd_fillScreen(OFF);
        glcd_update();
        glcd_imagen_error();
        glcd_update();
        while(touch()!=true){
        pitido();
        }     
        glcd_fillScreen(OFF);
        break;
        }
       
       for( g2 = 0 ; g2 <= 9 ; ++g2)
       {
      write_eeprom ((memAddress+g2),caract[g2]);
     
      delay_ms(100);
       }
      j=0;
      glcd_fillScreen(OFF);
      glcd_update();
      glcd_imagen_inicio();
      glcd_update();
     
      break;
      }
     glcd_update();
}
}
}
void modo_configuracion()
{

while(1)
{
if(touch()==true){

if(((x_loc>8) &&(x_loc<110))&((y_loc>10) &&(y_loc<22)))
{
pitido();
calibracion();
break;
}
if(((x_loc>8) &&(x_loc<110))&((y_loc>35) &&(y_loc<48)))
{
pitido();
teclado();
break;

}

}
}
glcd_fillScreen(OFF);
glcd_update();
glcd_imagen_inicio();
glcd_update();

}

void recepcion()
{
if ((rx_buffer[2]=0x2B)&(rx_buffer[3]=0x43)&(rx_buffer[5]=0x54))
{
posicion_memo=rx_buffer[14];

printf("AT+CMGR=");
putc(posicion_memo);
putc(0x0D);
}
}





void main()
{

   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_INTERNAL );
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   inicializar_movil();
    glcd_init(ON);             //Inicializa la glcd
   glcd_fillScreen(OFF);      //Limpia la pantalla
   glcd_update();
   sin_calibrado();
   glcd_imagen_inicio();
   glcd_update();
   next_rx=0;
   pitido();
   do
   {
     if(flag_rx_complete==1){ // Si la recepción está completa ...
   
    escribe_buffer_en_EEPROM(); // escribimos el contenido del buffer en la EEPROM y ...
    next_rx=0;         // ponemos a cero la siguiente posición a utilizar y ...
    flag_rx_complete=0; // ponemos a cero el flag que indica recepción completa. 
    recepcion();
   
    }
     
      if(touch()==true)
      {
      //print_xy_val();
     
     if(((x_loc>27) &&(x_loc<90))&((y_loc>52) &&(y_loc<57)))
{
        pitido();
        glcd_fillScreen(OFF);
        glcd_update();
        glcd_pantalla_configuracion();
        glcd_update();
        modo_configuracion();
         
       
     
      }
     
      }
 }while(true);
 
   
 
}
Ttelmah
Guest







PostPosted: Sun Nov 02, 2008 6:17 am     Reply with quote

You need to narrow down what your actual problem is. Classic debugging. Remove stuff, till the code starts to work.

However, some comments:
Get rid of the INT_EEPROM handler, and enabling the interrupt for this. The existing code, waits for the EEPROM to finish writing, before the write function returns. This is extra complexity, that gains nothing.
Then, in the INT_RDA handler, get rid of the kbhit test. You _only_ get an interrupt, _when_ a character is waiting. There is no point in testing in the interrupt.
Then, in the INT_RDA handler, your buffer handling is dangerous. If the carriage return is not seen, the code will overwrite other things. You should always test buffer addresses, before writing.
Then, you need to add 'errors' to the RS232 definition.
The problem here is that writing the whole buffer to the EEPROM, could take 320mSec. You are not using flow control on the serial, so if the system at the other end carries on sending data, over 300 characters will be lost. This will put the UART, into an 'overrun' state, and it will stop working. 'ERRORS', will clear this (but the data will still have been lost...).
This is probably your main problem. Your sender, needs to stop, and wait while the write occurs.
Do you really need to be storing this data to the EEPROM?. EEPROM, is _not_ designed for things that change at all frequentlty. It is designed for things that are changed infrequenctly, like configuration values. If data was writen continuously from a serial 'stream', you can destroy the EEPROM, in typically just over an hour. If you are looking at data that is likely to change at all often, consider an external FRAM instead.

Best Wishes
Daniv



Joined: 02 Nov 2008
Posts: 4

View user's profile Send private message

PostPosted: Sun Nov 02, 2008 6:54 am     Reply with quote

Hi, thanks for your advice. It is not necessary to write to the eeprom, I do it just to see if it works the use you. Try to use your tips.
I´m sorry my Inglish is very bad.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Nov 02, 2008 8:25 am     Reply with quote

I didn't look well into your code, it is too much, but I noticed a few bugs.

Code:
     if(((x_loc>27) &&(x_loc<90))&((y_loc>52) &&(y_loc<57)))
Change the '&' to '&&'.
You might be lucky and your code is working correct but that is very much dependent on how the compiler represents the values TRUE and FALSE internally. In another compiler or other compiler version it might fail.

Code:
   if(((x_loc>3) &&(x_loc<17)) &((y_loc>31) &&(y_loc<44))) button = '1';
   if(((x_loc>22) &&(x_loc<37))&((y_loc>31) &&(y_loc<44))) button = '2';
   if(((x_loc>49)&&(x_loc<58))&((y_loc>31) &&(y_loc<44))) button = '3';
   if(((x_loc>65) &&(x_loc<78)) &((y_loc>31)&&(y_loc<44))) button = '4';
   if(((x_loc>85) &&(x_loc<100))&((y_loc>31)&&(y_loc<44))) button = '5';
   if(((x_loc>107)&&(x_loc<121))&((y_loc>31)&&(y_loc<44))) button = '6';
   if(((x_loc>1) &&(x_loc<15)) &((y_loc>49)&&(y_loc<62))) button = '7';
   if(((x_loc>21) &&(x_loc<37))&((y_loc>49)&&(y_loc<62))) button = '8';
   if(((x_loc>42)&&(x_loc<58))&((y_loc>49)&&(y_loc<62))) button = '9';
   if(((x_loc>64) &&(x_loc<78)) &((y_loc>49)&&(y_loc<62))) button = '0';
   if(((x_loc>84) &&(x_loc<101))&((y_loc>49)&&(y_loc<62))) button = 'X';
   if(((x_loc>105) &&(x_loc<124))&((y_loc>49)&&(y_loc<62))) button = 'O';
Same error...

Code:
if(z2=1)
Change the '=' to '=='
Daniv



Joined: 02 Nov 2008
Posts: 4

View user's profile Send private message

PostPosted: Sun Nov 02, 2008 10:57 am     Reply with quote

Hello, thank you for your answer. The part of code on that you comment to me works correctly, I suppose that it has been a luck. I go to apply your advice(council). Thank you very much.
Daniv



Joined: 02 Nov 2008
Posts: 4

View user's profile Send private message

PostPosted: Sun Nov 02, 2008 12:31 pm     Reply with quote

What is the difference and & & &? Embarassed Which is correct?

}
Code:

if ((rx_buffer[2]=0x2B)&(rx_buffer[3]=0x43)&(rx_buffer[4]=0x4D)&(rx_buffer[5]=0x54))
{
posicion_memo=rx_buffer[14];

printf("AT+CMGR=");
putc(posicion_memo);
putc(0x0D);
 
--------------- o

if ((rx_buffer[2]=0x2B)&&(rx_buffer[3]=0x43)&&(rx_buffer[4]=0x4D)&&(rx_buffer[5]=0x54))
{
posicion_memo=rx_buffer[14];

printf("AT+CMGR=");
putc(posicion_memo);
putc(0x0D);




I hope that the mobile respond : + CMTI: "ME" *
(* Is the number position in memory storage sms cell.)
I check whether it has reached a +, a C, M and T. If this had come, is that I have received an sms and saved in this position * (stored in rx_buffer [14])

Thank´s you!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 02, 2008 1:03 pm     Reply with quote

Quote:
What is the difference between & and && ?

Look at the sections on Logical and Bitwise operators on page 9 of
this C tutorial:
http://cslibrary.stanford.edu/101/EssentialC.pdf
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Nov 02, 2008 4:04 pm     Reply with quote

Code:
if ((rx_buffer[2]=0x2B)&(rx_buffer[3]=0x43)&(rx_buffer[4]=0x4D)&(rx_buffer[5]=0x54))
Besides the '&' to '&&' replacement, here you have to replace the '=' by '==' too.

Your code will be easier to understand if you don't write the hexadecimal values but the ASCII character instead, for example 'C' instead of 0x43, etc.
The line then becomes:
Code:
if ((rx_buffer[2]=='+') && (rx_buffer[3]=='C') && (rx_buffer[4]=='M') && (rx_buffer[5]=='T'))

... or lookup the strcmp function.
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