Can some one point me to an idiots guide to using the attach function with serial input.
What I would like to do is use attach to direct the interupt to a function that sets a flag that the main program uses as a signal to tell it to get data from the serial port. This avoids the need for my code to be always monitoring the serail port.
The code below shows a very much simplified version of what i am trying to do. It works to the point of setting the flag but subsequent attempts to send data over the serial port cause the code to go into a loop in my responftoPC function.
#include "mbed.h"
void respondtoPC() ;
Serial pc(USBTX, USBRX); // tx, rx
DigitalOut myled(LED1);
main()
{
struct tm t;
volatile int test ;
test = 0 ;
pc.attach( respondtoPC) ;
while (1)
{
myled = !myled ;
if ( test == 1 )
{
printf("Enter current date and time: \n");
printf("YYYY MM DD HH MM SS[enter] \n");
scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
, &t.tm_hour, &t.tm_min, &t.tm_sec);
// adjust for tm structure required values
t.tm_year = t.tm_year - 1900;
t.tm_mon = t.tm_mon - 1;
// set the time
set_time(mktime(&t));
printf("set time\n");
}
wait(1) ;
}
}
void respondtoPC()
{
char dummy ;
dummy = pc.getc() ;
test++ ;
return ;
}
It seems to me that either I have the major structure wrong or I have my respond code wrong. Of course there may be another explanation.
Thanks in advance.
Allan
Can some one point me to an idiots guide to using the attach function with serial input.
What I would like to do is use attach to direct the interupt to a function that sets a flag that the main program uses as a signal to tell it to get data from the serial port. This avoids the need for my code to be always monitoring the serail port.
The code below shows a very much simplified version of what i am trying to do. It works to the point of setting the flag but subsequent attempts to send data over the serial port cause the code to go into a loop in my responftoPC function.
#include "mbed.h"
void respondtoPC() ;
Serial pc(USBTX, USBRX); // tx, rx
DigitalOut myled(LED1);
main()
{
struct tm t;
volatile int test ;
test = 0 ;
pc.attach( respondtoPC) ;
while (1)
{
myled = !myled ;
if ( test == 1 )
{
printf("Enter current date and time: \n");
printf("YYYY MM DD HH MM SS[enter] \n");
scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
, &t.tm_hour, &t.tm_min, &t.tm_sec);
// adjust for tm structure required values
t.tm_year = t.tm_year - 1900;
t.tm_mon = t.tm_mon - 1;
// set the time
set_time(mktime(&t));
printf("set time\n");
}
wait(1) ;
}
}
void respondtoPC()
{
char dummy ;
dummy = pc.getc() ;
test++ ;
return ;
}
It seems to me that either I have the major structure wrong or I have my respond code wrong. Of course there may be another explanation.
Thanks in advance.
Allan