x 過去ログを見よ
x PA_0をOBでGPIOに出来る人むけ
x STM32G031は、秋月で売っているSTM32G031J6M6の事
x SMALL_HAL_SSD1308_128x64_I2Cのライブラリを入れてください。
目的
OLEDのテスト
秋月の0.96 128x64(OLED) P-15870
改造元
忙しい人よう
//HAL_oled_16x24_031_1
#include "mbed.h"
#include "SSD1308.h"
int main() {
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF6_I2C2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
__HAL_RCC_I2C2_CLK_ENABLE();
I2C_HandleTypeDef hi2c2;
hi2c2.Instance = I2C2;
hi2c2.Init.Timing = 0x10707DBC;
hi2c2.Init.OwnAddress1 = 0;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.OwnAddress2 = 0;
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
HAL_I2C_Init(&hi2c2);
HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE);
HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0);
HAL_Delay(200);
SSD1308 oled = SSD1308( &hi2c2 , SSD1308_SA0);
//char n1_8[] = "12345678";
char n1_8[] = "87654321";
//char n1_8[] = "88888888";
int ii=0;
for(int nn=0; nn<8; nn++) {
// y x
oled.writeBigChar(0, ii*16,n1_8[nn]);
ii = ii + 1;
} //for
while(1) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
HAL_Delay(200);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_Delay(200);
}//while
}//main