Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MbedJSONValue mbed
Diff: main.cpp
- Revision:
- 0:f65ba5fb350e
- Child:
- 1:2b61ae8e6f94
diff -r 000000000000 -r f65ba5fb350e main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Jun 05 14:30:13 2017 +0000
@@ -0,0 +1,194 @@
+////////////////////////////////////////
+// Tau_ReSpeaker_DSP_Test //
+// Arkadiraf@gmail.com - 05/06/2017 //
+////////////////////////////////////////
+/*
+ Receive byte from pc to reroute input outputs
+ b1xxxxxxx - define input port; b10000000 - port 0, b10000001 - port 1, b10000010 - port 2 etc , b10000011 - port 3 etc.
+ b0xxxxxxx - define output ports; b10000001 - port 1, b10000011 - port 1&2, b10000000 - non.
+*/
+
+/*
+ Board : Nucleo STM32F446RE
+ Power Source : USB || Jumper 5V source from STM32 DSP board
+*/
+
+/*
+ Nucleo board modification:
+ to use PH_0 as IO modify boards as followed:
+ SB54 and SB55 ON
+ SB16 and SB50 (MCO) OFF
+ http://www.st.com/content/ccc/resource/technical/document/user_manual/98/2e/fa/4b/e0/82/43/b7/DM00105823.pdf/files/DM00105823.pdf/jcr:content/translations/en.DM00105823.pdf
+*/
+
+/*
+ Pinout:
+ PC - Serial 2
+ PA_2 (Tx) --> STLINK
+ PA_3 (Rx) --> STLINK
+
+ Switch - Serial 3
+ PC_10 (Tx) --> SW_Rx
+ PC_11 (Rx) --> SW_Tx
+
+ I2C_Bus
+ PB_8 --> SCL
+ PB_9 --> SDA
+
+ Digital output :
+ PA_5 --> led (DigitalOut)
+ PA_10 --> SW_Trigger
+
+ MUX: CD74HC4067
+ PC_12 --> MUX_S0
+ PD_2 --> MUX_S1
+ PH_0 --> MUX_S2
+ PH_1 --> MUX_S3
+
+ Speaker Switch : SN74LVC1G3157
+ PB_2 --> EN_SPK_1
+ PB_1 --> EN_SPK_2
+ PB_15 --> EN_SPK_3
+ PB_14 --> EN_SPK_4
+ PB_13 --> EN_SPK_5
+
+ MIC Interrupts:
+ PC_15 --> INTER_1
+ PC_14 --> INTER_2
+ PA_15 --> INTER_3
+ PA_14 --> INTER_4
+ PA_13 --> INTER_5
+
+ Digital Input
+ PC_13 --> BTN (Blue)
+
+ Analog Input
+ PA_0 --> A_DATA_1
+ PA_1 --> A_DATA_2
+ PA_4 --> A_DATA_3
+ PB_0 --> A_DATA_4
+ PC_1 --> A_DATA_5
+
+ Analog Output
+
+
+*/
+
+///////////////
+// Libraries //
+///////////////
+#include "mbed.h"
+#include "BufferedSerial.h" // solves issues of loosing data. alternative doing it yourself
+
+///////////////
+// #defines //
+///////////////
+
+#define DEBUG_MOD1
+
+/////////////
+// Objects //
+/////////////
+
+// uart
+BufferedSerial pc(USBTX, USBRX);
+
+// digital input
+DigitalIn user_button(PC_13);
+
+// digital output
+DigitalOut led(PA_5);
+DigitalOut sw_trigger(PA_10);
+
+// MUX: CD74HC4067
+DigitalOut mux_s0(PC_12);
+DigitalOut mux_s1(PD_2);
+DigitalOut mux_s2(PH_0);
+DigitalOut mux_s3(PH_1);
+
+// speaker switch
+DigitalOut en_spk_1(PB_2);
+DigitalOut en_spk_2(PB_1);
+DigitalOut en_spk_3(PB_15);
+DigitalOut en_spk_4(PB_14);
+DigitalOut en_spk_5(PB_13);
+
+// MIC interrupts
+DigitalOut inter_1(PC_15);
+DigitalOut inter_2(PC_14);
+DigitalOut inter_3(PA_15);
+DigitalOut inter_4(PA_14);
+DigitalOut inter_5(PA_13);
+
+// analog input
+AnalogIn a_data_1(PA_0);
+AnalogIn a_data_2(PA_1);
+AnalogIn a_data_3(PA_4);
+AnalogIn a_data_4(PB_0);
+AnalogIn a_data_5(PC_1);
+
+///////////////
+// variables //
+///////////////
+
+uint8_t in_byte=0;
+
+///////////////
+// Functions //
+///////////////
+
+////////////////////////
+// Main Code Setup : //
+////////////////////////
+int main()
+{
+ pc.baud(57600);
+#ifdef DEBUG_MOD1
+ pc.printf("ReSpeaker Test \r\n");
+#endif
+ ///////////////////////
+ // Main Code Loop : //
+ ///////////////////////
+ while(1) {
+ // check button state
+ if (user_button) {
+ if (pc.readable()) {
+ in_byte=pc.getc();
+#ifdef DEBUG_MOD1
+ pc.putc(in_byte);
+#endif
+ // check if command of input or output
+ if ((bool)(in_byte & 0b10000000)) { // set input
+ mux_s0.write((bool)(in_byte & 0b00000001));
+ mux_s1.write((bool)(in_byte & 0b00000010));
+ mux_s2.write((bool)(in_byte & 0b00000100));
+ mux_s3.write((bool)(in_byte & 0b00001000));
+ } else { // set output
+ en_spk_1.write((bool)(in_byte & 0b00000001));
+ en_spk_2.write((bool)(in_byte & 0b00000010));
+ en_spk_3.write((bool)(in_byte & 0b00000100));
+ en_spk_4.write((bool)(in_byte & 0b00001000));
+ en_spk_5.write((bool)(in_byte & 0b00010000));
+ }
+ }
+ } else {
+ // set default input / output
+ en_spk_1.write(1);
+ en_spk_2.write(1);
+ en_spk_3.write(1);
+ en_spk_4.write(1);
+ en_spk_5.write(1);
+
+ // mux input
+ mux_s0.write(0);
+ mux_s1.write(0);
+ mux_s2.write(0);
+ mux_s3.write(0);
+
+ }
+ }// end main loop
+}// end main
+
+///////////////
+// Functions //
+///////////////