HomeSTM32 TutorialsInterface SSD1306 Oled via I2C

Interface SSD1306 OLED Display with STM32 Using I2C

The SSD1306 OLED display is a popular choice for embedded projects due to its compact size, excellent contrast, and low power consumption. It is commonly available as a 0.96-inch 128×64 pixel module, and can communicate using either I2C or SPI protocols.

In this tutorial, we’ll focus on interfacing the SSD1306 OLED display with STM32 microcontrollers using the I2C interface. We will configure the I2C peripheral in STM32CubeMX, generate initialization code using the HAL library, and then write a simple driver to display text and graphics on the OLED screen.

This step-by-step STM32 SSD1306 OLED I2C tutorial is beginner-friendly and works across most STM32 series, including F1, F4, and H7 families. Whether you’re creating a real-time sensor dashboard or adding a stylish display to your project, this tutorial will help you get started quickly.

Recommended Resources:

You can also take a look at the other Oled and LCD Displays interfaced with STM32.

I am going to use a 0.96″ SSD1306 OLED display and STM32f103c8t6 for this project.

Interface 0.96 inch Oled Display with STM32 using I2C

SSD1306 OLED Overview & I2C Advantages

What Is the SSD1306 OLED Display?

The SSD1306 is a monochrome OLED driver IC used in the popular 0.96-inch 128×64 pixel modules found across embedded and IoT projects.

SSD1306 0.96 inch 128x64 monochrome OLED display module with I2C interface pins VCC GND SCL SDA

Unlike LCDs, OLED pixels are self-emissive (no backlight is needed), which delivers deep blacks, high contrast, and wide viewing angles even at low supply currents. Most breakout modules support both I2C and SPI; this tutorial covers the I2C variant.


Key Specifications at a Glance

FeatureSpecification
Display typeMonochrome OLED
Driver ICSSD1306
Resolution128 × 64 pixels
Operating voltage3.3 V or 5 V (module-dependent)
CommunicationI2C (this tutorial) or SPI
Default I2C address0x3C or 0x3D
Viewing angle> 160°
BacklightNone — self-emissive pixels

Why Use I2C with STM32?

The I2C interface is a two-wire serial communication protocol that uses only SDA (data) and SCL (clock) lines. Most STM32 microcontrollers have multiple I2C peripherals built in, making them ideal for connecting displays and sensors with minimal wiring.

Using I2C with the SSD1306 OLED has several advantages:

  • Fewer GPIO Pins: Only two lines are required, which leaves more pins available for other peripherals.
  • Built-in STM32 HAL Support: STM32CubeMX can automatically configure I2C peripherals, making initialization easier.
  • Multiple Devices on One Bus: You can connect several I2C devices (e.g., sensors and displays) to the same bus, reducing complexity.
  • Stable and Reliable Communication: I2C is well-supported by STM32 HAL drivers, so data transfer to the OLED is straightforward and efficient.

For these reasons, I2C is the most common and beginner-friendly method to interface the SSD1306 display with STM32 microcontrollers.

Wiring SSD1306 OLED to STM32

The first practical step in this project is to connect the SSD1306 OLED display to the STM32 board. Since we are using the I2C communication protocol, the wiring is very straightforward. We only need two I2C pins (SDA and SCL) along with power and ground connections.

The image below shows how the STM32 is connected to the SSD1306 Oled Display.

Wiring diagram connecting SSD1306 OLED VCC GND SCL SDA to STM32F103 3.3V and I2C1 pins PB6 PB7

As shown in the image above, the connection is as follows:

ConnectionDescription
VCCConnected to 3.3V pin of the STM32 board (powers the display)
GNDConnected to GND of the STM32 board
SCL (Clock Line)Connected to STM32’s I²C SCL pin
SDA (Data Line)Connected to STM32’s I²C SDA pin

The SSD1306 OLED modules typically operate at either 3.3 V or 5 V, depending on the breakout board. Many modules come with an onboard regulator, which allows them to be powered by 5 V while internally running at 3.3 V.

For STM32, which usually operates at 3.3 V logic levels, it is safest to:

  • Use a 3.3 V supply to power the OLED if supported.
  • If the OLED requires 5 V for VCC, make sure the I2C lines are 5 V tolerant on your STM32 pins (many F1/F4 pins are).
  • Alternatively, use level shifters if your MCU pins are not 5 V tolerant.

CubeMX Setup, Driver Code & Results

