stm32f767 oled hal
Dependencies: mbed SSD1308_128x64_I2C
Diff: main.cpp
- Revision:
- 0:18b766aea0ef
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 04 14:35:54 2022 +0000 @@ -0,0 +1,132 @@ + +//i2c_HT16K33_test1_767_1 + +#include "mbed.h" + +#include "main.h" + +#include "SSD1308.h" + + +#define ADDR (0x70<<1) // address + +DigitalOut myled(PB_0); + +I2C_HandleTypeDef hi2c1; + +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; + + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0); + + PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2C1; + PeriphClkInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1; + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); +} + +static void MX_I2C1_Init(void) +{ + hi2c1.Instance = I2C1; + hi2c1.Init.Timing = 0x00303D5B; + hi2c1.Init.OwnAddress1 = 0; + hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; + hi2c1.Init.OwnAddress2 = 0; + hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; + hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; + hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; + HAL_I2C_Init(&hi2c1); + + HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE); + HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0); +} + +static void MX_GPIO_Init(void) +{ + __HAL_RCC_GPIOB_CLK_ENABLE(); +} + +void HAL_MspInit(void) +{ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_RCC_SYSCFG_CLK_ENABLE(); +} + +void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) +{ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(hi2c->Instance==I2C1) { + __HAL_RCC_GPIOB_CLK_ENABLE(); + /**I2C1 GPIO Configuration + PB8 ------> I2C1_SCL + PB9 ------> I2C1_SDA + */ + GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + __HAL_RCC_I2C1_CLK_ENABLE(); + } +} + + + +int main() +{ + + HAL_Init(); + + SystemClock_Config(); + MX_GPIO_Init(); + MX_I2C1_Init(); + + HAL_MspInit(); + + HAL_I2C_MspInit(&hi2c1); + + +SSD1308 oled = SSD1308( &hi2c1 , SSD1308_SA0); +//SSD1308 oled = SSD1308( &hi2c1 , ADDR); + + + + //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 + //pc.printf("Printed something\r\n"); +// printf("Printed something\r\n"); + + //oled.writeString(0, 0, "Hello World !"); + + + + +}//main