6 years, 6 months ago.  This question has been closed. Reason: Too broad - no single answer

Problem with serial communication

Hello,

my project is it to build a light barrier with ir receiver (38kHz) via PWM. With a LCD, it works well, but with serial communication (TX,RX) my terminal program shows only tpass= 0.05s (+/- 0.01s).

I am working with nucleo f401re.

My program:

#include "mbed.h"
#include "freetronicsLCDShield.h"

//Serial bt(PA_11, PA_12);//Tx, Rx
//Serial pc (USBTX, USBRX);

Timer timer;

freetronicsLCDShield lcd(D8, D9, D4, D5, D6, D7, D10, A0); 
AnalogIn ain(PA_1);
PwmOut IRLED(PA_15);

float BackLightValue = 1.0;

void start(){
    timer.start();
}
void stop(){
    timer.stop();
    lcd.setCursorPosition(1, 0);
    lcd.printf("tpass= %f s", timer.read());
    bt.printf("tpass= %f s", timer.read());
    pc.printf("The time taken was %f seconds\n", timer.read());
    timer.reset();
}
void pwm(){
    IRLED.period(1.0/38000.0);
    IRLED = 0.5;
    wait_us(100);
    IRLED = 0;
    wait_us(1);
}

int main() {
    bt.baud(9600);
    lcd.setBackLight(BackLightValue);
    lcd.setCursorPosition(0, 0);   
    lcd.printf("BackLight %f",BackLightValue);
    while(1){
        while(1){
            pwm();
            if(ain>0.4f){
                start();
                break;    
            }
        }
        while(1){
            pwm();
            if(ain<0.3f){
                stop();
                break;
            }    
        }
    }

Thanks for your help.

What do you mean with "but with serial communication (TX,RX) my terminal program shows only tpass= 0.05s (+/- 0.01s)."?

posted by Jan Jongboom 03 Oct 2017