Once the OLED is connected to the STM32 board, the next step is to configure the I2C peripheral using STM32CubeMX.

Clock Configuration

Below is the image showing the Clock configuration for the project.

STM32CubeMX clock tree configuration showing 8 MHz HSE crystal with PLL multiplier set to 72 MHz system clock for SSD1306 OLED project

The system is clocked by an external 8MHz HSE Crystal, which is present on the Dev board. We will use the PLL to run the system at maximum 72MHz clock.


I2C Configuration (Fast Mode, 400 kHz)

Below is the image showing the I2C configuration.

STM32CubeMX I2C1 peripheral configuration set to Fast Mode 400 kHz with PB6 SCL and PB7 SDA pins for SSD1306 OLED

I am using I2C1 for the project.

  • Set the I2C in the FAST MODE, as it is required for the OLED Display. The clock speed will automatically set to 400KHz.
  • The SCL and SDA Pins will get automatically selected. Here PB6 is configured as SCL and PB7 is configured as SDA.

Driver Setup — ssd1306.c & ssd1306.h

Copy ssd1306.c, ssd1306.h, fonts.c, and fonts.h from the downloaded project into the Src and Inc folders of your CubeIDE project.

Open ssd1306.c and confirm the I2C handler matches what CubeMX generated:

extern I2C_HandleTypeDef hi2c1;
#define SSD1306_I2C &hi2c1

If you used I2C2 or I2C3 in CubeMX, change hi2c1 to match. Then confirm the resolution defines in ssd1306.h:

#define SSD1306_WIDTH   128
#define SSD1306_HEIGHT   64
Note: The default I2C address in the driver is 0x3C. If your module uses 0x3D (SA0 pin pulled HIGH), update the address define accordingly.

Display Strings on the SSD1306

SSD1306 0.96 inch OLED displaying HELLO at pixel position 10 10 and WORLD exclamation at 10 30 using STM32 HAL I2C
#include "ssd1306.h"
#include "fonts.h"

int main()
{
  .....
  SSD1306_Init (); // initialise the display 
  SSD1306_GotoXY (10,10); // goto 10, 10 
  SSD1306_Puts ("HELLO", &Font_11x18, 1); // print Hello 
  SSD1306_GotoXY (10, 30); 
  SSD1306_Puts ("WORLD !!", &Font_11x18, 1); 
  SSD1306_UpdateScreen(); // update screen
  while (1) { }
}  

SSD1306_Init() sends the full initialization sequence to the OLED. SSD1306_GotoXY(x, y) sets the pixel cursor. SSD1306_Puts() writes to the internal framebuffer. SSD1306_UpdateScreen() must be called to push the framebuffer to the display — nothing appears on screen until it is.


Display Numbers and Floats

SSD1306 OLED displaying integer 123456 on top row and float 123.45 on bottom row formatted with sprintf via STM32 HAL

Any display does not support printing the numbers directly on it. Instead we need to change the number into the equivalent Ascii characters with sprintf before sending:

Below the code shows how to print integer and floats.

#include "ssd1306.h"
#include "fonts.h"
#include "stdio.h"  // for sprintf

int main()
{
  .....
  int num = 123456; float flt = 123.45;
  char bufnum[7]; char bufflt[7];
  SSD1306_Init (); // initialise the display 
  sprintf (bufnum, "%d", num);
  sprintf (bufflt, "%.2f", flt);
  SSD1306_GotoXY (10,10); // goto 10, 10 
  SSD1306_Puts (bufnum, &Font_11x18, 1); // print Hello 
  SSD1306_GotoXY (10, 30); 
  SSD1306_Puts (bufflt, &Font_11x18, 1); 
  SSD1306_UpdateScreen(); // update screen
  while (1) { }
} 
  • The sprintf function is used to convert the integer(%d) and float(%f) values to the respective Ascii format.
  • Then set the cursor at x=10, y=10 and print num at this location.
  • Set the cursor at x=10, y=30 and print flt at this location.
  • We need to call the function SSD1306_UpdateScreen to update the display with the modified content.

Size your buffers to hold the maximum number of characters including sign, decimal point, and the null terminator.


Display Bitmaps

SSD1306 128x64 OLED displaying full-screen bitmap logo drawn with SSD1306_DrawBitmap function via STM32 HAL I2C

The driver’s SSD1306_DrawBitmap() function renders any image that has been converted to a C byte array.

