5360 views|4 replies

1

Posts

0

Resources
The OP
 

STM32F103C8T6 minimum system development board connected to 7-pin SPI OLED routine [Copy link]



I am a poor student, using the stm32f103c8t6 minimum system development board to make a 7-pin spi OLED. I want a routine to show the pin connection. Thank you!
This content is originally created by EEWORLD forum user picaj . If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

This post is from stm32/stm8

Latest reply

It is from LL library I learned something. Thanks.   Details Published on 2019-12-16 10:45
 

295

Posts

1

Resources
2
 

There are a lot, but you have to transplant it yourself, so you can learn a lot

This post is from stm32/stm8
 
Personal signature

我的小站 我的博客

 

4005

Posts

0

Resources
3
 

#include "stm32f4xx_hal.h"
#include "main.h"
#include "OLED.h"
#include "SPI.h"

#define OLED_CS_Set() //OLED_CS_GPIO_Port->ODR |= OLED_CS_Pin
#define OLED_CS_Clr() //OLED_CS_GPIO_Port->ODR &=~OLED_CS_Pin

void Delay_ms(uint32_t ms) {
ms+=HAL_GetTick();
while (HAL_GetTick()<=ms);
}
void OLED_WR_Dat(uint8_t da) {
//spi1 sends
LL_SPI_TransmitData8(SPI1,da);
while (!LL_SPI_IsActiveFlag_TXE(SPI1)) ;
while (LL_SPI_IsActiveFlag_BSY(SPI1));

}
void OLED_WR_Cmd(uint8_t da) {
OLED_DC_GPIO_Port->ODR &= ~OLED_DC_Pin;
OLED_WR_Dat(da);
OLED_DC_GPIO_Port->ODR |= OLED_DC_Pin;
}

//Set row and column addresses
void OLED_Set_Pos(unsigned char x, unsigned char y) {
OLED_WR_Cmd(0xb0+y);
OLED_WR_Cmd(((x&0xf0)>>4)|0x10);
OLED_WR_Cmd((x&0x0f)|0x01);
}
//Turn on OLED display
void OLED_Display_On(void) {
OLED_WR_Cmd(0X8D ); //SET DCDC command
OLED_WR_Cmd(0X14 ); //DCDC ON
OLED_WR_Cmd(0XAF ); //DISPLAY ON
}
//Turn off OLED display
void OLED_Display_Off(void) {
OLED_WR_Cmd(0X8D ); //SET DCDC command
OLED_WR_Cmd(0X10 ); //DCDC OFF
OLED_WR_Cmd(0XAE ); //DISPLAY OFF
}
//Clear screen function!
/**/void OLED_Clear(uint8_t da) {
uint16_t n;
for(n=0;n<128*8;n++) OLED_WR_Dat(da);
//The data low bit is on the top! !
}
/**************************/
//1k refresh buffer
uint8_t OLED_Buffer[OLEDBUFFER_SIZE];
uint32_t OLED_BufBitAddr;
static volatile uint16_t OLED_Refresh_Cnt=0;

void clsbuf(void) {
uint32_t i;
for (i=0;i<1024;i++)
OLED_Buffer[i]=0x0;
}

//Initialize SSD1306
void Oled_Init(void) {
LL_SPI_Enable(SPI1);
OLED_CS_Clr();
OLED_DC_GPIO_Port->ODR |= OLED_DC_Pin; //Default data status

OLED_WR_Cmd(0xAE );//--turn off oled panel
OLED_WR_Cmd(0x00 );//---set low column address OLED_WR_Cmd(
0x10 );//---set high column address
OLED_WR_Cmd(0x40 );//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
OLED_WR_Cmd(0x81 );//--set contrast control register
OLED_WR_Cmd(0xCF ); // Set SEG Output Current Brightness
/****Modify to fill from bottom left to top and right****/
OLED_WR_Cmd(0xA1 );//--Set SEG/Column Mapping 0xa0 reverse 0xa1 normal
OLED_WR_Cmd(0xC0 );//Set COM/Row Scan Direction 0xc0 up and down inversion 0xc8 normal
OLED_WR_Cmd(0xA6);//--set normal display
OLED_WR_Cmd(0xA8);//--set multiplex ratio(1 to 64)
OLED_WR_Cmd(0x3f);//--1/64 duty
OLED_WR_Cmd(0xD3);//-set display offset Shift Mapping RAM Counter (0x00 ~0x3F)
OLED_WR_Cmd(0x00 );//-not offset
OLED_WR_Cmd(0xd5 );//--set display clock divide ratio/oscillator frequency
OLED_WR_Cmd(0x80 );//--set divide ratio, Set Clock as 100 Frames/Sec
OLED_WR_Cmd(0xD9 );//--set pre-charge period
OLED_WR_Cmd(0xF1 );//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
OLED_WR_Cmd(0xDA );//--set com pins hardware configuration
OLED_WR_Cmd(0x12 );
OLED_WR_Cmd(0xDB );//--set vcomh
OLED_WR_Cmd(0x40 );//Set VCOM Deselect Level
OLED_WR_Cmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
OLED_WR_Cmd(0x01);//00 Horizontal Address Mode//01 Vertical Address Mode
OLED_WR_Cmd(0x8D);//--set Charge Pump enable/disable
OLED_WR_Cmd(0x14);//--set(0x10) dis able
OLED_WR_Cmd(0xA4 );// Disable Entire Display On (0xa4/0xa5)
OLED_WR_Cmd(0xA6 );// Disable Inverse Display On (0xa6/a7)
OLED_WR_Cmd(0xAF );//--turn on oled panel

OLED_Display_On();
OLED_BufBitAddr=0x22000000+((uint32_t)OLED_Buffer-0x20000000)*32;
clsbuf();
OLED_Refresh();
}

void SPI1_IRQHandler(void) {
// OLED_Refresh_Cnt++;
if (SPI1->SR & LL_SPI_SR_TXE) {
if (OLED_Refresh_Cnt<OLEDBUFFER_SIZE) {
//Not completed
LL_SPI_TransmitData8(SPI1,OLED_Buffer[OLED_Refresh_Cnt&1023]);
OLED_Refresh_Cnt++;
//End early
if (O LED_Refresh_Cnt ==OLEDBUFFER_SIZE) {
OLED_Refresh_Cnt=0;
LL_SPI_DisableIT_TXE(SPI1);
}
}
}}
void OLED_Refresh(void) {
LL_SPI_TransmitData8(SPI1,OLED_Buffer[0]);
OLED_Refresh_Cnt++;
LL_SPI_EnableIT_TXE(SPI1);
}

This post is from stm32/stm8

Comments

This is the study of LL library, thank you.  Details Published on 2019-12-16 10:45
 
 

4005

Posts

0

Resources
4
 

This is the spi dma screen refresh I made not long ago, 60HZ is no problem

This post is from stm32/stm8
 
 
 

39

Posts

1

Resources
5
 
huo_hu Published on 2019-12-11 13:22 #include "stm32f4xx_hal.h" #include "main.h" #include "OLED.h" #include "SPI.h" ...

It is from LL library

I learned something. Thanks.

This post is from stm32/stm8
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list