Libstock
It is currently 02 Sep 2014 22:31

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 08 Jul 2009 20:03 
Offline

Joined: 07 Jul 2009 20:05
Posts: 5
Hi, I am use the UART1_Read_Text to Reads characters received via UART until the delimiter sequence is detected in this case "OK" , when I reset the pic it working properly but after several readings the pic is frozen and justamnete is this function and there is no way to exit this loop until that I reset the pic again

I am use the mikroc Pro V1.65 and the Pic18f452 a 20Mhz.

Can anyone explain this or is it just a bug


Top
 Profile  
 
 Post subject:
PostPosted: 08 Jul 2009 20:57 
Offline

Joined: 16 Aug 2007 03:49
Posts: 1074
Location: St. Louis, MO
I have not used that function yet but I believe it is a blocking call. What value did you set ATTEMPTS to?
Are you checking the overrun and framming bits to see if there is a problem with reception?
I am a fan of using interrupts for reception and that may be helpful (sorry, no code available for this specific post but I have other entries on the forum).

Also, try to post some code.


Top
 Profile  
 
 Post subject:
PostPosted: 08 Jul 2009 21:25 
Offline

Joined: 07 Jul 2009 20:05
Posts: 5
Hi, it is my code:

int i, j, k = 0;
int Test_AT_CSQ = 0;
int received = 0;
char Buffer[16]  ;
char receive;

 
void Modo_RX(){

     UART1_Init(19200);
     Delay_ms(100);

     Test_AT_CSQ = 0;
          do {
           UART1_Write_Text ("AT\r\n");
           Delay_ms(1000);
           UART1_Write_Text ("AT+CSQ\r\n");

           Delay_ms(5000);
           if (UART1_Data_Ready() == 1) {
               receive = UART1_Read();
               if (receive == '\r')  {
                   received = 0;
                   do{
                      if (UART1_Data_Ready() == 1) {
                          PORTD.f0 = 1;
                          UART1_Read_Text(Buffer, "OK", 16);
                          received = 1;
                          PORTD.f0 = 0;
                          }
                   } while(received == 0);

                         // Verifica si es la trama +CSQ = 5 ?
                          if ((Buffer[3] == '+') && (Buffer[4] == 'C') && (Buffer[5] == 'S')&& (Buffer[6] == 'Q')) {
                              if ( Buffer[8] == '5'){
                                  Test_AT_CSQ = 1;
                                  }
                                else Test_AT_CSQ = 0;
                                }
                         }
            }
        } while (Test_AT_CSQ == 0);
 }

void main(){
TRISD = 0;

while (1){
      Modo_RX();
   }
 }


I have put in an LED indicator (PORTD.f0 ) to see where stops the program and just in this function:

UART1_Read_Text(Buffer, "OK", 16);

I have to reset the pic to run again...


Top
 Profile  
 
 Post subject:
PostPosted: 09 Jul 2009 13:31 
Offline
mikroElektronika team
User avatar

Joined: 07 Apr 2009 09:39
Posts: 1321
Hi!

This is not the library bug.
We recommend using the interrupts and state machine when working with the GSM modules.

i.e.
// uart rx interrupt handler
void interrupt(){
char tmp;
  if (PIR1.RCIF == 1) {                          // do we have uart rx interrupt request?
    tmp = UART1_Read();                          // get received byte

// process reception through state machine
// we are parsing only "OK" and "RING" responses
    switch (gsm_state) {
      case  0: {
                response = -1;                   // clear response
                if (tmp == 'O')                  // we have 'O', it could be "OK"
                  gsm_state = 1;                 // expecting 'K'
                if (tmp == 'R')                  // we have 'R', it could be "RING"
                  gsm_state = 10;                // expecting 'I'
                break;
               }
      case  1: {
                if (tmp == 'K') {                // we have 'K' ->
                  response = GSM_OK;             // we have "OK" response
                  gsm_state = 50;                // expecting CR+LF
                }
                else
                  gsm_state = 0;                 // reset state machine
                break;
               }
      case 10: {
                if (tmp == 'I')                  // we have 'I', it could be "RING"
                  gsm_state = 11;                // expecting 'N'
                else
                  gsm_state = 0;                 // reset state machine
                break;
               }
      case 11: {
                if (tmp == 'N')                  // we have 'N', it could be "RING"
                  gsm_state = 12;                // expecting 'G'
                else
                  gsm_state = 0;                 // reset state machine
                break;
               }
      case 12: {
                if (tmp == 'G') {                // we have 'G' ->
                  response = GSM_RING;           // we have "RING" response
                  gsm_state = 50;                // expecting CR+LF
                }
                else
                  gsm_state = 0;                 // reset state machine
                break;
               }
      case 50: {
                if (tmp == 13)                   // we have 13, it could be CR+LF
                  gsm_state = 51;                // expecting LF
                else
                  gsm_state = 0;                 // reset state machine
                break;
               }
      case 51: {
                if (tmp == 10) {                 // we have LF, response is complete
                  response_rcvd = 1;             // set reception flag
                  responseID = response;         // set response ID
                }
                gsm_state = 0;                   // reset state machine
                break;
               }
      default: {                                 // unwanted character
                gsm_state = 0;                   // reset state machine
                break;
               }
    }
  }
}


Visit the link below to see complete GSM code example:

http://www.mikroe.com/zip/gsm-gprs/gm862_pic_examples_v100.zip

Best regards
Slavisa


Top
 Profile  
 
 Post subject:
PostPosted: 09 Jul 2009 14:28 
Offline

Joined: 07 Jul 2009 20:05
Posts: 5
I am sorry, :roll: thank you very much...


Top
 Profile  
 
PostPosted: 23 Jun 2011 01:40 
Offline

Joined: 23 Jun 2011 01:24
Posts: 1
I have exactly the same problem but I need a different solution... This is my code:
UART1_Read_Text(bt_uart_response,"\r\n",30);
UART1_Read_Text(bt_uart_status,"\r\n",10);


When connected to my BlueTooth module in AT command mode (38400 baud) if I issue a command like "AT+UART?" then the response form the BT module is:
"+UART=38400,0,0\r\nOK\r\n" and everything works fine and bt_uart_response string is "+UART=38400,0,0" and bt_uart_status string is "OK". But when I issue a command like "AT+NAME=MyBTModule" then the response is just "OK\r\n" and my MCU hangs there, of course on the second UART1_Read_Text function. Can you help me please how to change the second function, expected strings is just "OK" or nothing. Oh and I forgot, the MCU is PIC18F4520. :)

Greetings, Goran. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: aurbo and 6 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group