Step 1 — Convert your image: Use the LVGL image converter tool. Set output format to Binary RGB332, color format to Indexed 1-bit, and output to C array. Download the generated .c file and copy the array into bitmap.h in your project.

LVGL online image converter tool configuration showing Binary RGB332 output format and Indexed 1-bit color for SSD1306 bitmap conversion
Generated C array bitmap data in code editor ready to be included as bitmap.h in STM32 CubeIDE SSD1306 project

Step 2 — Draw and update:

#include "ssd1306.h"
#include "bitmap.h"

SSD1306_Init();
SSD1306_DrawBitmap(0, 0, logo, 128, 64, 1);
SSD1306_UpdateScreen();

SSD1306_DrawBitmap(x, y, bitmap, width, height, color) — origin (0,0) is the top-left pixel. Width and height must match your converted image exactly.


Scrolling and Animation

Animated GIF showing SSD1306 OLED bitmap scrolling left and right using hardware scroll registers via SSD1306_ScrollRight and SSD1306_ScrollLeft

The SSD1306 supports hardware-level scrolling via onboard registers, hence no CPU involvement once triggered. Two directions are available:

#include "ssd1306.h"
#include "fonts.h"
#include "stdio.h"  // for sprintf
#include "bitmap.h"

int main()
{
  .....
  SSD1306_Init();
  SSD1306_DrawBitmap(0, 0, logo, 128, 64, 1);
  SSD1306_UpdateScreen(); // update screen

  SSD1306_ScrollRight(0x00, 0x07);    // scroll entire screen (Page0 to Page7) right
  HAL_Delay (5000);
  SSD1306_Stopscroll();

  SSD1306_ScrollLeft(0x00, 0x07);    // scroll entire screen (Page0 to Page7) right
  HAL_Delay (5000);
  SSD1306_Stopscroll();
<p style="margin:0;"></p>  while (1) { }
} 

0x00 to 0x07 selects pages 0–7, covering the full 64-pixel height. Call SSD1306_Stopscroll() before writing new content to the display, otherwise the write will conflict with the active scroll command. Frame-by-frame animation (drawing successive bitmaps in a loop) is demonstrated in the video below.

STM32 SSD1306 OLED I2C — Video Tutorial

Watch the complete walkthrough: CubeMX I2C Fast Mode configuration, SSD1306 driver setup, and HAL code examples for strings, numbers, bitmaps, and scrolling animations on a 128×64 OLED display with STM32F103.

STM32 SSD1306 OLED I2C: FAQs

Conclusion

The SSD1306 over I2C is one of the most practical display setups in embedded development: two GPIO pins, a small HAL-based driver, and you have a 128×64 OLED capable of text, graphics, and hardware-accelerated scrolling.

The pattern scales directly — the same SSD1306_Init() / SSD1306_UpdateScreen() flow works on STM32F1, F4, and H7 with only the HAL include changed. For projects needing more screen real estate or a graphical UI framework, the SH1106 1.3″ OLED tutorial and the U8G2 graphics library port for STM32 are natural next steps. For character-based output where a full graphics buffer isn’t needed, the I2C LCD1602 tutorial offers a leaner alternative.

Download the complete CubeIDE project below — it includes ssd1306.c/.h, fonts.c/.h, and bitmap.h with the full main.c examples for strings, numbers, bitmaps, and scrolling.

Download STM32 SSD1306 OLED I2C Project Files

Complete CubeIDE project including ssd1306.c/.h driver, fonts.c/.h, bitmap.h, and main.c examples for strings, numbers, bitmaps, and scrolling. Free to download — support the work if it helped you.

SSD1306 + I2C CubeMX + HAL source STM32F103

Browse More STM32 Oled Tutorials

About the Author
Arun Rawat
Arun Rawat
Embedded Systems Engineer · Founder, ControllersTech

Arun is an embedded systems engineer with 10+ years of experience in STM32, ESP32, and AVR microcontrollers. He created ControllersTech to share practical tutorials on embedded software, HAL drivers, RTOS, and hardware design — grounded in real industrial automation experience.

Subscribe
Notify of

80 Comments
Newest
Oldest Most Voted
Joe
5 months ago

At line 70 of ssd1306.c, this statement “SSD1306_WRITECOMMAND(0x10);” seems not conform to datasheet. It uses A[1:0] so valid settings are 00b/01b/10b but not 0x10. Could you check that?

Uriel
1 year ago

This configuration uses DMA? If not, can I do some changes for use it?

Hosein
2 years ago

