cancel
Showing results for 
Search instead for 
Did you mean: 

NucleoF411re, SPI1 --> NSS (StdPeriphLib)

hackerli90
Associate II
Posted on October 30, 2015 at 17:33

Hello guys

im working on a SPI interface where SPI1 has a hard wired NSS (neg. slave select == /chip select).

watching the logic analyser, the spi transmission takes place but the NSS signal is staying high during the entire running periode. 

do you see why?

here some code for uvision keil v5:

int main(void)

{

  /* SysTick end of count event each 1ms */

  RCC_GetClocksFreq(&RCC_Clocks);

  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

 

  /* Insert 50 ms delay */

  Delay(50);

/* Configuration and Initialisation */

  RCC_configuration(); // CLK managemant RCC

//GPIO_configuration(); // GPIO general

SPI_configuration(); // SPI peripherals (GPIO)

//USART_configuration(); // USART peripherals (GPIO)

Delay(50);

  SPI_initialization(); // INIT SPI parameter

//USART_initialization(); // INIT USART parameter

Delay(50);

st7565r_display_initialization(); // INIT Display Newhaven instructions (ST7565R)

Delay(10);

/* Testing only: Draw full page */

display_clear_page(2,1); 

 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);

/* USART1 */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/* SPI1 */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);

}

void SPI_configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure_SPI;  

/* A0 general purpose output (Newhaven A0, select register) */

GPIO_InitStructure_SPI.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure_SPI.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure_SPI.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure_SPI.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure_SPI.GPIO_PuPd = GPIO_PuPd_UP; 

GPIO_Init(GPIOA, &GPIO_InitStructure_SPI);

/* /RST general purpose output (Newhaven /RST, reset) */

GPIO_InitStructure_SPI.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructure_SPI.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure_SPI.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure_SPI.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure_SPI.GPIO_PuPd = GPIO_PuPd_UP;  

GPIO_Init(GPIOA, &GPIO_InitStructure_SPI);

/* Set PB0 as output (Background LED Display) */

GPIO_InitStructure_SPI.GPIO_Pin = GPIO_Pin_0;

GPIO_InitStructure_SPI.GPIO_Speed = GPIO_Speed_2MHz;

GPIO_InitStructure_SPI.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure_SPI.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure_SPI.GPIO_PuPd = GPIO_PuPd_DOWN;  

GPIO_Init(GPIOB, &GPIO_InitStructure_SPI);

/* Configure SPI1 pins: NSS, SCK and MOSI alternative function */

GPIO_InitStructure_SPI.GPIO_Pin =  GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_4;

GPIO_InitStructure_SPI.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure_SPI.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure_SPI.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure_SPI.GPIO_PuPd = GPIO_PuPd_NOPULL; 

GPIO_Init(GPIOA, &GPIO_InitStructure_SPI);

/* Mux out SPI1: SCK, MOSI, NSS (alternative functions) */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI1); // /CS1 - NSS

GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_SPI1);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource7, GPIO_AF_SPI1);

void SPI_initialization(void) 

{

/* Disable SPI1 */

SPI_Cmd(SPI1, DISABLE);

/* SPI Deinitialize */

SPI_I2S_DeInit(SPI1);

SPI_InitTypeDef SPI_InitStructure;

/* SPI1 parameter */

SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;

SPI_InitStructure.SPI_Mode = SPI_Mode_Master;

SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;

SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;  // SPI Mode 4: CPOL==1

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; // SPI Mode 4: CPHA==1

SPI_InitStructure.SPI_NSS = SPI_NSS_Hard; // NSS (=/CS) hard wired

SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; // max 2.5MHz --> 100M/64=1.56M

SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_InitStructure.SPI_CRCPolynomial = 10;

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 SPI1 RXNE, TXE interrupts */

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);

SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_TXE, ENABLE);

/* Enable SPI1  */

SPI_Cmd(SPI1, ENABLE);

 void st7565r_display_initialization(void) 

{

// Hard Reset NH Display 

st7565r_hard_reset();

// Instructions for init NH Display from datasheet 

//st7565r_sleep_enable(); // TEST: Power Saver ON

st7565r_spi_send_cmd(ST7565R_CMD_ADC_NORMAL); //A0

//st7565r_spi_send_cmd(ST7565R_CMD_ADC_REVERSE); //A1 TESTING ONLY: Switches Cols to 31,..,0

st7565r_spi_send_cmd(ST7565R_CMD_DISPLAY_OFF); //AE

st7565r_spi_send_cmd(ST7565R_CMD_NORMAL_SCAN_DIRECTION); //C0

st7565r_spi_send_cmd(ST7565R_CMD_LCD_BIAS_1_DIV_9_DUTY33); //A2

st7565r_spi_send_cmd(ST7565R_CMD_POWER_CTRL_ALL_ON); //2F

st7565r_spi_send_cmd(ST7565R_CMD_VOLTAGE_RESISTOR_RATIO_1); //21

st7565r_spi_send_cmd(ST7565R_CMD_ELECTRONIC_VOLUME_MODE_SET); //81

st7565r_spi_send_cmd(0x3F); //st7565r_spi_send_cmd(ST7565R_CMD_ELECTRONIC_VOLUME(0x3F)); //3f

//st7565r_sleep_disable(); // TEST: Power Saver OFF

st7565r_display_on(); //0xAF

st7565r_set_contrast(35);

st7565r_set_all_pixels(0); //0xA4

display_en_bg_led(1); // enable background led

}

void st7565r_spi_send_cmd(uint8_t i)

{

// Set A0==0 for instruction transmission 

GPIO_ResetBits(GPIOA, GPIO_Pin_1);

// Clear flag

SPI_ClearFlag(SPI1, SPI_FLAG_TXE);

//SPI_ClearFlag(SPI1, SPI_I2S_FLAG_BSY);

// Send via SPI1 

SPI_SendData(SPI1, i);

// Loop until SPI1 transmit data register is empty 

while(SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET);

//while(SPI_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET){};

// Clear flag

SPI_ClearFlag(SPI1, SPI_FLAG_TXE);

//SPI_ClearFlag(SPI1, SPI_I2S_FLAG_BSY);

2 REPLIES 2
Posted on October 30, 2015 at 18:25

You need to enable SPI_CR2.SSOE. I don't speak ''library''.

/* Enable SPI1 SS output - what is this? */

//SPI_SSOutputCmd(SPI2, ENABLE);

This is probably it, except you need to do it for SPI1.

JW
hackerli90
Associate II
Posted on October 30, 2015 at 20:19

Ah yeah true, i forgot to enable slave select. thanks. CLOSED!