for each button pressed nucleo sends a command, used to interface citroen steering wheel command to keenwood car radio

Dependencies:   MBC002-DigitalIn

Fork of steering_wheel_controls_TO_KEENWOOD_RADIO_INFRARED_INTERFACE by luca visconti

Files at this revision

API Documentation at this revision

Comitter:
lucaVisconti
Date:
Wed Jul 04 13:49:20 2018 +0000
Parent:
9:33d8b36e81d4
Commit message:
STM32 NUCLEO-F401RE steering wheel command infrared interface to KEENWOOD CAR RADIO

Changed in this revision

README.md Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 33d8b36e81d4 -r 4ff4a376a6fd README.md
--- a/README.md	Fri Jun 29 12:25:39 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-# Getting started with Blinky on mbed OS
-
-This guide reviews the steps required to get Blinky working on an mbed OS platform.
-
-Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
-
-## Import the example application
-
-From the command-line, import the example:
-
-```
-mbed import mbed-os-example-blinky
-cd mbed-os-example-blinky
-```
-
-### Now compile
-
-Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
-
-```
-mbed compile -m K64F -t ARM
-```
-
-Your PC may take a few minutes to compile your code. At the end, you see the following result:
-
-```
-[snip]
-+----------------------------+-------+-------+------+
-| Module                     | .text | .data | .bss |
-+----------------------------+-------+-------+------+
-| Misc                       | 13939 |    24 | 1372 |
-| core/hal                   | 16993 |    96 |  296 |
-| core/rtos                  |  7384 |    92 | 4204 |
-| features/FEATURE_IPV4      |    80 |     0 |  176 |
-| frameworks/greentea-client |  1830 |    60 |   44 |
-| frameworks/utest           |  2392 |   512 |  292 |
-| Subtotals                  | 42618 |   784 | 6384 |
-+----------------------------+-------+-------+------+
-Allocated Heap: unknown
-Allocated Stack: unknown
-Total Static RAM memory (data + bss): 7168 bytes
-Total RAM memory (data + bss + heap + stack): 7168 bytes
-Total Flash memory (text + data + misc): 43402 bytes
-Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
-```
-
-### Program your board
-
-1. Connect your mbed device to the computer over USB.
-1. Copy the binary file to the mbed device.
-1. Press the reset button to start the program.
-
-The LED on your platform turns on and off.
-
-## Export the project to Keil MDK, and debug your application
-
-From the command-line, run the following command:
-
-```
-mbed export -m K64F -i uvision
-```
-
-To debug the application:
-
-1. Start uVision.
-1. Import the uVision project generated earlier.
-1. Compile your application, and generate an `.axf` file.
-1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger).
-1. Set breakpoints, and start a debug session.
-
-![Image of uVision](img/uvision.png)
-
-## Troubleshooting
-
-1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0`
-
- ```
- mbed --version
- ```
-
- If not, you can update it:
-
- ```
- pip install mbed-cli --upgrade
- ```
-
-2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size.
\ No newline at end of file
diff -r 33d8b36e81d4 -r 4ff4a376a6fd main.cpp
--- a/main.cpp	Fri Jun 29 12:25:39 2018 +0000
+++ b/main.cpp	Wed Jul 04 13:49:20 2018 +0000
@@ -1,29 +1,32 @@
 #include "mbed.h"
 
-// DEFINE AN ARRAY FOR EACH COMMAND I NEED
-
-//int ARRAY_SOURCE[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,1};
-//int ARRAY_TEL[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,1};
+// DEFINE AN ARRAY FOR EACH COMMAND YOU NEED, IT CONTAINS A SEQUENCE OF VALUE FOR EACH COMMAND WE NEED, 
+// SEE DOCUMENTATION: COMMAND PROTOCOL DETAILS
 
-//int ARRAY_SOURCE[] = {9000,4500,560,1690,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,560,560,560,560,560,560,1690,560,560,560,560,560,560,560,1690,560,560,560,1690,560,560,560,560,560,560,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,1690,560,26};
-//int ARRAY_TEL[] = {9000,4500,560,1690,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,560,560,560,560,560,560,1690,560,560,560,560,560,560,560,1690,560,560,560,1690,560,560,560,560,560,560,560,1690,560,1690,560,560,560,1690,560,560,560,1690,560,1690,560,1690,560,26};
-
-int ARRAY_SOURCE[] = {4421,4447,560,1690,560,1690,560,1690,560,560,560,560,560,560,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,560,560,560,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,1690,560,1690,560,1690,560,1690,560,1690,560};
-int ARRAY_TEL[] = {4421,4447,560,1690,560,1690,560,1690,560,560,560,560,560,560,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,560,560,560,560,560,560,560,560,1690,560,1690,560,1690,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,560,1690,560,1690,560,1690,560,1690,560,1690,560};
-
-//DEFINE MY OUTPUTS "led" is IRLED connected on PC_0, "myled" is STM32 NUCLEO board-led
+int ARRAY_SOURCE[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,64,21};
+int ARRAY_TEL[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,21,21,64,21,64,21,21,21,64,21,64,21,21,21};
+int ARRAY_VOLUP[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,1};
+int ARRAY_VOLDWN[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21};
+int ARRAY_FF[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21};
+int ARRAY_RR[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,21,21,64,21,21,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,64,21,64,21};
+int ARRAY_ROTUP[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,21,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21};
+int ARRAY_ROTDWN[] = {342,171,21,64,21,21,21,21,21,64,21,64,21,64,21,21,21,64,21,21,21,64,21,64,21,21,21,21,21,21,21,64,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,21,21,21,21,64,21,64,21,21,21,21,21,64,21,64,21,64,21,64,21};
+    
+//DEFINE MY OUTPUTS: "led" is IRLED (anode connected on PC_0, catode on GND), "myled" is STM32 NUCLEO board-led
 DigitalOut myled(LED1);
 DigitalOut led(PC_0);
 
 
 //Define an input port for each command
-DigitalIn pushButton1(PC_1);
-DigitalIn pushButton2(PC_2);
-//DigitalIn pushButton3(PC_3);
-//DigitalIn pushButton4(PC_4);
-//DigitalIn pushButton5(PC_5);
-//DigitalIn pushButton6(PC_6);
-//DigitalIn pushButton7(PC_7);
+DigitalIn pushButton1(PC_1); //connect "SOURCE" steering wheel controls button to STMF401RE  PC_1 port
+DigitalIn pushButton2(PC_2); //connect "TEL" steering wheel controls button to STMF401RE  PC_2 port
+DigitalIn pushButton3(PC_3); //connect "VOLUP" steering wheel controls button to STMF401RE  PC_3 port
+DigitalIn pushButton4(PC_4); //connect "VOLDWN" steering wheel controls button to STMF401RE  PC_4 port
+DigitalIn pushButton5(PC_5); //connect "FF" steering wheel controls button to STMF401RE  PC_5 port
+DigitalIn pushButton6(PC_6); //connect "RR" steering wheel controls button to STMF401RE  PC_6 port
+DigitalIn pushButton7(PC_7); //connect "ROTUP" steering wheel controls button to STMF401RE  PC_7 port
+DigitalIn pushButton8(PC_8); //connect "ROTDWN" steering wheel controls button to STMF401RE  PC_8 port
+
 
 //int x;
 
@@ -33,47 +36,60 @@
     // Active Pull-Up Resistor
     pushButton1.mode(PullDown);
     pushButton2.mode(PullDown);
-//    pushButton3.mode(PullDown);
-//    pushButton4.mode(PullDown);
-//    pushButton5.mode(PullDown);
-//    pushButton6.mode(PullDown);
-//    pushButton7.mode(PullDown);
-
-   
+    pushButton3.mode(PullDown);
+    pushButton4.mode(PullDown);
+    pushButton5.mode(PullDown);
+    pushButton6.mode(PullDown);
+    pushButton7.mode(PullDown);
+    pushButton8.mode(PullDown);
     // Inifite Loop
 
   while(1) {
 
 // DEFINE for each button pressed which is the array to send
-// IF any button is pressed the outputs level is 0
 int ARRAY_SEND[67];
 int i;
  if(pushButton1 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_SOURCE[i];} }
   else if(pushButton2 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_TEL[i];} }
-          else {
-            
+  else if(pushButton3 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_VOLUP[i];} }      
+  else if(pushButton4 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_VOLDWN[i];} }    
+  else if(pushButton5 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_FF[i];} } 
+  else if(pushButton6 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_RR[i];} }
+  else if(pushButton7 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_ROTUP[i];} }
+  else if(pushButton8 == 1)  { for (i=0;i<67;i++) {ARRAY_SEND[i]=ARRAY_ROTDWN[i];} } 
+// IF any button is pressed the outputs level is 0
+        else {
             // LEDs Turn-Off
             led = 0;
             myled =0;            
         }
-//If a button is 1
-if (pushButton1==1 || pushButton2 ==1 ) {
+//If a button is 1 CREATE A IRPULSE WAVEFORM THAT FOLLOW THE ARRAY_SEND
+if (pushButton1==1 || pushButton2 ==1 || pushButton3 ==1 || pushButton4 ==1 || pushButton5 ==1 || pushButton6 ==1 || pushButton7 ==1 || pushButton8 ==1 ) {
 //From BIT 0 to the final BIT OF ARRAYSEND
-int BIT;
+int BIT,n;
 for (BIT = 0; BIT < 67; BIT ++) {
-//if the position of bit is even turn on the leds for bit value time, 
-//if bit is odd turn off the leds for bit value time  
-  if ( BIT % 2==0) {           
+//if the position of BIT in ARRAYSEND is even, turn on/off the IRLED and BOARD LED following a 38000Hz modulation(13usON/13usOFF) for a number of cicles = BIT value 
+  if ( BIT % 2==0) {  
+  for (n =1; n <= ARRAY_SEND[BIT]; n++){         
              myled =1;
-              led =1;
-             wait_us (ARRAY_SEND[BIT]);}
- 
- else {            
+            led =1;
+             wait_us (13);
+            myled =0;
+            led =0;
+            wait_us (13);
+             }}
+//if the position of BIT in ARRAYSEND is odd, turn off the IRLED and BOARD LED following a 38000Hz modulation(13us+13us=26us OFF) for a number of cicles = BIT value 
+  else {            
+    for (n =1; n <= ARRAY_SEND[BIT]; n++){         
              myled =0;
-              led =0;
-             wait_us (ARRAY_SEND[BIT]);}
-             
+            led =0;
+            wait_us (26);
+             }}
+ } // end for
+ //PUT 100000us OFF at the end of ARRAY_SEND IRPULSE WAVEFORM 
              myled =0;
-              led =0;
-             wait_us (9000);
-}}}}
\ No newline at end of file
+             led =0;
+             wait_us (110000);
+} // end if
+} //end while
+} //end main
\ No newline at end of file