2009-12-15 10:45 PM
SPI2 clock
2011-05-17 03:20 AM
Hello,
I modified the evaluation board source codes to use SPI2 as a master, but I could get clock signal for PB13.2011-05-17 03:20 AM
Hi pinwu1,
PB13 (SPI2_CLK) is used in the Evaluation board from ST (MB525) to drive the TFT LCD and is working fine on my board, I suggest you to re-check your code for sure you have something missing in the initilisation. :) Magigimix2011-05-17 03:20 AM
I studied that part of source code. That clock for LCD is not generated by SPI internal clock. I simplified the code to initialize SPI registers and releated clocks only. I tested on this way, and found SPI1 working, but not SPI2.
For STM32F103RB chip, both SPI1 and SPI2 not working. Thank You,2011-05-17 03:20 AM
Quote:
On 27-12-2007 at 19:41, Anonymous wrote: Hi pinwu1, PB13 (SPI2_CLK) is used in the Evaluation board from ST (MB525) to drive the TFT LCD and is working fine on my board, I suggest you to re-check your code for sure you have something missing in the initilisation. :) Magigimix2011-05-17 03:20 AM
I posted my part of source code here.
void Set_System() { GPIO_InitTypeDef GPIO_InitStructure; // if (mode == 1) { // DFU mode // FLASH_Unlock(); // } /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ------------*/ /* RCC system reset(for debug purpose) */ RCC_DeInit(); /* Enable HSE */ RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* ADCCLK = PCLK2/6 */ RCC_ADCCLKConfig(RCC_PCLK2_Div6); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) { } /* USBCLK = PLLCLK / 1.5 */ RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); /* Enable USB clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USB, ENABLE); } RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE); USB_Cable_Config (DISABLE); SPI_FLASH_Init(); USB_Cable_Config (ENABLE); } int main(void) { #ifdef DEBUG debug(); #endif Set_System(); while (1) { SPI_FLASH_ReadID(); // Test Only } } void SPI_FLASH_Init(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable SPI1 and GPIOA clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOA, ENABLE); // RCC_APB2PeriphClockCmd(RCC_APB1Periph_SPI2 | RCC_APB2Periph_GPIOB, ENABLE); /* Configure SPI1 pins: NSS, SCK, MISO and MOSI */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure PA.4 as Output push-pull, used as Flash Chip select */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); // GPIO_Init(GPIOB, &GPIO_InitStructure); /* Deselect the FLASH: Chip Select high */ SPI_FLASH_CS_HIGH(); /* SPI1 configuration */ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI1, &SPI_InitStructure); // SPI_Init(SPI2, &SPI_InitStructure); /* Enable SPI1 */ SPI_Cmd(SPI1, ENABLE); // SPI_Cmd(SPI2, ENABLE); } In spi_flash.h, /* Exported macro ---------*/ /* Select SPI FLASH: ChipSelect pin low */ #define SPI_FLASH_CS_LOW() GPIO_ResetBits(GPIOA, GPIO_Pin_4) // #define SPI_FLASH_CS_LOW() GPIO_ResetBits(GPIOB, GPIO_Pin_12) /* Deselect SPI FLASH: ChipSelect pin high */ #define SPI_FLASH_CS_HIGH() GPIO_SetBits(GPIOA, GPIO_Pin_4) // #define SPI_FLASH_CS_HIGH() GPIO_SetBits(GPIOB, GPIO_Pin_12) [ This message was edited by: pinwu1 on 28-12-2007 00:22 ]2011-05-17 03:20 AM
Dear pinwu1,
I think that you mising part is in line : /* Enable SPI1 and GPIOA clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOA, ENABLE); // RCC_APB2PeriphClockCmd(RCC_APB1Periph_SPI2 | RCC_APB2Periph_GPIOB, ENABLE); SPI2 is connected in APB1 and not like SPI1 which is connected to APB2 with all GPIOs. So the right code to enbale SPI2 is something like : /* Enable SPI2 and GPIOB clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); Tell me if it is working well now ;) Magigimix ;)2011-05-17 03:20 AM
My project has also this problem. The clk of SPI2 does not work at all, but there is signal on MOSI pin.
Already set like this RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);Quote:
On 28-12-2007 at 15:48, Anonymous wrote: Dear pinwu1, I think that you mising part is in line : /* Enable SPI1 and GPIOA clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1 | RCC_APB2Periph_GPIOA, ENABLE); // RCC_APB2PeriphClockCmd(RCC_APB1Periph_SPI2 | RCC_APB2Periph_GPIOB, ENABLE); SPI2 is connected in APB1 and not like SPI1 which is connected to APB2 with all GPIOs. So the right code to enbale SPI2 is something like : /* Enable SPI2 and GPIOB clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); Tell me if it is working well now ;) Magigimix ;)2011-05-17 03:20 AM
Dear Magigimix,
Thank you for your correction. It does still not work for SPI2 with this correction. Is there something wrong? PinWu2011-05-17 03:20 AM
For the evaluation borad, both SPI1 and SPI2 are working. I found that SPI_FLASH_SendByte was hard-coded for SPI1.
Thank You Magigimix