![](/media/cache/profiles/6d042df5f90546ecee8736241d28dbe1.jpg.50x50_q85.jpg)
Hack the PHS Shield, serial bridge
Fork of PHSShield_F405hack by
Diff: main.cpp
- Revision:
- 1:9cb4854ab263
- Parent:
- 0:90cbfc14fcb7
--- a/main.cpp Mon May 11 15:15:44 2015 +0000 +++ b/main.cpp Wed Jul 01 00:45:54 2015 +0000 @@ -2,42 +2,47 @@ * select: Nucleo F401RE */ #include "mbed.h" +#include "phs_f405.h" + +//#define BAUD 120000 +#define BAUD 9600 Serial pc(PB_6, PB_7); -Serial phs(PA_2, PA_3); -DigitalOut rts(PA_1); -DigitalIn cts(PA_0); +ShieldSerial ser(BAUD); // PC_12, PD_2 +DigitalIn pwron(PC_5), regon(PC_4); +DigitalOut state(PB_1); -DigitalOut led1(PC_6), led2(PC_7); -DigitalOut pwr1(PC_9); -DigitalIn pwr2(PA_8); +Serial phs(PA_2, PA_3); +DigitalOut rts(PA_1), dsr(PA_5); +DigitalIn cts(PA_0), dcd(PA_7), dtr(PA_6), ri(PA_4); +PhsReset reset; // PB_11 +DigitalOut power(PC_9); +DigitalOut led1(PC_7), led2(PC_6); int main() { - pc.baud(115200); - phs.baud(120000); - pwr1 = 0; // DCDC enable - pwr2.mode(PullUp); - GPIOB->MODER = (GPIOB->MODER & ~(3<<22)) | (1<<22); // PB_11 output - GPIOB->OTYPER = (1<<11); // open drain - GPIOB->ODR &= ~(1<<11); // reser=0 -// phs.set_flow_control(Serial::RTSCTS, PA_1, PA_0); + pwron.mode(PullUp); + regon.mode(PullDown); + reset = 0; + power = 0; // DCDC on + led1 = 0; + led2 = 0; + phs.baud(BAUD); cts.mode(PullUp); - rts = 0; - wait_ms(100); - GPIOB->MODER &= ~(3<<22); // PB_11 input - GPIOB->PUPDR = (GPIOB->MODER & ~(3<<22)) | (1<<22); // pullup - - pc.printf("*** PHSShield STM32F405\r\n"); - + dsr = rts = 1; + wait_ms(200); + for (;;) { - if (phs.readable()) { - pc.putc(phs.getc()); + if (phs.readable() && ser.writeable()) { + ser.putc(phs.getc()); } - if (pc.readable()) { - phs.putc(pc.getc()); + if (ser.readable() && phs.writeable()) { + phs.putc(ser.getc()); } - led2 = cts; + + reset = pwron; + led2 = pwron; + dsr = rts = regon; } }