pascal coulbeaux
/
Nucleo_F411RE_UART
use serial6, RX interrupt, frame transmitted on TX, analog A0, button state
Diff: main.cpp
- Revision:
- 0:07fbd0b5bebd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Dec 21 16:00:01 2014 +0000 @@ -0,0 +1,71 @@ +#include "mbed.h" + +char tx_buffer [6]= {0x54,0x41,0x55,0x01,0xFF,0x0D}; +int tx_buffer_size=5; +char rx_buffer =0; +int cana0 = 0; +int membouton = 0; +int i = 1; +int j = 0; + +DigitalOut myledred(D2); +DigitalOut myled(LED1); +DigitalOut myledgreen(D3); +DigitalIn mybutton (D4); +AnalogIn inputan0(A0); +Serial pc(USBTX, USBRX); //for test +Serial RXTX ( PA_11, PA_12 ); //module bluetooth RN42-XV connected on PA11-PA12 + + +void serialInterrupt() +{ + rx_buffer = RXTX.getc(); +} +int main() { + + RXTX.printf("Hello World !\n"); + RXTX.attach(&serialInterrupt); + + while(1) + { + if(rx_buffer == 'a'){myledred = 1;rx_buffer=0;} // LED is ON + + if(rx_buffer == 'e'){myledred = 0;rx_buffer=0;} // LED is OFF + + if(rx_buffer == 't') //transmission frame on demand + { + for (int j=0; j<tx_buffer_size +1; j++) + { + RXTX.putc(tx_buffer[j]); + rx_buffer=0; + } + } + + cana0 = inputan0.read_u16(); //CAN input A0 + wait(0.001f); + + tx_buffer [4] = cana0; //store LSB CAN A0 in frame + tx_buffer [3] = ((cana0&0xFF00)>>8); //store MSB CAN A0 in frame + + if(mybutton==0) //detection of button state + { + if(membouton==0) + { + membouton=1; + myledgreen = ! myledgreen; + } + } + else + { + if(membouton==1) + {membouton=0;} + } + + tx_buffer [2] = myledgreen; //store button state in frame + + wait(0.1); //tempo 100ms in loop + for (int j=0; j<tx_buffer_size +1; j++) //transmission frame in loop + { + RXTX.putc(tx_buffer[j]); + } + }}