Hello there, how do I add some new/custom fonts instead of using the inner fonts in library files?

Uriel
Reply to  Hosein
1 year ago

Probably like file fonts.h you can add you own custom file .h with your fonts or download a font on internet, there are some programs that create it (pixel font for example)

Sherbeen
2 years ago

I cannot find where to download the following?? Can you please direct me where to find these files that you mentioned?

”Download the code below, unzip it, Copy the fonts.h, test.h and ssd1306.h in the Inc folder of your project, and fonts.c, test.c and ssd1306.c in the Src folder and open the project now.”

Denis
3 years ago

Thank you for very good tutorial. Example runs with minor modification (PB6 & PB7 –> PB8 , PB9) also on NUCLEO-F411RE board and stmcube ide 1.11.0

Maxi Lara
3 years ago

Would it work in any I2C OLED 128×64 display? and 256×64?

Andre Santos
3 years ago

Hi. I am trying to add more fonts. But I did’nt find any program to output 32bit format font archive. Only 8 bit format! Could you tell me wich program did you use? Thanks a lot.

seth
Reply to  Andre Santos
3 years ago

Hi, have you found how to create front ?

Uriel
Reply to  Andre Santos
1 year ago

Probably didn’t exists, fonts are made 16x16pix, and escalates if you want more resolution, or maybe 256×256, but 32 bits?? That will be 65536 x 65536 resolution, not even 8K

Adrian
4 years ago

Great tutorial and well explained. One small change I made to your SSD1306_DrawBitmap function. You can add “else SSD1306_DrawPixel(x+i, y, 0);” right after the if statement to draw a black pixel instead of white. This will make for a very smooth horse running and eliminates the need to clear the screen following each call to DrawBitmap. Thanks again for the awesome video.

Ibrahim KHADRAOUI
4 years ago

Hello Sir,
Thank you for the tutorial it’s awesome and very helpful, I have just one question, can I use this SSD1306 library with FreeRTOS, I think it will be very interesting, we could use an SD card with bitmaps in it and print them on the screen with the OLED display.
Thanks, Sir!

Last edited 4 years ago by Ibrahim KHADRAOUI
ram
4 years ago

if u have possible provide with spi interfacing

Jake Mangels
4 years ago

I am having a problem in ssd1306.c with undefined references to ‘hi2c1’. What fixes can I do?

zhengtata
Reply to  Arun Rawat
3 years ago

i have enabled i2c in cubeMX,why i have the same problem? maybe because there exist 2 i2c?

Harshit
4 years ago

That’s a really helpful tutorial. I want to know if I can connect MPU6050 and the LCD to the same pins at the same time (using I2C only). Will the config of any affect the other.

Harshit
Reply to  Arun Rawat
4 years ago

Thanks a lot!! I really Appreciate it!

George Robertson
5 years ago

Hi, I really liked the tutorial, I wandering if this code can be used for a NUCLEO-F446RE (STM32F446RE)? I have been trying to make it work but I haven’t been able to. Thanks.

Carl
Reply to  George Robertson
4 years ago

Yes , check this video https://www.youtube.com/watch?v=Z6VyFYzQWSs. Just need to change #include “stm32f1xx_hal.h” to f4 inside ssd1306.h.

Luis Moises Lopez Lopez
5 years ago
extern I2C_HandleTypeDef hi2c1;

what function has this code line?

Luis Moises Lopez
5 years ago

I don´t have money for you but, I would like to tell you “I LOVE YOU S MUC FOR THIS.”

NHY
5 years ago

Is it possible to interface the lcd 128x32u using your library?

govardhan
5 years ago

why it is can not downloaded

stmstart
5 years ago

Thank you for your good writing and explanation.

Milad
5 years ago

Hello,
Thank you .
I downloaded the zip file and tried to build the project.
But I have below error :
./Inc/fonts.h:41:10: fatal error: stm32f1xx_hal.h: No such file or directory

What do you think? Can you share me this library please?

Last edited 5 years ago by Milad
stmstart
Reply to  Milad
5 years ago

It works if you change to the same header file as the MCU you use.

Zain
5 years ago

