Skip to main content
AANTO.13
Associate
Dec 11, 2018 6:49 AM UTC
Question

how is SPI configuration and NSS pin settings in STM32F4-Discovery board to configure ST7735

sir, i am using STM32F4- discovery board, i want to configure color display with driver ST7735S. i want to know that how will i configure my spi to send data to the display. also the Nss pin.

This topic has been closed for replies.

8 replies

waclawek.jan
Super User
Dec 12, 2018 6:41 AM UTC

Set up SPI to fulfill speed and CPOL/CPHA requirements of the display, see display's datasheet.

NSS in STM32's SPI is mostly useless, you are better off generating any framing signal needed by the target (display) "manually" through a GPIO output pin.

JW

AANTO.13
AANTO.13Author
Associate
Dec 12, 2018 11:00 AM UTC

thank you for your reply

I have initialised the spi for lcd as

/* SPI2 init function */

void MX_SPI2_Init(void)

{

 hspi2.Instance = SPI2;

 hspi2.Init.Mode = SPI_MODE_MASTER;

 hspi2.Init.Direction = SPI_DIRECTION_1LINE;

 hspi2.Init.DataSize = SPI_DATASIZE_8BIT;

 hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;

 hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;

 hspi2.Init.NSS = SPI_NSS_SOFT;

 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;

 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;

 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

 hspi2.Init.CRCPolynomial = 10;

 HAL_SPI_Init(&hspi2);

}

i am new to this field. let me know what is the error.

waclawek.jan
Super User
Dec 12, 2018 9:51 PM UTC

I don't use Cube.

What is the problem, what are the symptoms?

JW

AANTO.13
AANTO.13Author
Associate
Dec 29, 2018 6:29 AM UTC

sir,

sorry for the late reply.

I am using display with ST7735S as driver and it is having green tab. I have set the SPI as required. I have attached my code here. I started to code the display with filling pixels with some colors. the display is now showing mixed colors.

i don't know whether the problem is in the initialization command or in the code for the pixels.

can you help pls

AANTO.13
AANTO.13Author
Associate
Dec 29, 2018 6:30 AM UTC

this is my display now

RomainR.
ST Employee
Dec 31, 2018 5:49 PM UTC

Hi,

Here archive attached of my code for STM32L476 with cheap 1.8" LCD ST7735.

You can port the code on F4 easily with Cube (.ioc)

NSS (CSX in my code) is managed by software (not SPI hardware)

Here SPI2 config for CPOL/CHPA with SPI frequency = 10MHz.

/* SPI2 Configuration */
 hspi2.Instance = SPI2;
 hspi2.Init.Mode = SPI_MODE_MASTER; 
 hspi2.Init.Direction = SPI_DIRECTION_1LINE; 
 hspi2.Init.DataSize = SPI_DATASIZE_8BIT; 
 hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
 hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
 hspi2.Init.NSS = SPI_NSS_SOFT; 
 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; // PCLK2/8 = 10MHz
 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; 
 hspi2.Init.TIMode = SPI_TIMODE_DISABLE; 
 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; 
 hspi2.Init.CRCPolynomial = 7; 
 hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; 
 hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
 HAL_SPI_Init(&hspi2);

Good luck.

BR

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
AANTO.13
AANTO.13Author
Associate
Jan 2, 2019 10:46 AM UTC

sir,

thank you for helping me.

I could not load the code since I have the updated version of cubemx.

I do have another doubt also

I have ST7735S display with Green tab

I used initialization in my code as below

static const uint8_t Scmd[] = {         // Initialization commands for 7735S screens

  16,            // 17 commands in list:

  ST7735_SLPOUT ,  DELAY, // 2: Out of sleep mode, no args, w/delay

  120,          //   255 = 500 ms delay

  ST7735_FRMCTR1, 3,   // 4: Frame rate control 1, 3 args

  0x05,          //   fastest refresh

  0x3C,          //   6 lines front porch

  0x3C,          //   3 lines back porch

  ST7735_FRMCTR2, 3,

  0x05,

  0x3C,

  0x3C,

  ST7735_FRMCTR3, 6,

  0x05,

  0x3C,

  0x3C,

  0x05,

  0x3C,

  0x3C,

  ST7735_INVCTR , 1   , // 7: Display inversion control, 1 arg:

  0x03,          //   Line inversion

  ST7735_PWCTR1 , 3, // 8: Power control, 2 args + delay:

  0x28,          //   GVDD = 4.7V

  0x08,          //   1.0uA

  0x04,

  ST7735_PWCTR2 , 1   , // 9: Power control, 1 arg, no delay:

  0xC0,          //   VGH = 14.7V, VGL = -7.35V

  ST7735_PWCTR3 , 2   , // 10: Power control, 2 args, no delay:

  0x0D,          //   Opamp current small

  0x00,          //   Boost frequency

  ST7735_PWCTR4, 2,

  0x8D,

  0x2A,

  ST7735_PWCTR5, 2,

  0x8D,

  0xEE,

  ST7735_VMCTR1 , 1, // 11: Power control, 2 args + delay:

  0x1A,          //   VCOMH = 4V

  ST7735_MADCTL , 1  , // 5: Memory access ctrl (directions), 1 arg:

  0xC0,          //   Row addr/col addr, bottom to top refresh

  ST7735_GMCTRP1, 16,   // 13: Magical unicorn dust, 16 args, no delay:

  0x04, 0x22, 0x07, 0x0A, //   (seriously though, not sure what

  0x2E, 0x30, 0x25, 0x2A, //   these config values represent)

  0x28, 0x26, 0x2E, 0x3A,

  0x00, 0x01, 0x03, 0x13,

  ST7735_GMCTRN1, 16,   // 14: Sparkles and rainbows, 16 args + delay:

  0x04, 0x16, 0x06, 0x0D, //   (ditto)

  0x2D, 0x26, 0x23, 0x27,

  0x27, 0x25, 0x2D, 0x3B,

  0x00, 0x01, 0x04, 0x13,

  ST7735_COLMOD , 1, // 3: Set color mode, 1 arg + delay:

  0x05,          //   16-bit color

  ST7735_DISPON ,  DELAY, // 18: Main screen turn on, no args, w/delay

  255

}; 

will the initialization changes for ST7735S display like ST7735R as the tab color changes?

RomainR.
ST Employee
Jan 2, 2019 2:21 PM UTC

"will the initialization changes for ST7735S display like ST7735R as the tab color changes?"

You need to check the datasheet of your ST7735S display and check cmd register.

I do not understand why you're not able to my project with CubeMX ?

Even if you have updated it, it's possible to open the .ioc file that I provided.

BR

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.