出力ポートを,オープンドレインまたはプッシュプルに設定するグローバル関数の使用例. Example of global functions for setting the output port bits as open-drain or push-pull.
Dependencies: mbed UIT_SetOutputPortType
main.cpp
00001 //--------------------------------------------------------------------------------- 00002 // 出力ポートを,オープンドレインまたはプッシュプルに設定するグローバル関数の使用例 00003 // (Example of global functions for setting the output port bit 00004 // as open-drain or push-pull) 00005 // 00006 // 2019/12/17, Copyright (c) 2019 MIKAMI, Naoki 00007 //--------------------------------------------------------------------------------- 00008 00009 #include "SetOutputPortType.hpp" 00010 using namespace Mikami; 00011 00012 // ユーザ・ボタン(青のボタン)を押すまで待つ関数 00013 void WaitButton(char str[]) 00014 { 00015 DigitalIn uButton(USER_BUTTON); 00016 printf(str); 00017 printf("\r\nPush blue button"); 00018 #ifdef STM32F7 00019 while (uButton != 1) {} 00020 #else 00021 while (uButton == 1) {} 00022 #endif 00023 wait(0.5); 00024 } 00025 00026 int main() 00027 { 00028 BusOut bus(D2, D3, D4, D5, D6, D7, D8); 00029 00030 // MODER I/O ポートを,入力/汎用出力/代替え機能/アナログに設定するレジスタ 00031 // PUPDR I/O ポートを,プルアップ,プルダウン,プルアップ・プルダウンなしに設定するレジスタ 00032 // OTYPER 出力のタイプをプッシュプル/オープンドレインに設定するレジスタ 00033 printf("\r\n\nGPIOB mode Reg.: 0x%08x", GPIOB->MODER); 00034 printf("\r\nGPIOB pull-up/pull-down Reg.: 0x%08x", GPIOB->PUPDR); 00035 00036 bus = 0x7F; 00037 SetOpenDrain(D2, D3, D4, D5, D6, D7, D8); 00038 printf("\r\n\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER); 00039 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER); 00040 WaitButton("\r\nD2 - D8: open drain\r\n"); 00041 00042 SetPushPull(D2, D3, D4, D5, D6, D7, D8); 00043 printf("\r\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER); 00044 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER); 00045 WaitButton("\r\nD2 - D8: push-pull\r\n"); 00046 00047 SetOpenDrain(D2); 00048 printf("\r\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER); 00049 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER); 00050 WaitButton("\r\nD2: open drain\r\n"); 00051 00052 SetOpenDrain(D3, D4); 00053 printf("\r\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER); 00054 printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER); 00055 printf("\r\nD2 - D4: open drain\r\n"); 00056 00057 #ifdef STM32F7 00058 DigitalOut pg(PG_0, 0); 00059 WaitButton("\r\nPG_0: push-pull, Output: 0\r\n"); 00060 00061 pg = 1; 00062 WaitButton("\r\nPG_0: push-pull, Output: 1\r\n"); 00063 SetOpenDrain(PG_0); 00064 00065 WaitButton("\r\nPG_0: Open RDain\r\n"); 00066 SetPushPull(PG_0); 00067 WaitButton("\r\nPG_0: push-pull\r\n"); 00068 #endif 00069 00070 printf("\r\nEnd of Test\r\n"); 00071 00072 while (true); 00073 }
Generated on Tue Sep 6 2022 08:26:39 by 1.7.2