//********************************************************************************//
//* 函数名: SPI_Write(unsigned char txdata) //
//* 函数功能: SPI单字节写入函数 //
//********************************************************************************//
void SPI_Write(unsigned char txdata)
{
unsigned char i;
for (i = 0;i < 8;i++)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_13);//RF4432_SCLK=0;
delay_us(20);
if ((txdata&0x80)==0x80) //总是发送最高位
{
GPIO_SetBits(GPIOB, GPIO_Pin_15);
}
else
{
GPIO_ResetBits(GPIOC,GPIO_Pin_15);
}
txdata = txdata<<1;
delay_us(20);//delay_10us(2);
GPIO_SetBits(GPIOB, GPIO_Pin_13);//RF4432_SCLK=1;
delay_us(20);//delay_10us(2);
}
}
void Si4332_GPIO_Config(void)
{
/*定义一个GPIO_InitTypeDef类型的结构体*/
GPIO_InitTypeDef GPIO_InitStructure;
/*开启GPIOB的外设时钟*/
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*选择要控制的GPIOB引脚*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_15|GPIO_Pin_13;
/*设置引脚模式为通用推挽输出*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/*设置引脚速率为50MHz */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/*调用库函数,初始化GPIOB*/
GPIO_Init(GPIOB, &GPIO_InitStructure);
/*开启GPIOC的外设时钟*/
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE);
/*选择要控制的GPIOC引脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_5;
/*设置引脚模式为通用推挽输出*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/*设置引脚速率为50MHz */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/*调用库函数,初始化GPIOC*/
GPIO_Init(GPIOC, &GPIO_InitStructure);
/*开启GPIOA的外设时钟*/
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/*选择要控制的GPIOC引脚*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
/*设置引脚模式为通用推挽输出*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/*设置引脚速率为50MHz */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/*调用库函数,初始化GPIOC*/
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_9);
}
void main()
{
Si4332_GPIO_Config ();
while(1)
{
SPI_Write (0x0f);
}
}
执行完那个
SPI_Write ()程序后,PB15脚一直是高电平。没办法拉低,新手,求高手指点一下,谢谢
|