so, I bought a cheap OLED module from amazon (
https://www.amazon.com/Diymall-Yellow-Serial-Arduino-Display/dp/B00O2LLT30/ref=sr_1_3?ie=UTF8&qid=1500080882&sr=8-3&keywords=oled++module). it came preconfigured for I2C; so, I tested the module first with arduino and it worked on the adafruit example code for address 0x3C.
I'm trying to roll my own code for the msp430 (maybe make a watch or something) ; so, I made the following code below :
/*************************************************************
// MSP430 I2C OLED Module
//
//
//
//
//
//
//
//
//
************************************************************/
#include <msp430.h>
// SSD1306 PARAMETERS
#define SSD1306_LCDWIDTH 128
#define SSD1306_LCDHEIGHT 64
#define SSD1306_MAXROWS 7
#define SSD1306_MAXCONTRAST 0xFF
// command table
#define SSD1306_SETCONTRAST 0x81
#define SSD1306_DISPLAYALLON_RESUME 0xA4
#define SSD1306_DISPLAYALLON 0xA5
#define SSD1306_NORMALDISPLAY 0xA6
#define SSD1306_INVERTDISPLAY 0xA7
#define SSD1306_DISPLAYOFF 0xAE
#define SSD1306_DISPLAYON 0xAF
// scrolling commands
#define SSD1306_SCROLL_RIGHT 0x26
#define SSD1306_SCROLL_LEFT 0X27
#define SSD1306_SCROLL_VERT_RIGHT 0x29
#define SSD1306_SCROLL_VERT_LEFT 0x2A
#define SSD1306_SET_VERTICAL 0xA3
// address setting
#define SSD1306_SETLOWCOLUMN 0x00
#define SSD1306_SETHIGHCOLUMN 0x10
#define SSD1306_MEMORYMODE 0x20
#define SSD1306_COLUMNADDRESS 0x21
#define SSD1306_COLUMNADDRESS_MSB 0x00
#define SSD1306_COLUMNADDRESS_LSB 0x7F
#define SSD1306_PAGEADDRESS 0x22
#define SSD1306_PAGE_START_ADDRESS 0xB0
// hardware configuration
#define SSD1306_SETSTARTLINE 0x40
#define SSD1306_SEGREMAP 0xA1
#define SSD1306_SETMULTIPLEX 0xA8
#define SSD1306_COMSCANINC 0xC0
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SETDISPLAYOFFSET 0xD3
#define SSD1306_SETCOMPINS 0xDA
// timing and driving
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
#define SSD1306_SETPRECHARGE 0xD9
#define SSD1306_SETVCOMDETECT 0xDB
#define SSD1306_NOP 0xE3
// power supply configuration
#define SSD1306_CHARGEPUMP 0x8D
#define SSD1306_EXTERNALVCC 0x10
#define SSD1306_SWITCHCAPVCC 0x20
#define SSD1306_ADDRESS 0x3C
/*unsigned char init_array_SSD1306 [] = {
0xAE, // Set display OFF
0xD5, // Set Display Clock Divide Ratio / OSC Frequency
0x80, // Display Clock Divide Ratio / OSC Frequency
0xA8, // Set Multiplex Ratio
0x3F, // Multiplex Ratio for 128x64 (64-1)
0xD3, // Set Display Offset
0x00, // Display Offset
0x40, // Set Display Start Line
0x8D, // Set Charge Pump
0x14, // Charge Pump (0x10 External, 0x14 Internal DC/DC)
0x20, // SET MEMORY ADDRESSING MODE
0x02, // horizontal addressing mode
0xA1, // set segment re-map, column address 127 is mapped to SEG0
0xC8, // Set Com Output Scan Direction
0xDA, // Set COM Hardware Configuration
0x12, // COM Hardware Configuration
0x81, // Set Contrast
0xCF, // Contrast
0xD9, // Set Pre-Charge Period
0xF1, // Set Pre-Charge Period (0x22 External, 0xF1 Internal)
0xDB, // Set VCOMH Deselect Level
0x40, // VCOMH Deselect Level
0xA4, // Set all pixels OFF
0xA6, // Set display not inverted
0xAF, // Set display On
0xA5, // all pixels on
};*/
char SSD1306_init[] = {
SSD1306_DISPLAYOFF,
SSD1306_SETLOWCOLUMN,
SSD1306_SETHIGHCOLUMN,
SSD1306_SETSTARTLINE,
SSD1306_SETCONTRAST,
0xcf,
SSD1306_SEGREMAP,
SSD1306_NORMALDISPLAY,
SSD1306_SETMULTIPLEX,
0x3f,
SSD1306_SETDISPLAYOFFSET,
0x00,
SSD1306_SETDISPLAYCLOCKDIV,
0x80,
SSD1306_SETPRECHARGE,
0xf1,
SSD1306_SETCOMPINS,
0x12,
SSD1306_SETVCOMDETECT,
0x40,
SSD1306_CHARGEPUMP,
0x14,
SSD1306_DISPLAYON
};
const unsigned int length = sizeof(init_array_SSD1306)/sizeof(init_array_SSD1306[0]);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
/* Configure P1.6 and P1.7 for I2C */
P1SEL |= BIT6 + BIT7;
P1SEL2 |= BIT6 + BIT7;
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = SSD1306_ADDRESS;
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
unsigned char BYTE_CNT = 0;
__disable_interrupt();
while(BYTE_CNT < length)
{
while (!(IFG2 & UCB0TXIFG));
UCB0TXBUF = init_array_SSD1306[BYTE_CNT++];
}
while (UCB0STAT & UCBUSY); // wait for all to finish
UCB0RXBUF; // clear IFG and overruns
while(1);
}
It is suppose to go through the initialization of the OLED, then try to light up the entire screen with 0xA5.
The commented array is based off someone's code on their msp430. the uncommented code is based on the msp430 booster example code for their package. No dice. so any suggestions on debugging?