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.
6 years ago. This question has been closed. Reason: Off Topic
A two way serial communication
Hi, I've created a simple two way serial to get AT commands from pc and send them back to a Quectel GSM modem. First I tried to use standard serial from mbed but somehow it stuck (or maybe overflowed) after receiving data from the modem. I used BufferedSerial library https://os.mbed.com/users/sam_grove/code/BufferedSerial which works fine but it lacks some functions like `scanf` or `gets` so I need to read chars by using `getc` function.
#include "mbed.h" #include "BufferedSerial.h" DigitalOut modem_pwr(PD_3); DigitalOut modem_sw(PB_12); Serial pc(PA_9, PA_10); // tx, rx BufferedSerial modem(PC_6, PC_7); void strInput(char str[], int nchars) { int i = 0; int ch; while ((ch = modem.getc()) != '\n' && ch != EOF) { if (i < nchars) { str[i++] = ch; } } str[i] = '\0'; } void two_way_serial() { char temp[200]; if (pc.readable()) { pc.scanf("%[^\n]", temp); if (modem.writeable()) { modem.printf("%s\r\n", temp); memset(temp, 0, sizeof(temp)); } } while (modem.readable()) { strInput(temp, sizeof(temp) - 1); pc.printf("%s\n", temp); memset(temp, 0, sizeof(temp)); } } int main() { relay = 1; modem_pwr = 1; wait_ms(500); pc.baud(115200); modem.baud(115200); modem_sw = 1; wait_ms(2000); modem_sw = 0; wait(2); pc.printf("Setup Complete!\n"); while (1) { two_way_serial(); } }
I have two problems with this code: 1. when I send a command I receive my answer plus all previous commands and answers. 2. after sending some commands I get a huge amount of previous data in the terminal which is strange for me. I'm using an STM32F407 board and using Serial6 pins.
2 Answers
5 years, 11 months ago.
How would you check if it's functioning? Appears as though the exhausting would simply stay there doing the code however you'd have no chance to get of knowing. If you plug your PC into the sequential screen of one of the strenuous at that point you have three things on the sequential port.https://www.assignmentland.co.uk/mba-assignments-writing