242
USCI SPI – Interfacing SSD1306 OLED Display
SPI is perhaps best known for the communication speed it offers. This raw communication speed is
most needed when we need to interface external memories and smart displays like TFT displays and
OLED displays. Here, we will see how to interface a SSD1306 OLED display with MSP430 using half-
duplex or unidirectional USCI-based SPI communication bus.
Code Example
HW_SPI.h
#include <msp430.h>
void HW_SPI_init(void);
void SPI_write(unsigned char tx_data);
unsigned char SPI_read(void);
unsigned char SPI_transfer(unsigned char tx_data);
HW_SPI.c
#include "HW_SPI.h"
void HW_SPI_init(void)
{
UCB0CTL1 |= UCSWRST;
UCB0CTL0 = UCCKPH | UCMSB | UCMST | UCMODE_1 | UCSYNC;
UCB0CTL1 = UCSSEL_2;
UCB0BR0 = 8;
UCB0BR1 = 0;
UCB0CTL1 &= ~UCSWRST;
}
void SPI_write(unsigned char tx_data)