5 years ago.

strange situetion with serial

hi to all i have this situetion, i use this shield http://www.cooking-hacks.com/documentation/tutorials/arduino-gprs-gsm-quadband-sim900, and i write this software

t

#include "mbed.h"
Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication
Serial SIM900(PA_9, PA_10);    // serial comunication 
DigitalOut sim_power(D9);  // sim power 

// power to shield sim900
void power()
 {
 sim_power.write(1);
 wait(3);
    sim_power.write(0);
  wait(19);   
    }
// i read the serial answer
	void callback_rx() {
	 pc.printf("%c", SIM900.getc());
	}
int main() {
power();    
	wait_ms(100); 
pc.printf("\r\n GSM 900 TEST\n"); 
SIM900.attach(&callback_rx);  
    SIM900.baud(9600); // oppure 115200
          
    while(1) {
 
      SIM900.printf("AT\r");
       wait_ms(1000); 	
  
}
}

All work well, when i send the AT comand the shield send me the ok now i want save this answare in a variable and i write this

#include <string>
string result;
....

void callback_rx() {
//	 pc.printf("%c", SIM900.getc());
	 char x;
    x = SIM900.getc();
    result += x;
   pc.putc(x);
	
	}

i don't see nothing, i want save the answer of shield for check it if all is ok, can you help me? best regards antonio

Are you still getting interrupts? If you don't read all of the waiting data in your interrupt you may not get any more generated. Given the baud rate and simplicity of the code this shouldn't be a problem but just to be safe you should do:

string result = "";

void callback_rx() {
    char x;
    while (SIM900.readable()) {
      x = SIM900.getc();
      result += x;
      pc.putc(x);
  }
}
posted by Andy A 30 Sep 2014

thanks now all work well,

posted by Antoniolinux B. 03 Oct 2014
Comment on this question
Be the first to answer this question.

Assigned to Antoniolinux B. 5 years ago.

This means that the question has been accepted and is being worked on.

You need to log in to post a question