Thanks for this tutorial! Excellent job! I ran into a problem compiling the code first time in a C++ project in STM32CubeIDE: “error: ‘C’ does not name a type; did you mean ‘_C’?” Needed to add quotation marks on C to get it to compile correctly: extern “C” {

Abhay Garg
5 years ago

Hi,
Where is the link for all these libraries which you are mentioned in the above tutorials?

Milad
Reply to  Abhay Garg
5 years ago

If you click on the download but the download does not start, you right click on the download button then copy the address of the line then paste in the search bar.

Zeroache277
Reply to  Milad
3 years ago

The link is obviously broken.. link to a github repo would be much better

Chaitanya
5 years ago

Can Anyone send me the library for SSD1309 for STM32?

Alperen KOLAMUÇ
5 years ago

good work

Alperen KOLAMUÇ
5 years ago

good work

ebe
5 years ago

hi there, really good thanks.. may i ask, could this ssd1306 driver be repurposed for a ssd1327 (128×128) i2c oled ? im using the same ssd1306 code with a different init sequence, however the oled simply doesnt display anything.. any help would be appreciated.. kind thanks

Brandon
5 years ago

Hi! Thanks, it worked perfectly. Is there any LCDAssistant avaliable for Linux distributions?

Serge
5 years ago

Good afternoon. Tell me how you can edit your code to use a smaller buffer?

Abhinav Jha
5 years ago

Brother I started the Payment Process but it says you have exceeded the limit for receiving any more funds.
If this resolves just reply.
Thanks for this contribution

Mukesh kumar
5 years ago

Hello,
I need ssd1306 code for stm8s controller. Actually i have done this , but the problem i am facing is font or size. I am not able to change the size of the letter in my code.
The library i used is from this site.
Please help me out how can i change the size.
http://embedded-lab.com/blog/stm8-microcontrollers-final-chapters/3/

Please help me out how can i change the size.
Thanks you.
m.k.verma795@gmail.com

Gottlieb
5 years ago

hello sir i want ask you something, i make this code to stm32 bluephill and then i get error selected processor does not support `dsb 0xF’ in Thumb mode

Mitchell Kelly
5 years ago

Hallo awesome library
only i have this following error message and i dont know how to get around it can you please help me with it?

.\Objects\OLED_i2c.axf: Error: L6218E: Undefined symbol Font_11x18 (referred from main.o).
.\Objects\OLED_i2c.axf: Error: L6218E: Undefined symbol SSD1306_GotoXY (referred from main.o).
.\Objects\OLED_i2c.axf: Error: L6218E: Undefined symbol SSD1306_Init (referred from main.o).
.\Objects\OLED_i2c.axf: Error: L6218E: Undefined symbol SSD1306_Puts (referred from main.o).
.\Objects\OLED_i2c.axf: Error: L6218E: Undefined symbol SSD1306_UpdateScreen (referred from main.o).
Not enough information to list image symbols.
Not enough information to list load addresses in the image map.
Finished: 2 information, 0 warning and 5 error messages.
“.\Objects\OLED_i2c.axf” – 5 Error(s), 0 Warning(s).

Edit:
Nevermind i fixed it already, i was using Keilv5 IDE, where you cannot just copy paste into the source and inc folder, but you have to add the item to the group by right clicking,
and then i modify it for my stm32f030xx and it worked fine, thank you again

Last edited 5 years ago by Mitchell Kelly
yaniv
5 years ago

thank you for your code just send you a coffee , you saved me some times

hadi alavi
5 years ago

i want sent u donate but we are Boycott bye united state.
very very very thanks 🙂
the best likable aspiration for you.
Thanks Again
from IRAN

Last edited 5 years ago by hadi alavi
Giovanni Sánchez
5 years ago

hi! excellent project, but I have a problem. when I download the .zip, i don´t see any libraries fonts.h, test.h, and ssd1306.h, and neither do libraries fonts.c, test.c and ssd1306.h; but I do see libraries font.d and font.o, likewise with test and ssd1306. Are these libraries similar to .c and .h?

Atir Sharif
6 years ago

HI
IT IS VERY HARD TO SWITCH ON STM32 FROM AVR 8 BIT BUT YOU DID A GREAT JOB FOR ALL PEOPLE LIKE ME . THANKS

Johann dJ
6 years ago

Thank you for the example, got it working on Nucleo-L476RG board

T C
6 years ago

Was anyone able to get this to work on a STM32F466RE?

Joao Pifer
6 years ago

I adapted the code for Nucleo-32, it works perfectly but sometimes it stops working for no reason.
Once the display just scrolled down alone and almost half-top was the bottom part of the display. Then I disassembled the display to try to reset it or something but when I assembled it again it stopped working. This happened to me before but without de scrolling.

The code works perfectly, I was just adjusting some parameters. I have searched some information about it and some people says it’s because of using the nucleo’s power supply but it doesn’t work when I put an external input voltage to the display. Other people says that it is because its power supply is 3V3 not 5V as in this guide but I have also tried it and guess what, sometimes it works and but when you disassemble the display it doesn’t.

If anyone knows why this happens please tell me.

pablito Tapiales
6 years ago

MUCHAS GRACIAS. It works perfectly, you saved my day, I didn’t know how to use it in keil. Thank you so much.
STM32F103 (BLUE-PILL)
SCK (oled) to PB6
SDA(oled) to PB7

Mampfi
7 years ago

Works very well on my STM32F407 board, Thank you!

GLett
7 years ago

A detail…
The ssd1306_I2C_WriteMulti() function has a little bug in the counters, that is the reason why @Oleksandr Gusiev had to change SSD1306_WIDTH 128 to 129
Here is the fix

void ssd1306_I2C_WriteMulti(uint8_t address, uint8_t reg, uint8_t* data, uint16_t count) {
uint8_t dt[256];
dt[0] = reg;
uint8_t i;
for(i = 0; i < count; i++)
dt[i+1] = data[i];
HAL_I2C_Master_Transmit(&hi2c1, address, dt, count+1, 10);
}

I hope it can help to another freaky electronic lover like us 😉

Denis
7 years ago

/* USER CODE BEGIN Includes */
#include “ssd1306.h”
#include “i2c-lcd.h”
/* USER CODE END Includes */
Why i2c-lcd.h in code exists,but in video are not??

Denis
7 years ago

/* USER CODE BEGIN Includes */
#include “ssd1306.h”
#include “i2c-lcd.h”
/* USER CODE END Includes */
Why i2c-lcd.h in code exists,but in video are not?

Liberman
7 years ago

How I can Put float number from adc in the display?

pablito Tapiales
Reply to  Liberman
6 years ago

/* Private variables ———————————————————*/

//variable para LCD
char buf[25];
int dato=1;
…….
…….
while (1)
{

dato +=1;
if(dato>1000)
dato = 5;
dato = ((float)dato/24); // for example
sprintf(buf,”Dat:%.1f”,dato); //convert dato to string
SSD1306_GotoXY (0,0);
SSD1306_Puts (buf, &Font_11x18, 1);

SSD1306_UpdateScreen(); //Update the LCD
//End of LCD display

HAL_Delay(100);
SSD1306_Clear();
}

Sandip Maurya
7 years ago

Thanks Working good,
please tell me command to clear lcd.

ramin_javadi
7 years ago

thanks….
it was fantastic

Oleksandr Gusiev
8 years ago

Hello. I followed your guide. Thanks a lot, it helped me clarify some points, but i have some troubles. First of all https://goo.gl/XD3yQC there are some dots at right side of screen (tested on two screens, same problem). And the second, but the most important, during run in debug, screen looks https://goo.gl/UMFquG at any
debug step, and it is always so when boot pins in such a state. Please, relpy, if possible. Thanks.

Oleksandr Gusiev
Reply to  Oleksandr Gusiev
8 years ago

I fixed this issues. First problem with point to the right – bug into the lib. You should change #define SSD1306_WIDTH 128 in ssd1306.h to 129, cause numeration is starts from zero, not 1. The second problem was it that, I changed boot pins to 1. Both should be at 0.

pablito Tapiales
Reply to  Oleksandr Gusiev
6 years ago

In mi OLED work #define SSD1306_WIDTH 130

thorben
8 years ago

many thanks for this, really good c code

8 years ago

Hi, thanks for the explanation, I’m trying to port this code to a STM32L4 family.
I have managed to change all STM32f1xx lines. As well as changes the I2C number that I’m using hi2c3.

What’s is strange is that I’m getting only one error now which is on a completely different part of the code. It’s telling me the variable “count” needs a constant value. So maybe it’s not receiving anything.

void ssd1306_I2C_WriteMulti(uint8_t address, uint8_t reg, uint8_t* data, uint16_t count) {
uint8_t dt[count + 1];
dt[0] = reg;
uint8_t i;
for(i = 1; i <= count; i++)
dt[i] = data[i-1];
HAL_I2C_Master_Transmit(&hi2c3, address, dt, count, 10);
}

martin
8 years ago

thanks,very professional and useful.

×

Don’t Miss Future STM32 Tutorials

Join thousands of developers getting free guides, code examples, and updates.