Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
attach function not working with Hexiwear
I am writing a serial application with Hexiwear platform . I am trying to configure gsm modem using uart communication. I am sending AT commands to gsm modem and the response from modem will be stored in buffer.
I used attach() function in Serial class to attach a function ( rec() ) . The code i used is,
main.cpp
#include "mbed.h"
Serial pc(USBTX, USBRX);
Serial gsm( PTD3,PTD2);
unsigned char buffer[256];
int counter = 0 ;
void rec() {
pc.printf("in rec\r\n");
if(counter<=255){
buffer[counter]=gsm.getc();
counter++;
}
else counter =0;
}
void Init()
{
pc.printf("init\r\n");
gsm.baud(115200);
gsm.format(8, Serial::None, 1);
pc.baud(115200);
pc.format(8, Serial::None, 1);
gsm.attach(&rec);
}
main()
{
Init();
int j=0,i=0;
const char at[ ] = "ATI\r";
for(j=0;j<4;j++)
{
gsm.putc(at[j]);
}
for ( i=0; i<counter; i++) {
pc.putc(buffer[i]);
}
}
The problem i am facing is that rec() function is never called even though the AT command is successfully send. Please help me with a solution. Thanks
1 Answer
8 years, 4 months ago.
I know this is an old question but I would suggest starting with the Simple attach example. If that works, build your code up from that base incrementally. In my case, the example file hangs a MAX32630FTHR when it triggers. Let us know how it goes.
i solved the issue by using latest available mbed library. earlier i used the hexiwear serial example and added code up on it . With that library (mbed-os) attach is not working.
posted by ADHEETH VK 05 Jul 2017