2011-09-18 01:38 PM
I have observed a conflict between SPI1 and DAC1 on stm32f103ZG micro.
When spi1 is initialized first and then DAC1 the spi1 clock shuts down. It is time sensitive, but I manage to make repeatable on stm3210E-EVAL board. Common scenario is: nw_spi_init(SPI_1); nw_spi_send_32(SPI_1, 0xffffffff); nw_spi_send_32(SPI_1, 0xffffffff); for(i=0;i<0x1f;i++); nw_dac_config();//error is caused here spi1 clk shuts down by dac1 if dac is enabled for(i=0;i<0x2f;i++); nw_spi_send_32(SPI_1, 0xffffffff); nw_spi_send_32(SPI_1, 0xffffffff); SPI1 configuration is:GPIO_InitTypeDef
gpioInitStruct;SPI_InitTypeDef
spiInitStruct;RCC_APB2PeriphClockCmd
(RCC_APB2Periph_AFIO ,ENABLE
);//
RCC_APB2PeriphClockCmd
((RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOG | RCC_APB2Periph_SPI1),ENABLE
);gpioInitStruct.
GPIO_Speed
=GPIO_Speed_50MHz
;gpioInitStruct.
GPIO_Mode
=GPIO_Mode_Out_PP
;gpioInitStruct.
GPIO_Pin
= GPIO_Pin_8;GPIO_Init(GPIOG, &gpioInitStruct);
SPI1_OUTPUT_EXTENDER_SW_CS_HIGH();
gpioInitStruct.
GPIO_Mode
=GPIO_Mode_AF_PP
;gpioInitStruct.
GPIO_Pin
= GPIO_Pin_5;//clockGPIO_Init(GPIOA, &gpioInitStruct);
gpioInitStruct.
GPIO_Pin
= GPIO_Pin_7;//mosiGPIO_Init(GPIOA, &gpioInitStruct);
gpioInitStruct.
GPIO_Pin
= GPIO_Pin_6;//misogpioInitStruct.
GPIO_Mode
=GPIO_Mode_IN_FLOATING
;GPIO_Init(GPIOA, &gpioInitStruct);
spiInitStruct.
SPI_Direction
= SPI_Direction_2Lines_FullDuplex;spiInitStruct.
SPI_Mode
= SPI_Mode_Master;spiInitStruct.
SPI_DataSize
= SPI_DataSize_16b;spiInitStruct.
SPI_CPOL
= SPI_CPOL_Low;// idle low
spiInitStruct.
SPI_CPHA
= SPI_CPHA_1Edge;//data captured on leading rising edge
spiInitStruct.
SPI_NSS
= SPI_NSS_Soft;// software driven with external pin CS low active
spiInitStruct.
SPI_FirstBit
= SPI_FirstBit_MSB;spiInitStruct.
SPI_CRCPolynomial
= 7;//not used
spiInitStruct.
SPI_BaudRatePrescaler
= SPI_BaudRatePrescaler_8;SPI_I2S_DeInit(SPI1);
SPI_Init(SPI1, &spiInitStruct);
SPI_Cmd(SPI1,
ENABLE
); The dac1 configuration is:static
void
nw_dac_config
(void
){
GPIO_InitTypeDef
GPIO_InitStructure;
DAC_InitTypeDef
DAC_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,
ENABLE
);GPIO_InitStructure.
GPIO_Pin
= GPIO_Pin_4;GPIO_InitStructure.
GPIO_Mode
=GPIO_Mode_AIN
;GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel1 Configuration */
DAC_InitStructure.
DAC_Trigger
= DAC_Trigger_Software;DAC_InitStructure.
DAC_WaveGeneration
= DAC_WaveGeneration_None;DAC_InitStructure.
DAC_OutputBuffer
= DAC_OutputBuffer_Enable;RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC,
ENABLE
);DAC_Init(DAC_Channel_1, &DAC_InitStructure);
/* Set DAC Channel1 DHR12L register */
DAC_SetChannel1Data(DAC_Align_12b_R, 0x7FF);
}
//-------------
static
void
nw_dac_start
(u16
voltage)//mV
{
#define
NW_ADC_VREF_mV ((u16)3000)#define
NW_ADC_COUNT_MAX ((u16)4095)
u32
data = (voltage > NW_ADC_VREF_mV ? NW_ADC_VREF_mV : voltage) * NW_ADC_COUNT_MAX;
//enable DAC channel
DAC->
CR
|= (DAC_CR_EN1 << DAC_Channel_1);DAC_SetChannel1Data(DAC_Align_12b_R, (
u16
)(data / NW_ADC_VREF_mV));
/* Start DAC Channel1 conversion by software */
DAC_SoftwareTriggerCmd(DAC_Channel_1,
ENABLE
);}
Has anyone experienced similar problems?