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

Dependencies:   mbed

Committer:
emcu
Date:
Wed Dec 27 22:16:04 2017 +0000
Revision:
2:ae247a2441e1
Parent:
1:0de89eebb160
Change date 2018 to 2017

Who changed what in which revision?

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