stm32g031 hal oled
Dependencies: SMALL_HAL_SSD1308_128x64_I2C
Diff: main.cpp
- Revision:
- 0:2633b3dba75d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 11 00:16:18 2022 +0000 @@ -0,0 +1,76 @@ + +//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