Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-src MODSERIAL
main.cpp
- Committer:
- edodm85
- Date:
- 2013-10-18
- Revision:
- 2:08505f23f37a
- Parent:
- 1:a11db105c379
- Child:
- 3:2f5485de3328
File content as of revision 2:08505f23f37a:
/*
* Author: Edoardo De Marchi
* Date: 02-07-13
* Notes: HC05 AT command
*/
#include "mbed.h"
#include "MODSERIAL.h"
#define SERIAL_1
#ifdef SERIAL_1
MODSERIAL blue(p9,p10); // HC05
#endif
#ifdef SERIAL_2
MODSERIAL blue(p13,p14); // HC05
#endif
MODSERIAL pc(USBTX, USBRX);
DigitalOut led1(LED1);
DigitalOut led4(LED4);
bool new_send = false;
bool new_response = false;
char ATCmd[80];
char blueChar[80];
void commandAT(char *v) // Send the AT command
{
int i=0;
while(v[i] != NULL)
{
blue.putc(v[i]);
i++;
}
blue.printf("\r\n");
}
// This function is called when a character goes into the RX buffer.
void rxBlueCallback(MODSERIAL_IRQ_INFO *q)
{
new_response = true;
}
// This function is called when a character goes into the RX buffer.
void rxPcCallback(MODSERIAL_IRQ_INFO *q)
{
new_send = true;
}
int main()
{
blue.baud(38400);
pc.baud(9600);
blue.attach(&rxBlueCallback, MODSERIAL::RxIrq);
pc.attach(&rxPcCallback, MODSERIAL::RxIrq);
pc.printf("AT Mode Start\r\n");
while(1)
{
if(new_send)
{
int i = 0;
while(pc.readable())
{
ATCmd[i] = pc.getc();
i++;
}
commandAT(ATCmd);
new_send = false;
}else
if(new_response)
{
int i = 0;
while(blue.readable())
{
blueChar[i] = blue.getc();
i++;
}
printf("Response: %s", blueChar);
new_response = false;
}
wait_ms(100);
}
}