AnsweredAssumed Answered

NucleoF411RET6 with Newhaven ST7565R Display (SPI)

Question asked by Jibbajibba on Oct 13, 2015
Latest reply on Oct 13, 2015 by waclawek.jan
 Hello


Im working on a project with a NucleoF411RE MCU board and a Newhaven Display using a ST7565R Controller.
Now, i'd like to start with simply turning on/ff all pixels. 


So far, it's not working,... yet. I have put a zip file with all data in it here, inclusice the PCB schemata:
http://www.filedropper.com/datasheets_1


Questions 1-4 are placed directly into the software coding! Please make me some suggestions!








********************************************************************
1.) Pins 
********************************************************************
I would suggest to set up all pins of the Newhaven display as shown below:


* Ext Newhaven - VSS     : GND
* Ext Newhaven - VDD     : 3V3
*
* Ext Newhaven - /RST     : CN07.28 - PA0 - GPIO (MCU Output)
* Ext Newhaven - /CS1     : CN07.32 - PA4 - SPI1_NSS (CS) or GPIO (MCU Output)
* Ext Newhaven - SCL     : CN10.11 - PA5 - SPI1_SCK
* Ext Newhaven - A0     : CN07.30 - PA6 - GPIO (MCU Output)
* Ext Newhaven - SI     : CN10.15 - PA7 - SPI1_MOSI 
* Ext Newhaven - BG_A     : CN07.34 - PB0 - GPIO (MCU Output) via Transistor
* Ext Newhaven - BG_K     : GND


Question 1: Where i dont know if to connect the displays chip select (/CS1) to SP1_NSS or to standart Output??


********************************************************************
2.) Software Code: Main
********************************************************************


/* Includes ------------------------------------------------------------------*/
#include "main.h"


/* Private define ------------------------------------------------------------*/


/* TEMP */     
/* SPI: Decide if NSS (CS) is used as NSS_CS_GPIO or NSS_CS_AF */           
#define NSS_CS_GPIO


int main(void)
{
     /* SysTick end of count event each 1ms */     
     SystemCoreClockUpdate();
     SysTick_Config(SystemCoreClock / 1000);
     
       /* Initialisation */
       RCC_configuration();
       GPIO_configuration();
     USART_configuration();
          
     /* Display */
     Newhaven_configuration();
     SPI_init();
     
     /* Delay 1s */     
     Delay(1000);
     
     /* Infinite loop */
      while (1)
       {
          /* Delay 500ms */
          Delay(2000);
          test1++;


          /* Test 3: SPI1     */
          /* Instruction: A0==0, 0xA5 All points on, 0xA4 All points off */
          /* Test to turn on/off all pixels */
          if(1)
          {
               /* Reset Display */
               GPIO_WriteBits(GPIOA, GPIO_Pin_0, 0);
               GPIO_WriteBits(GPIOA, GPIO_Pin_0, 1);
               Delay(100);
               
               /* Change to instruction: A0==0 */
               GPIO_WriteBits(GPIOA, GPIO_Pin_6, 0);
               /* /CS1 to Zero */
               GPIO_WriteBits(GPIOA, GPIO_Pin_4, 0);
               Delay(100);


               /* Send Instruction via SPI1 */
               SPI_SendData(SPI1, 0xA5);
               /* Loop until SPI1 transmit data register  is empty */ 
               while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET){}
               test3++;


               /* Newhaven Toggle Display Background LED */
               GPIO_ToggleBits(GPIOB, GPIO_Pin_0);
          }
       }
}


Question 2: Is there something missing or not correct for a simple instruction transmission?


********************************************************************
3.) Software Code: SPI_init
********************************************************************


