.
https://www.mediafire.com/file/sjhxgn70gxshilg/protocol_spi_pwm.png/file
Revision 112:478ae92cb106, committed 2022-04-26
- Comitter:
- voltxd
- Date:
- Tue Apr 26 11:11:49 2022 +0000
- Parent:
- 111:f11575e7c79b
- Commit message:
- .
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f11575e7c79b -r 478ae92cb106 main.cpp --- a/main.cpp Thu Apr 07 12:30:01 2022 +0000 +++ b/main.cpp Tue Apr 26 11:11:49 2022 +0000 @@ -14,15 +14,18 @@ #define SPI3_CS A3 //Define PWM -#define PWM_PROP D10 -#define PWM_DIR D9 +#define PWM_PROP D9 +#define PWM_DIR D10 + +//fontion interrupt SP +void onRxInterrupt(); //Declaration PWM outputs PwmOut propulsion(PWM_PROP); PwmOut direction(PWM_DIR); //Declaration Links -static BufferedSerial serial_port(USBTX, USBRX,115200); +static UnbufferedSerial serial_port(USBTX, USBRX,115200); SPISlave device(SPI3_MOSI, SPI3_MISO, SPI3_SCLK, SPI3_CS); // mosi, miso, sclk, ssel int main() @@ -34,6 +37,9 @@ //Test Serial port serial_port.write("Test\n\r",strlen("Test\n\r")); + //Interrupt SP + serial_port.attach(&onRxInterrupt, SerialBase::RxIrq); + //Init. propulsion PWM propulsion.period_us(20000); propulsion.pulsewidth_us(pulsewidth_propulsion); @@ -53,7 +59,9 @@ //If SPI received a char, decode it then reply bullshit. if(device.receive()) { - decodeMessage((char)device.read()); + char c = device.read(); + decodeMessage(c); + serial_port.write(&c, 1); device.reply(0b10101010); } @@ -64,5 +72,19 @@ propulsion.pulsewidth_us(pulsewidth_propulsion); direction.pulsewidth_us(pulsewidth_direction); } + } } + +void onRxInterrupt() +{ + char c; + + + // Read the data to clear the receive interrupt. + if (serial_port.read(&c, 1)) { + decodeMessage(c); + serial_port.write(&c, 1); + } + +} \ No newline at end of file