出力ポートを,オープンドレインまたはプッシュプルに設定するグローバル関数の使用例. Example of global functions for setting the output port bits as open-drain or push-pull.

Dependencies:   UIT_SetOutputPortType mbed

Committer:
MikamiUitOpen
Date:
Fri May 19 13:42:26 2017 +0000
Revision:
4:b8b4d42fa9fd
Parent:
3:f9dc19059c3b
5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen0:09d27b602681 1//---------------------------------------------------------------------------------
MikamiUitOpen0:09d27b602681 2// 出力ポートを,オープンドレインまたはプッシュプルに設定するグローバル関数の使用例
MikamiUitOpen0:09d27b602681 3// (Example of global functions for setting the output port bit
MikamiUitOpen0:09d27b602681 4// as open-drain or push-pull)
MikamiUitOpen0:09d27b602681 5//
MikamiUitOpen4:b8b4d42fa9fd 6// 2017/05/19, Copyright (c) 2017 MIKAMI, Naoki
MikamiUitOpen0:09d27b602681 7//---------------------------------------------------------------------------------
MikamiUitOpen0:09d27b602681 8
MikamiUitOpen0:09d27b602681 9#include "SetOutputPortType.hpp"
MikamiUitOpen0:09d27b602681 10using namespace Mikami;
MikamiUitOpen0:09d27b602681 11
MikamiUitOpen0:09d27b602681 12// ユーザ・ボタン(青のボタン)を押すまで待つ関数
MikamiUitOpen0:09d27b602681 13void WaitButton(char str[])
MikamiUitOpen0:09d27b602681 14{
MikamiUitOpen3:f9dc19059c3b 15 DigitalIn uButton(USER_BUTTON);
MikamiUitOpen0:09d27b602681 16 printf(str);
MikamiUitOpen0:09d27b602681 17 printf("\r\nPush blue button");
MikamiUitOpen3:f9dc19059c3b 18#ifdef STM32F7
MikamiUitOpen3:f9dc19059c3b 19 while (uButton != 1) {}
MikamiUitOpen3:f9dc19059c3b 20#else
MikamiUitOpen3:f9dc19059c3b 21 while (uButton == 1) {}
MikamiUitOpen3:f9dc19059c3b 22#endif
MikamiUitOpen0:09d27b602681 23 wait(0.5);
MikamiUitOpen0:09d27b602681 24}
MikamiUitOpen0:09d27b602681 25
MikamiUitOpen0:09d27b602681 26int main()
MikamiUitOpen0:09d27b602681 27{
MikamiUitOpen3:f9dc19059c3b 28 BusOut bus(D2, D3, D4, D5, D6, D7, D8);
MikamiUitOpen3:f9dc19059c3b 29
MikamiUitOpen0:09d27b602681 30// MODER I/O ポートを,入力/汎用出力/代替え機能/アナログに設定するレジスタ
MikamiUitOpen0:09d27b602681 31// PUPDR I/O ポートを,プルアップ,プルダウン,プルアップ・プルダウンなしに設定するレジスタ
MikamiUitOpen0:09d27b602681 32// OTYPER 出力のタイプをプッシュプル/オープンドレインに設定するレジスタ
MikamiUitOpen0:09d27b602681 33 printf("\r\n\nGPIOB mode Reg.: 0x%08x", GPIOB->MODER);
MikamiUitOpen0:09d27b602681 34 printf("\r\nGPIOB pull-up/pull-down Reg.: 0x%08x", GPIOB->PUPDR);
MikamiUitOpen0:09d27b602681 35
MikamiUitOpen3:f9dc19059c3b 36 bus = 0x7F;
MikamiUitOpen0:09d27b602681 37 SetOpenDrain(D2, D3, D4, D5, D6, D7, D8);
MikamiUitOpen1:5bf39be14d61 38 printf("\r\n\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER);
MikamiUitOpen1:5bf39be14d61 39 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER);
MikamiUitOpen1:5bf39be14d61 40 WaitButton("\r\nD2 - D8: open drain\r\n");
MikamiUitOpen0:09d27b602681 41
MikamiUitOpen0:09d27b602681 42 SetPushPull(D2, D3, D4, D5, D6, D7, D8);
MikamiUitOpen1:5bf39be14d61 43 printf("\r\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER);
MikamiUitOpen1:5bf39be14d61 44 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER);
MikamiUitOpen1:5bf39be14d61 45 WaitButton("\r\nD2 - D8: push-pull\r\n");
MikamiUitOpen1:5bf39be14d61 46
MikamiUitOpen0:09d27b602681 47 SetOpenDrain(D2);
MikamiUitOpen1:5bf39be14d61 48 printf("\r\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER);
MikamiUitOpen1:5bf39be14d61 49 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER);
MikamiUitOpen1:5bf39be14d61 50 WaitButton("\r\nD2: open drain\r\n");
MikamiUitOpen0:09d27b602681 51
MikamiUitOpen0:09d27b602681 52 SetOpenDrain(D3, D4);
MikamiUitOpen1:5bf39be14d61 53 printf("\r\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER);
MikamiUitOpen1:5bf39be14d61 54 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER);
MikamiUitOpen1:5bf39be14d61 55 printf("\r\nD2 - D4: open drain\r\n");
MikamiUitOpen0:09d27b602681 56
MikamiUitOpen3:f9dc19059c3b 57#ifdef STM32F7
MikamiUitOpen3:f9dc19059c3b 58 DigitalOut pg(PG_0, 0);
MikamiUitOpen3:f9dc19059c3b 59 WaitButton("\r\nPG_0: push-pull, Output: 0\r\n");
MikamiUitOpen3:f9dc19059c3b 60
MikamiUitOpen3:f9dc19059c3b 61 pg = 1;
MikamiUitOpen3:f9dc19059c3b 62 WaitButton("\r\nPG_0: push-pull, Output: 1\r\n");
MikamiUitOpen3:f9dc19059c3b 63 SetOpenDrain(PG_0);
MikamiUitOpen3:f9dc19059c3b 64
MikamiUitOpen3:f9dc19059c3b 65 WaitButton("\r\nPG_0: Open RDain\r\n");
MikamiUitOpen3:f9dc19059c3b 66 SetPushPull(PG_0);
MikamiUitOpen3:f9dc19059c3b 67 WaitButton("\r\nPG_0: push-pull\r\n");
MikamiUitOpen3:f9dc19059c3b 68#endif
MikamiUitOpen3:f9dc19059c3b 69
MikamiUitOpen3:f9dc19059c3b 70 printf("\r\nEnd of Test\r\n");
MikamiUitOpen3:f9dc19059c3b 71
MikamiUitOpen0:09d27b602681 72 while (true);
MikamiUitOpen2:966a8ad956d3 73}