![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Ports serie USB trensparent
main.cpp@0:0184b799af90, 2022-05-18 (annotated)
- Committer:
- schnf30
- Date:
- Wed May 18 07:48:25 2022 +0000
- Revision:
- 0:0184b799af90
Serie transparent entre USB et Port serie
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
schnf30 | 0:0184b799af90 | 1 | #include "mbed.h" |
schnf30 | 0:0184b799af90 | 2 | #include "platform/mbed_thread.h" |
schnf30 | 0:0184b799af90 | 3 | // Blinking rate in milliseconds |
schnf30 | 0:0184b799af90 | 4 | #define BLINKING_RATE_MS 500 |
schnf30 | 0:0184b799af90 | 5 | RawSerial pc(USBTX,USBRX); |
schnf30 | 0:0184b799af90 | 6 | RawSerial SimXXXX (PA_9,PA_10); |
schnf30 | 0:0184b799af90 | 7 | DigitalOut SimXXXXreset (PA_12); |
schnf30 | 0:0184b799af90 | 8 | |
schnf30 | 0:0184b799af90 | 9 | void SimXXXXreceive() |
schnf30 | 0:0184b799af90 | 10 | { |
schnf30 | 0:0184b799af90 | 11 | if (SimXXXX.readable()) pc.putc(SimXXXX.getc()); |
schnf30 | 0:0184b799af90 | 12 | } |
schnf30 | 0:0184b799af90 | 13 | void pcreceive() |
schnf30 | 0:0184b799af90 | 14 | { |
schnf30 | 0:0184b799af90 | 15 | if (pc.readable()) SimXXXX.putc(pc.getc()); |
schnf30 | 0:0184b799af90 | 16 | } |
schnf30 | 0:0184b799af90 | 17 | int main() |
schnf30 | 0:0184b799af90 | 18 | { |
schnf30 | 0:0184b799af90 | 19 | SimXXXX.baud(115200); |
schnf30 | 0:0184b799af90 | 20 | pc.baud(921600); |
schnf30 | 0:0184b799af90 | 21 | pc.printf("je commence\r\n"); |
schnf30 | 0:0184b799af90 | 22 | pc.printf("reset\r\n"); |
schnf30 | 0:0184b799af90 | 23 | SimXXXXreset.write(0); |
schnf30 | 0:0184b799af90 | 24 | wait(0.2); |
schnf30 | 0:0184b799af90 | 25 | SimXXXXreset.write(1); |
schnf30 | 0:0184b799af90 | 26 | wait(3); |
schnf30 | 0:0184b799af90 | 27 | pc.printf("reset termine\r\n"); |
schnf30 | 0:0184b799af90 | 28 | SimXXXX.attach(&SimXXXXreceive, RawSerial::RxIrq); |
schnf30 | 0:0184b799af90 | 29 | pc.attach(&pcreceive, RawSerial::RxIrq); |
schnf30 | 0:0184b799af90 | 30 | pc.printf("tapez at pour synchroniser la frequence d'horloge\r\n"); |
schnf30 | 0:0184b799af90 | 31 | DigitalOut led(LED1); |
schnf30 | 0:0184b799af90 | 32 | |
schnf30 | 0:0184b799af90 | 33 | while (true) { |
schnf30 | 0:0184b799af90 | 34 | led = !led; |
schnf30 | 0:0184b799af90 | 35 | thread_sleep_for(BLINKING_RATE_MS); |
schnf30 | 0:0184b799af90 | 36 | } |
schnf30 | 0:0184b799af90 | 37 | } |