msp430 and OLED (SSD1306 Driver ) - Page 1
Forum section: electronics / general

author: kubuni
author_rank: Newbie
timestamp: July 15, 2017, 01:20:37 am
content: 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 :Code:/*************************************************************// 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_PAGEADDRESS0x22#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 OFF0xD5, // Set Display Clock Divide Ratio / OSC Frequency0x80, // Display Clock Divide Ratio / OSC Frequency0xA8, // Set Multiplex Ratio0x3F, // Multiplex Ratio for 128x64 (64-1)0xD3, // Set Display Offset0x00, // Display Offset0x40, // Set Display Start Line0x8D, // Set Charge Pump0x14, // Charge Pump (0x10 External, 0x14 Internal DC/DC)0x20, // SET MEMORY ADDRESSING MODE0x02, // horizontal addressing mode0xA1, // set segment re-map, column address 127 is mapped to SEG00xC8, // Set Com Output Scan Direction0xDA, // Set COM Hardware Configuration0x12, // COM Hardware Configuration0x81, // Set Contrast0xCF, // Contrast0xD9, // Set Pre-Charge Period0xF1, // Set Pre-Charge Period (0x22 External, 0xF1 Internal)0xDB, // Set VCOMH Deselect Level0x40, // VCOMH Deselect Level0xA4, // Set all pixels OFF0xA6, // Set display not inverted0xAF, // Set display On0xA5, // 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);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 resetUCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous modeUCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW resetUCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHzUCB0BR1 = 0;UCB0I2CSA = SSD1306_ADDRESS;UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operationUCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start conditionunsigned 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 finishUCB0RXBUF;// clear IFG and overrunswhile(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?

author: Cervisia
author_rank: Regular Contributor
timestamp: July 15, 2017, 08:31:08 am
content: Which MSP? How did you connect it? Where is the module's datasheet? What is the relationship between this code and the Adafruit example code? Why did you expect to see dice (or what exactly do you mean with "no dice")?

author: Unknown
author_rank: Unknown
timestamp: July 15, 2017, 08:33:29 am
content: Quote from: kubuni on July 15, 2017, 01:20:37 amWithout knowing much else, a logic analyzer, oscilloscope with I2C decode, or the (fairly inexpensive)Bus Piratemight give a better idea of what is going on, on the wire.Also if you suspect the I2C code, you might try the I2C driver library provided with MSP430Ware (available in the Resource Explorer, under CCS).

author: kubuni
author_rank: Newbie
timestamp: July 15, 2017, 03:42:13 pm
content: I use the adafruit code on the arduino uno just to test out the module and figure out address. I'm using msp430g2253. I'll probably buy the bus pirate; so, I can see if it is the I2C lines. I based my code off the example code on the product's softwaretool docs :http://www.ti.com/product/MSP430G2253/toolssoftwareFor my configuration (using the launchpad),I have P1.7 connected to SDA and the P1.6 to SCL. I have 4.6K resistors between the VCC and SDA likewise . I measured the voltage of the VCC pins next to the reset button on the launchpad ; it reads 3.57V.

author: kubuni
author_rank: Newbie
timestamp: July 15, 2017, 03:47:08 pm
content: I might just download the CCS with msp430ware. I was using my linux laptop and the msp RF2500 commandline tool.