static void SPI_init(void){
     
     /* Reset A0 and /CS */
     GPIO_ResetBits(GPIOA, GPIO_Pin_6); //set A0 = 0
       GPIO_SetBits(GPIOA, GPIO_Pin_4);  //set !CS = 1
     
     /* Disable SPI1 */
     SPI_Cmd(SPI1, DISABLE);
     
     /* SPI Configuration */
     SPI_I2S_DeInit(SPI1);
     
     SPI_InitTypeDef SPI_InitStructure;
     
     /* check if settings fitting for application!? */
     SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //SPI_Direction_1Line_Tx;
     SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
     SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
     SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //High;
     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //2Edge;
     SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
     SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
     SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
     SPI_InitStructure.SPI_CRCPolynomial = 7;
     SPI_Init(SPI1, &SPI_InitStructure);
     
     /* Disable CRC calculation of transfered data */
     SPI_CalculateCRC(SPI1, DISABLE);


     /* Enable SPI1 SS output - what is this? */
     SPI_SSOutputCmd(SPI2, ENABLE);


     /* Enable RXNE - what is this for? */
     SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);
     SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);


     /* Enable SPI1  */
     SPI_Cmd(SPI1, ENABLE);
}


Question 3: Settings suggestions and explainations? NSS_Soft or Hard?


********************************************************************
4.) Software Code: Newhaven_config
********************************************************************
static void Newhaven_configuration(void) 
{
     GPIO_InitTypeDef NH_InitStructure;  
     
     #ifdef NSS_CS_GPIO
     /* Configurte SPI1 pin: CS general purpose output  */
     NH_InitStructure.GPIO_Pin = GPIO_Pin_4;
     NH_InitStructure.GPIO_Speed = GPIO_Speed_50MHz,
     NH_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     NH_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_Init(GPIOA, &NH_InitStructure);
     #endif
     
     #ifdef NSS_CS_AF
     /* Configure SPI1 pin: NSS alternative function */
     NH_InitStructure.GPIO_Pin =  GPIO_Pin_4;
     NH_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     NH_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     NH_InitStructure.GPIO_OType = GPIO_OType_PP;
     NH_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_Init(GPIOA, &NH_InitStructure);
     #endif
     
     /* Configure SPI1 pins: SCK and MOSI alternative function */
     NH_InitStructure.GPIO_Pin =  GPIO_Pin_5 | GPIO_Pin_7; 
     NH_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     NH_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     NH_InitStructure.GPIO_OType = GPIO_OType_PP;
     NH_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
     GPIO_Init(GPIOA, &NH_InitStructure);
     
     /* Mux out SPI1 NSS, SCK, MOSI (alternative functions) */
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI1);      
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);      
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);      
     
     #ifdef A0_GPIO
     /* Configure PA1 as output (Newhaven A0, select register) */
     NH_InitStructure.GPIO_Pin = GPIO_Pin_6;
     NH_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
     NH_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     NH_InitStructure.GPIO_OType = GPIO_OType_PP;
     NH_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 
     GPIO_Init(GPIOA, &NH_InitStructure);
     #endif
     
     /* Set PA0 as output (/RST) */
     NH_InitStructure.GPIO_Pin = GPIO_Pin_0;
     NH_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
     NH_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     NH_InitStructure.GPIO_OType = GPIO_OType_PP;
     NH_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;  
     GPIO_Init(GPIOA, &NH_InitStructure);
     
     /* Set PB0 as output (Background LED Display) */
     NH_InitStructure.GPIO_Pin = GPIO_Pin_0;
     NH_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
     NH_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
     NH_InitStructure.GPIO_OType = GPIO_OType_PP;
     NH_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;  
     GPIO_Init(GPIOB, &NH_InitStructure);
}


Question 4: /CS1 as Output or SPI1_NSS???




********************************************************************
5.) Software Code: GPIO_config and RCC_config
********************************************************************


void GPIO_configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
     
     /* Set PB13 as output (LED LD2) */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;  
     GPIO_Init(GPIOB, &GPIO_InitStructure);


  /* Configure PC13 as  input for button reading (B1) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
     GPIO_Init(GPIOC, &GPIO_InitStructure);
     
     /* USART1 RX/TX Conficure as alternative-function */
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
     
     /* Mux out USART1 Tx, Rx (alternative functions) */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); 
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);




}


void RCC_configuration(void)
{
  /* Enable clock for Port A, B, C */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
     
     /* Enable clock for SPI1, PortA, APB2 */
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
     
     /* Enable  USART1 clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);


}























Outcomes