SSD1306 communication method depends on hardware selection:
OLED style 1
D0 clock D1 data of
four-wire SPI (only one name of SSD1306) RST reset DC data command selection Four-wire SPI (only one name of SSD1306) OLED style 2
D0 clock D1 Data RST reset DC data command select CS chip select
The timing diagram of the four-wire SPI mode, the key point is that the microcontroller must give data on the rising edge of the clock, and the highest bit of a byte is transmitted first. But when G2553 is set later, it needs a falling edge to give data, so I don't understand this.
For the SPI (Universal Serial Communication Interface, SPI Mode) USCI module in G2553,
(1) The four wires are these four wires, and the last STE is the enable wire. G2553 can choose whether STE is high-level enable or low-level (regulation register).
(2) The polarity and phase of the clock line are controlled by registers UCCKPL and UCCKPH. UCCKPL is 1 when controlling SSD1306.
(3) The CS chip selection line can be directly connected to GND.
#include <msp430.h>
#include "oled.h"
// | G2 P1.2|-> Data Out (UCA0SIMO) --D1(OLED)
// | P1.1|<- Data In (UCA0SOMI)
// | P1.4|<- Serial Clock In (UCA0CLK) --D0(OLED)
// | P2.0|->RES(OLED) 任意指定一个引脚
// | P2.1|->DC(OLED) 任意指定一个引脚
// | GND|->CS(OLED) 直接接GND片选上OLED
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */
OLED_Init(); /* OLED初始化 */
OLED_ShowString(0, 0, "QQ137712826", 16, 1);
OLED_ShowString(0, 2, "QQ137712826", 16, 0);
OLED_ShowString(0, 4, "QQ137712826", 8, 1);
OLED_ShowString(0, 5, "QQ137712826", 8, 1);
OLED_ShowString(0, 6, "QQ137712826", 8, 1);
OLED_ShowString(0, 7, "QQ137712826", 8, 1);
while (1)
{
}
}
(4) SPI is faster than IIC protocol, and very stable, refreshing the screen is almost instantaneous. Moreover, IIC needs an address, which is quite troublesome to set up. Although there are many SPI lines, it is not troublesome. After using the hardware SPI method, I prefer OLED.