How to use the Adafruit Motor Shield on STM32 NUCLEO 74HC595 + L293D + STM32

Dependencies:   mbed

Committer:
emcu
Date:
Wed Dec 27 16:32:20 2017 +0000
Revision:
0:44fb10b45c97
Child:
1:0de89eebb160
How to use the Adafruit Motor Shield on STM32 NUCLEO; 74HC595 +  L293D

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:44fb10b45c97 1 /*
emcu 0:44fb10b45c97 2
emcu 0:44fb10b45c97 3 By: www.emcu.eu
emcu 0:44fb10b45c97 4 Date: December 2018
emcu 0:44fb10b45c97 5 Simple test for: How to use the Adafruit Motor Shield on STM32 NUCLEO
emcu 0:44fb10b45c97 6 the explanations are here:
emcu 0:44fb10b45c97 7 http://www.emcu.eu/how-to-use-the-adafruit-motor-shield-on-stm32-nucleo/
emcu 0:44fb10b45c97 8 UART Configuration (It is necessary for see the results, we suggest to use TeraTerm on PC)
emcu 0:44fb10b45c97 9 Baud Rate: 9600
emcu 0:44fb10b45c97 10 Data Bit: 8
emcu 0:44fb10b45c97 11 Parity: NONE
emcu 0:44fb10b45c97 12 Stop Bit: 1
emcu 0:44fb10b45c97 13 Flow Control: NONE
emcu 0:44fb10b45c97 14
emcu 0:44fb10b45c97 15 ATTENTION
emcu 0:44fb10b45c97 16 THE SOFTWARE AND HARDWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
emcu 0:44fb10b45c97 17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emcu 0:44fb10b45c97 18 FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
emcu 0:44fb10b45c97 19 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
emcu 0:44fb10b45c97 20 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
emcu 0:44fb10b45c97 21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
emcu 0:44fb10b45c97 22
emcu 0:44fb10b45c97 23 */
emcu 0:44fb10b45c97 24
emcu 0:44fb10b45c97 25
emcu 0:44fb10b45c97 26 #include "mbed.h"
emcu 0:44fb10b45c97 27
emcu 0:44fb10b45c97 28 Serial pc(USBTX,USBRX);
emcu 0:44fb10b45c97 29 DigitalOut LED(LED1);
emcu 0:44fb10b45c97 30
emcu 0:44fb10b45c97 31 DigitalOut clockpin(PB_5); // SCHP or SCK - PB_5
emcu 0:44fb10b45c97 32 DigitalOut latchpin(PA_6); // STCP or RCK - PA_6
emcu 0:44fb10b45c97 33 DigitalOut OE(PA_8); // OE or G
emcu 0:44fb10b45c97 34 DigitalOut datapin(PA_9); // DS or SER - PA_9
emcu 0:44fb10b45c97 35
emcu 0:44fb10b45c97 36 DigitalIn PULS(USER_BUTTON);
emcu 0:44fb10b45c97 37
emcu 0:44fb10b45c97 38 void PressBB(void);
emcu 0:44fb10b45c97 39 void WaitSerialChar(void);
emcu 0:44fb10b45c97 40
emcu 0:44fb10b45c97 41 int n = 0;
emcu 0:44fb10b45c97 42
emcu 0:44fb10b45c97 43
emcu 0:44fb10b45c97 44 int main() {
emcu 0:44fb10b45c97 45
emcu 0:44fb10b45c97 46 const int number[10][8]=
emcu 0:44fb10b45c97 47 {// Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 Line
emcu 0:44fb10b45c97 48 { 1, 0, 1, 0, 1, 0, 1, 0}, // 0
emcu 0:44fb10b45c97 49 { 0, 1, 0, 1, 0, 1, 0, 1}, // 1
emcu 0:44fb10b45c97 50 { 1, 0, 1, 1, 0, 1, 1, 0}, // 2
emcu 0:44fb10b45c97 51 { 1, 0, 0, 1, 1, 1, 1, 1}, // 3
emcu 0:44fb10b45c97 52 { 1, 1, 0, 0, 1, 1, 0, 0}, // 4
emcu 0:44fb10b45c97 53 { 1, 1, 0, 1, 1, 0, 1, 1}, // 5
emcu 0:44fb10b45c97 54 { 1, 1, 1, 1, 1, 0, 0, 0}, // 6
emcu 0:44fb10b45c97 55 { 0, 0, 0, 0, 1, 1, 1, 1}, // 7
emcu 0:44fb10b45c97 56 { 1, 1, 1, 1, 1, 1, 1, 0}, // 8
emcu 0:44fb10b45c97 57 { 1, 1, 0, 0, 1, 1, 1, 1} // 9
emcu 0:44fb10b45c97 58 };
emcu 0:44fb10b45c97 59
emcu 0:44fb10b45c97 60 pc.printf("\n\r\n\r\n\r The explanations are here:\n\r");
emcu 0:44fb10b45c97 61 pc.printf(" http://www.emcu.eu/how-to-use-the-adafruit-motor-shield-on-stm32-nucleo/ \n\r");
emcu 0:44fb10b45c97 62 while(1)
emcu 0:44fb10b45c97 63 {
emcu 0:44fb10b45c97 64 OE = 0;
emcu 0:44fb10b45c97 65
emcu 0:44fb10b45c97 66 pc.printf("\n\r\n\r START... \n\r\n\r");
emcu 0:44fb10b45c97 67 pc.printf(" 74HC595 \n\r");
emcu 0:44fb10b45c97 68 pc.printf(" _______ \n\r");
emcu 0:44fb10b45c97 69 pc.printf(" Q1 1 |_| 16 VCC \n\r");
emcu 0:44fb10b45c97 70 pc.printf(" Q2 2 15 Q0 \n\r");
emcu 0:44fb10b45c97 71 pc.printf(" Q3 3 14 DS \n\r");
emcu 0:44fb10b45c97 72 pc.printf(" Q4 4 13 /OE \n\r");
emcu 0:44fb10b45c97 73 pc.printf(" Q5 5 12 STCP\n\r");
emcu 0:44fb10b45c97 74 pc.printf(" Q6 6 11 SHCP\n\r");
emcu 0:44fb10b45c97 75 pc.printf(" Q7 7 10 /MR \n\r");
emcu 0:44fb10b45c97 76 pc.printf("GND 8_______ 9 Q7S \n\r\n\r");
emcu 0:44fb10b45c97 77
emcu 0:44fb10b45c97 78 for(int j=0;j<=1;j++) // 9
emcu 0:44fb10b45c97 79 {
emcu 0:44fb10b45c97 80 latchpin=0;
emcu 0:44fb10b45c97 81
emcu 0:44fb10b45c97 82 pc.printf(" Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0\n\r");
emcu 0:44fb10b45c97 83 for(int i=0;i<=7;i++)
emcu 0:44fb10b45c97 84 {
emcu 0:44fb10b45c97 85 pc.printf(" %d ", number[j][i]);
emcu 0:44fb10b45c97 86 datapin=number[j][i];
emcu 0:44fb10b45c97 87 wait_ms(1);
emcu 0:44fb10b45c97 88 clockpin=1;
emcu 0:44fb10b45c97 89 wait_ms(1);
emcu 0:44fb10b45c97 90 clockpin=0;
emcu 0:44fb10b45c97 91 wait_ms(1);
emcu 0:44fb10b45c97 92 }
emcu 0:44fb10b45c97 93
emcu 0:44fb10b45c97 94 latchpin=1;
emcu 0:44fb10b45c97 95 wait_ms(5);
emcu 0:44fb10b45c97 96 latchpin=0;
emcu 0:44fb10b45c97 97 wait_ms(1);
emcu 0:44fb10b45c97 98 OE = 1;
emcu 0:44fb10b45c97 99 wait_ms(1);
emcu 0:44fb10b45c97 100 OE = 0;
emcu 0:44fb10b45c97 101 wait_ms(1);
emcu 0:44fb10b45c97 102
emcu 0:44fb10b45c97 103 WaitSerialChar();
emcu 0:44fb10b45c97 104 pc.printf(" \n\r");
emcu 0:44fb10b45c97 105
emcu 0:44fb10b45c97 106 }
emcu 0:44fb10b45c97 107 pc.printf(" END.... \n\r");
emcu 0:44fb10b45c97 108 WaitSerialChar();
emcu 0:44fb10b45c97 109
emcu 0:44fb10b45c97 110 }
emcu 0:44fb10b45c97 111 }
emcu 0:44fb10b45c97 112
emcu 0:44fb10b45c97 113
emcu 0:44fb10b45c97 114 void WaitSerialChar(void)
emcu 0:44fb10b45c97 115 {
emcu 0:44fb10b45c97 116 pc.printf(" Press a key on PC to continue\n\r");
emcu 0:44fb10b45c97 117 while (pc.readable() != 1);
emcu 0:44fb10b45c97 118 pc.getc();
emcu 0:44fb10b45c97 119 }
emcu 0:44fb10b45c97 120
emcu 0:44fb10b45c97 121
emcu 0:44fb10b45c97 122 void PressBB(void)
emcu 0:44fb10b45c97 123 {
emcu 0:44fb10b45c97 124 pc.printf("Press Blue Button on PC to continue\n\r");
emcu 0:44fb10b45c97 125 while (PULS != 0) // Button not pressed
emcu 0:44fb10b45c97 126 {
emcu 0:44fb10b45c97 127 LED = !LED;
emcu 0:44fb10b45c97 128 wait(0.1);
emcu 0:44fb10b45c97 129 }
emcu 0:44fb10b45c97 130 }