This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: MSP432P401R interface OLED SSD1306 SPI problem

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hello Fellows, 

I have facing some problems... I need to interface a MSP432P401R micro controller with a OLED SSD1306 Display, trougth SPI communication, but when initialize the "init_Lcd" function, all program stop.

const char init_cmd_array[25]={0xAE,          // DISPLAY OFF
                             0xD5,          // SET OSC FREQUENY
                             0x80,          // divide ratio = 1 (bit 3-0), OSC (bit 7-4)
                             0xA8,          // SET MUX RATIO
                             0x3F,          // 64MUX
                             0xD3,          // SET DISPLAY OFFSET
                             0x00,          // offset = 0
                             0x40,          // set display start line, start line = 0
                             0x8D,          // ENABLE CHARGE PUMP REGULATOR
                             0x14,          //
                             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, remapped mode (COM[N-1] to COM0)
                             0xDA,          // SET COM PINS HARDWARE CONFIGURATION
                             0x12,          // alternative COM pin configuration
                             0x81,          // SET CONTRAST CONTROL
                             0xCF,          //
                             0xD9,          // SET PRE CHARGE PERIOD
                             0xF1,          //
                             0xDB,          // SET V_COMH DESELECT LEVEL
                             0x40,          //
                             0xA4,          // DISABLE ENTIRE DISPLAY ON
                             0xA6,          // NORMAL MODE (A7 for inverse display)
                             0xAF};         // DISPLAY ON

void init_LCD(void){
    int byte = sizeof(init_cmd_array);
    P2->OUT|= OLED_RS;

    while(byte){

        set_instruction(0,init_cmd_array[sizeof(init_cmd_array)-byte]);
        printf("4b-Byte %d, 0x%X\n",byte, init_cmd_array[sizeof(init_cmd_array)-byte]);
        byte--;
    }
     //display RAM is undefined after reset, clean dat ***
    fill_display(SCREEN_WIDTH ,SCREEN_HEIGHT,0x00);
 
}

void init_Ports(void){

    P2->DIR |= OLED_DC|OLED_RS;
    P5->DIR |= OLED_CS;
    P2->OUT &= ~(OLED_DC | OLED_RS);                  // chip select HIGH
    P5->OUT |= OLED_CS;                  // chip select HIGH
    P2->OUT |= OLED_RS;
}

main.c

    void main(void){
    WatchDogHold();
    clockSystem();

    P1->DIR |= BIT0;
    P1->OUT |= BIT0;

    init_Ports();
    init_EUSCI();
    init_LCD();

        while(1)
        {
          //code...
        }
}

  • You haven't shown set_instruction nor fill_display. They are probably the prime suspects here.

    When you pause your program, where is it executing?

    I'm supposing your printf() is going to a CCS console window. What does it show?
  • void fill_display(unsigned char width, unsigned char height, unsigned char byte){
        height/=8;
        while(height--){
            set_cursor(0,height);
            while(width--)
                set_instruction(1,byte);
            width=SCREEN_WIDTH ;
        }
    }
    
    
    
    // for 4-wire SPI
    void set_instruction(unsigned char register_sel, unsigned char number){
      
        if(register_sel)
            P2->OUT |= OLED_DC;            // data
        else
            P2->OUT &= ~(OLED_DC);        // command
    
    
        P3->OUT &=~(OLED_CS);
        // start condition
        while(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0);      // TX buffer ready?
        EUSCI_B0->TXBUF = number;           // start transmission
    }
    

    "When you pause your program, where is it executing?"

    inside while on "init_Lcd" function

    "I'm supposing your printf() is going to a CCS console window. What does it show?"

    nothing

    all code was based in this website: http://xdec.de/msp430-oled-display-ssd1306-128x64/

  • > while(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0); // TX buffer ready?

    This will stop you forever. Try:

    > while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0)); // TX buffer ready?
  • Hello Bruce, 

    I  modify the syntax to "while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0));" after that he read's two register and stop's again in the same place.

  • Another way of saying it: TXIFG doesn't go high after writing TXBUF (once). This indicates that the USCI clock isn't running. Possibly:
    1) Init_EUSCI doesn't take the USCI out of reset (clear UCSWRST) or
    2) The clock you're supplying to the USCI (UCSSEL) isn't running or
    3) UCMST and/or UCMODE aren't set appropriately.

    If you can post Init_EUSCI, I expect someone will be able to identify something.
  • I just went back to the original, and that only works by accident. I recommend you remove these lines (or equivalent):

    > IE2|=UCB0TXIE; // enable TX interrupt
    > IFG2&=~UCB0TXIFG;

    You can/should also remove the ISR.

    [Edit: A bit more:]

    Also, add these to the end of set_instruction:

    while (!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG)) /*EMPTY*/; Wait for completion 
    (void)EUSCI_B0->RXBUF; // Clear RXIFG 
    P2->OUT |= CS; // transmission done
    

  • Hello Bruce
    Sorry for a late response, but I have been sick, so yesterday I solved the problem, I start a new code and step by step, I have test every variables and I get the oled working.

    thank you

**Attention** This is a public forum