.
Dependencies: L432KC_SPI_Pey_Lal
Diff: main.cpp
- Revision:
- 109:4ee7ffc8f175
- Parent:
- 108:2fd41d299a8c
- Child:
- 110:a6d1d3525014
diff -r 2fd41d299a8c -r 4ee7ffc8f175 main.cpp --- a/main.cpp Tue Apr 05 11:19:38 2022 +0000 +++ b/main.cpp Tue Apr 05 13:34:51 2022 +0000 @@ -9,6 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <SPISlave.h> +#include "protocol.h" // Blinking rate in milliseconds @@ -28,9 +29,6 @@ PwmOut propulsion(PWM_PROP); PwmOut direction(PWM_DIR); -DigitalOut led(LED1); - - //Déclarations Liaisons static BufferedSerial serial_port(USBTX, USBRX,115200); SPISlave device(SPI3_MOSI, SPI3_MISO, SPI3_SCLK, SPI3_CS); // mosi, miso, sclk, ssel @@ -38,18 +36,38 @@ int main() { uint32_t pulsewidth_direction = 1100; + uint32_t pulsewidth_propulsion = 1500; + char texte[32]; + sprintf(texte,"Test\n\r"); serial_port.write(texte,strlen(texte)); + propulsion.period_us(20000); - propulsion.pulsewidth_us(1500); + propulsion.pulsewidth_us(pulsewidth_propulsion); + thread_sleep_for(2000); + direction.period_us(20000); direction.pulsewidth_us(pulsewidth_direction); - led = 1; + device.format(8); while (true) { + if (device.receive()) + { + decodeMessage((char)device.read()); + } + if (isDataAvailable()) + { + uint32_t pwms[2]; + getVerifiedPWMValues(pwms); + pulsewidth_propulsion = pwms[0]; + pulsewidth_direction = pwms[1]; + propulsion.pulsewidth_us(pulsewidth_propulsion); + direction.pulsewidth_us(pulsewidth_direction); + } + /* propulsion.pulsewidth_us(1450); @@ -71,19 +89,6 @@ thread_sleep_for(BLINKING_RATE_MS); */ - if (device.receive()) { - led = !led; - int v = device.read(); // Read byte from master - if (v == 'a') - { - //device.reply('o'); - led = 1; - } - else if (v == 'e') - { - //device.reply('n'); - led = 0; - } - } + } }