cancel
Showing results for 
Search instead for 
Did you mean: 

No CLK on SPI2 STM32F407VG

Just Matt
Associate III
Posted on January 25, 2014 at 20:23

Hi,

I'm trying to figure out why i'm not getting a CLK on SPI2. In this below example MOSI sends the data, but I'm getting no clock. (Verified with a logic analyzer) My Pinout: SCK - PB10 MISO - PC2 MOSI - PC3 You can download my CooCox Project from herehttp://sdrv.ms/1flS1n8 I've got to be overlooking something simple. Thanks in advance! -Matt

int
main(
void
) {
SetupSPI();
SPI_I2S_SendData(SPI2, 0x04);
}
void
SetupSPI() {
GPIO_InitTypeDef initStructure;
SPI_InitTypeDef spiInitStructure;
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_SPI2); 
//SCK
GPIO_PinAFConfig(GPIOC, GPIO_PinSource2, GPIO_AF_SPI2); 
//MISO
GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_SPI2); 
//MOSI
initStructure.GPIO_Mode = GPIO_Mode_AF;
initStructure.GPIO_Speed = GPIO_Speed_50MHz;
initStructure.GPIO_OType = GPIO_OType_PP;
initStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
initStructure.GPIO_Pin = GPIO_Pin_10; 
//SCK
GPIO_Init(GPIOB, &initStructure);
initStructure.GPIO_Pin = GPIO_Pin_2; 
//MISO
GPIO_Init(GPIOC, &initStructure);
initStructure.GPIO_Pin = GPIO_Pin_3; 
//MOSI
GPIO_Init(GPIOC, &initStructure);
initStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_7; 
//CS and RST
initStructure.GPIO_Mode = GPIO_Mode_OUT;
initStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &initStructure);
initStructure.GPIO_Pin = GPIO_Pin_9; 
//DC Low = CMD - High = Data
GPIO_Init(GPIOC, &initStructure);
SPI_I2S_DeInit(SPI2);
spiInitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
spiInitStructure.SPI_DataSize = SPI_DataSize_8b; 
// 8 Bits per transfer
spiInitStructure.SPI_CPOL = SPI_CPOL_Low; 
//Clock is low when inactive
spiInitStructure.SPI_CPHA = SPI_CPHA_1Edge; 
// Data is valid on clock leading edge
spiInitStructure.SPI_NSS = SPI_NSS_Soft;
spiInitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;
spiInitStructure.SPI_FirstBit = SPI_FirstBit_MSB; 
//Most significant bit first
spiInitStructure.SPI_CRCPolynomial = 7;
spiInitStructure.SPI_Mode = SPI_Mode_Master;
SPI_Init(SPI2, &spiInitStructure);
SPI_Cmd(SPI2, ENABLE);
}

1 REPLY 1
Posted on January 27, 2014 at 14:14

I don't see anything suspicious (except that I wouldn't set pulldown on output pins, but that should make no harm except slightly higher than necessary power consumption), and that main() should really be an endless loop (but I assume you know what you are doing with the LA).

Can't be hardware problem?

Try a somewhat simpler thing - set the said pin as a GPIO output and toggle it in an endless loop, watching it with an oscilloscope or the LA.

JW