Added spi_clock_speed function

This commit is contained in:
nopnop2002 2024-03-25 22:28:55 +09:00
parent 9345ea5cdc
commit 0002b64533
3 changed files with 34 additions and 2 deletions

View File

@ -110,6 +110,11 @@ Right:0.96 inch SSD1306
---
# I2C Clock speed
According to the SSD1306 datasheet, the minimum i2c clock cycle time is 2.5us.
Therefore, the maximum i2c clock frequency is 400KHz.
The i2c clock frequency used by this project is 400KHz.
# I2C Port selection
![config-i2c-port](https://github.com/nopnop2002/esp-idf-ssd1306/assets/6020549/7a7de5ec-ef20-42ac-ba70-73ba74a762a7)
@ -119,6 +124,22 @@ If you use this module at the same time as another I2C device using I2C port 0,
---
# SPI Clock speed
According to the SSD1306 datasheet, the minimum SPI clock cycle time is 100ns.
Therefore, the maximum SPI clock frequency is 10MHz.
The SPI clock frequency used by this project is 1MHz.
Higher SPI clock frequencies can be specified using ```spi_clock_speed()```.
```
//int speed = 1000000; // 1MHz
//int speed = 2000000; // 2MHz
//int speed = 4000000; // 4MHz
//int speed = 6000000; // 6MHz
//int speed = 8000000; // 8MHz
int speed = 10000000; // 10MHz
spi_clock_speed(speed);
spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO);
```
# SPI BUS selection
![config-spi-bus](https://user-images.githubusercontent.com/6020549/202815807-6c2df14f-f38e-4032-94fb-da1723607279.jpg)

View File

@ -134,6 +134,9 @@ void ssd1306_fadeout(SSD1306_t * dev);
void ssd1306_dump(SSD1306_t dev);
void ssd1306_dump_page(SSD1306_t * dev, int page, int seg);
#if CONFIG_SPI_INTERFACE
void spi_clock_speed(int speed);
#endif
void i2c_master_init(SSD1306_t * dev, int16_t sda, int16_t scl, int16_t reset);
void i2c_init(SSD1306_t * dev, int width, int height);
void i2c_display_image(SSD1306_t * dev, int page, int seg, uint8_t * images, int width);

View File

@ -20,7 +20,14 @@
#define SPI_COMMAND_MODE 0
#define SPI_DATA_MODE 1
#define SPI_FREQUENCY 1000000; // 1MHz
#define SPI_DEFAULT_FREQUENCY 1000000; // 1MHz
int clock_speed_hz = SPI_DEFAULT_FREQUENCY;
void spi_clock_speed(int speed) {
ESP_LOGI(TAG, "SPI clock speed=%d MHz", speed/1000000);
clock_speed_hz = speed;
}
void spi_master_init(SSD1306_t * dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int16_t GPIO_CS, int16_t GPIO_DC, int16_t GPIO_RESET)
{
@ -59,7 +66,8 @@ void spi_master_init(SSD1306_t * dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int1
spi_device_interface_config_t devcfg;
memset( &devcfg, 0, sizeof( spi_device_interface_config_t ) );
devcfg.clock_speed_hz = SPI_FREQUENCY;
//devcfg.clock_speed_hz = SPI_DEFAULT_FREQUENCY;
devcfg.clock_speed_hz = clock_speed_hz;
devcfg.spics_io_num = GPIO_CS;
devcfg.queue_size = 1;