[SOLVED] [MSP430F5529 + ili9341 screen] command instruction seem don't works - Page 1
Forum section: electronics / beginners

author: OrKaraz
author_rank: Newbie
timestamp: January 21, 2021, 09:26:20 am
content: Hi,Since few days i'm working on a screen project with my MSP430F5529 and one ili9341 screen.I have take an exemple (from arduino, can't find on MSP) and adapt it to know how use the screen.After few try, i can fill the screen with colors but can't draw a simple line or rectangle at a special position.When i run the program step by step, all instruction command work and on the screen i have all the program what have to do.I have try to change all wire but no change.The MSP430F5529 run at 25 MHz (max) with 3.3V like the screen.Code://This application does not rely on any libraries and it is for ILI9341//This program is a demo of clearing screen to display black,white,red,green,blue.//when using the BREAKOUT BOARD only and using these hardware spi lines to the LCD,//the SDA pin and SCK pin is defined by the system and can't be modified.//if you don't need to control the LED pin,you can set it to 3.3V and set the pin definition to -1.//other pins can be defined by youself,for example//pin usage as follow:// CS DC/RS RESET SDI/MOSI SCK LED VCC GND// GND//Remember to set the pins to suit your display module!#include <msp430.h>#define FPROC 25000000/*P3.0 : MOSIP3.1 : MISOP3.2 : CLK*/#define RSUP P6OUT|=BIT0 // DC/RS#define RSDOWN P6OUT&=~BIT0#define LEDUP P6OUT|=BIT1#define LEDDOWN P6OUT&=~BIT1#define CSUP P6OUT|=BIT2#define CSDOWN P6OUT&=~BIT2#define RESETUP P6OUT|=BIT3#define RESETDOWN P6OUT&=~BIT3unsigned long oldrand = 5468;void SetVcoreUp (unsigned int level){// Open PMM registers for writePMMCTL0_H = PMMPW_H;// Set SVS/SVM high side new levelSVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;// Set SVM low side to new levelSVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;// Wait till SVM is settledwhile ((PMMIFG & SVSMLDLYIFG) == 0);// Clear already set flagsPMMIFG &= ~(SVMLVLRIFG + SVMLIFG);// Set VCore to new levelPMMCTL0_L = PMMCOREV0 * level;// Wait till new level reachedif ((PMMIFG & SVMLIFG))while ((PMMIFG & SVMLVLRIFG) == 0);// Set SVS/SVM low side to new levelSVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;// Lock PMM registers for write accessPMMCTL0_H = 0x00;}// fonction aleatoireunsigned int random(unsigned int n) {unsigned long nn = oldrand;oldrand = (unsigned int)((859*nn)%6823);return oldrand % n;}void delay(unsigned int i){while(i--)__delay_cycles(FPROC/1000); // 1000 for 1MHz}// envoyer sur le SPI la donnéevoid Lcd_Writ_Bus(unsigned char d){while(UCB0STAT&BIT0) {} // si la communication n'est pas finie on attendUCB0TXBUF = d;}// écrire la commandevoid Lcd_Write_Com(unsigned char VH){RSDOWN; //LCD_RS=0;Lcd_Writ_Bus(VH);}// écrire la donnéevoid Lcd_Write_Data(unsigned char VH){RSUP; //LCD_RS=1;Lcd_Writ_Bus(VH);}void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2){Lcd_Write_Com(0x2a);Lcd_Write_Data(x1>>8);Lcd_Write_Data(x1);Lcd_Write_Data(x2>>8);Lcd_Write_Data(x2);Lcd_Write_Com(0x2b);Lcd_Write_Data(y1>>8);Lcd_Write_Data(y1);Lcd_Write_Data(y2>>8);Lcd_Write_Data(y2);Lcd_Write_Com(0x2c);}void draw_pixel (unsigned char cr,unsigned char cv,unsigned char cb) {Lcd_Write_Data(cr);Lcd_Write_Data(cv);Lcd_Write_Data(cb);}void SPI_Init(void){UCB0CTL0 = BIT7 | BIT5 | BIT3; // Master + MSBfirst + front montant + CLK inactif 0UCB0CTL1 = BIT7 | BIT6; // SMCLKP3SEL |= 0x07; // on utilise le SPI (CLK, MOSI et MISO)}void Lcd_Init(void){RESETUP;delay(5);RESETDOWN;delay(15);RESETUP;delay(15);CSDOWN; //CSLcd_Write_Com(0xCB);Lcd_Write_Data(0x39);Lcd_Write_Data(0x2C);Lcd_Write_Data(0x00);Lcd_Write_Data(0x34);Lcd_Write_Data(0x02);Lcd_Write_Com(0xCF);Lcd_Write_Data(0x00);Lcd_Write_Data(0XC1);Lcd_Write_Data(0X30);Lcd_Write_Com(0xE8);Lcd_Write_Data(0x85);Lcd_Write_Data(0x00);Lcd_Write_Data(0x78);Lcd_Write_Com(0xEA);Lcd_Write_Data(0x00);Lcd_Write_Data(0x00);Lcd_Write_Com(0xED);Lcd_Write_Data(0x64);Lcd_Write_Data(0x03);Lcd_Write_Data(0X12);Lcd_Write_Data(0X81);Lcd_Write_Com(0xF7);Lcd_Write_Data(0x20);Lcd_Write_Com(0xC0); //Power controlLcd_Write_Data(0x23); // 23 VRH[5:0]Lcd_Write_Com(0xC1); //Power controlLcd_Write_Data(0x10); //SAP[2:0];BT[3:0]Lcd_Write_Com(0xC5); //VCM controlLcd_Write_Data(0x3e); //ContrastLcd_Write_Data(0x28);Lcd_Write_Com(0xC7); //VCM control2Lcd_Write_Data(0x86); //--Lcd_Write_Com(0x36); // Memory Access ControlLcd_Write_Data(0x48); // 48 (28 -> mode paysage, 48 -> mode portrait)Lcd_Write_Com(0x3A); // Pixel format setLcd_Write_Data(0x66); // 55Lcd_Write_Com(0xB1);Lcd_Write_Data(0x00);Lcd_Write_Data(0x18); // 18Lcd_Write_Com(0xB6); // Display Function ControlLcd_Write_Data(0x08);Lcd_Write_Data(0x82); // 82Lcd_Write_Data(0x27);Lcd_Write_Com(0x11); //Exit Sleepdelay(120);Lcd_Write_Com(0x29); //Display onLcd_Write_Com(0x2c);CSUP;}void H_line(unsigned int x, unsigned int y, unsigned int l,unsigned char cr,unsigned char cv,unsigned char cb){unsigned int i;CSDOWN;Lcd_Write_Com(0x02c); //write_memory_startAddress_set(x,y,l+x,y);for(i=1;i<=l;i++){draw_pixel(cr, cv, cb);}CSUP;}void V_line(unsigned int x, unsigned int y, unsigned int l,unsigned char cr,unsigned char cv,unsigned char cb){unsigned int i;CSDOWN;Lcd_Write_Com(0x02c); //write_memory_startAddress_set(x,y,x,l+y);for(i=1;i<=l;i++){draw_pixel(cr, cv, cb);}CSUP;}void Rect(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned char cr,unsigned char cv,unsigned char cb){H_line(x , y , w, cr, cv, cb);H_line(x , y+h, w, cr, cv, cb);V_line(x , y , h, cr, cv, cb);V_line(x+w, y , h, cr, cv, cb);}void Rectf(unsigned int x,unsigned int y,unsigned int w,unsigned int h,unsigned char cr,unsigned char cv,unsigned char cb){unsigned int i;for(i=0;i<h;i++){H_line(x , y , w, cr, cv, cb);H_line(x , y+i, w, cr, cv, cb);}}void LCD_Clear(unsigned char cr,unsigned char cv,unsigned char cb){unsigned int ii,mm;CSDOWN;Address_set(0,0,240,320);for(ii=0;ii<240;ii++)for(mm=0;mm<320;mm++){draw_pixel(cr, cv, cb);}CSUP;}void LCD_Arc(){unsigned int ii,mm;unsigned char cb = 0, cv = 0, cr = 0;CSDOWN;Address_set(0,0,240,320);for(ii=0;ii<320;ii++) {if (ii<80) cr=3*(ii%80);else if (ii<160) cr=3*(80-(ii-80)%80);else if (ii<240) cb=3*((ii-160)%80);else cb=3*(80-(ii-240)%80);for(mm=0;mm<240;mm++){cv = mm%240;draw_pixel(cr, cv, cb);}}CSUP;}void LCD_Carre(){unsigned int ii;CSDOWN;Address_set(10,10,20,20);for(ii=0;ii<100;ii++) {draw_pixel(0xff, 0xff, 0xff);}CSUP;}/*** main.c*/void main(void){WDTCTL = WDTPW | WDTHOLD;// stop watchdog timerSetVcoreUp(1);SetVcoreUp(2);SetVcoreUp(3);UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO (32 768)__bis_SR_register(SCG0); // Disable the FLL control loopUCSCTL0 = 0x0000; // Set lowest possible DCOx, MODxUCSCTL1 = DCORSEL_5; // Select DCO range 25MHz operationUCSCTL2 = FLLD_0 + (FPROC/32768 - 1); // Set DCO Multiplier for 25MHz (487 pour 16MHz) (761 pour 25MHz)// (N + 1) * FLLRef = Fdco// (761 + 1) * 32768 = 25MHz// Set FLL Div = fDCOCLK__bic_SR_register(SCG0); // Enable the FLL control loopthen select clock source by write SPI control register (UCSSELx)UCSCTL4 |= SELA_3; // présence de MCLK/1024 sur P1.0UCSCTL5 |= DIVPA_5 | DIVA_5;P1DIR |= BIT0;P1SEL |= BIT0;SPI_Init();P6DIR |= 0x0F; // bit0 à 3 en sortieRSUP;LEDUP;CSUP;RESETUP;Lcd_Init();while (1) {LCD_Clear(0xff, 0xff, 0xff);delay(1000);LCD_Clear(0xff, 0x00, 0x00);delay(1000);LCD_Clear(0x00, 0xff, 0x00);delay(1000);LCD_Clear(0x00, 0x00, 0xff);delay(1000);LCD_Arc();delay(3000);LCD_Carre();delay(5000);LCD_Clear(0x00, 0x00, 0x00);Rect(10,10,100,50,random(256),random(256),random(256));/*for(i=0;i<100;i++){Rect(random(239),random(319),random(239),random(319),random(256),random(256),random(256)); // rectangle at x, y, width, hight, color}*/delay(5000);}__bis_SR_register(LPM4_bits);}Thank you for help.

author: mayor
author_rank: Regular Contributor
timestamp: January 21, 2021, 11:53:18 am
content: Pasting the entire program makes it difficult to help. Can you paste a minimal working example (filling the screen), and a minimal non-working example (a line) ?

author: OrKaraz
author_rank: Newbie
timestamp: January 21, 2021, 01:20:32 pm
content: Hi,All the program is minimum.After more research when waiting this answer (16h i search it) i have find the probem.To me : never use any more --opt_level 3 or 4.Don't know why, but the "P6OUT &= ~BIT0" instruction was not working in --opt_level 4 nether 3. (line 84)I have set to 2 and now all works like it does to be.Now i'll able to use ASM.Thank you for answering.