This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PGA113程序驱动

驱动程序如下   电压一直放不大一直  找不到程序哪有问题

#include "PGA.h"


void PGA_GPIOInit(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;

/* 使能SPI时钟 */
PGA_SPI_APBxClock_FUN ( PGA_SPI_CLK, ENABLE );

/* 使能SPI引脚相关的时钟 */
PGA_SPI_CS_APBxClock_FUN ( PGA_SPI_CS_CLK|PGA_SPI_SCK_CLK|
PGA_SPI_MOSI_PIN, ENABLE );

/* 配置SPI的 CS引脚,普通IO即可 */
GPIO_InitStructure.GPIO_Pin = PGA_SPI_CS_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PGA_SPI_CS_PORT, &GPIO_InitStructure);

/* 配置SPI的 SCK引脚*/
GPIO_InitStructure.GPIO_Pin = PGA_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(PGA_SPI_SCK_PORT, &GPIO_InitStructure);

/* 配置SPI的 MOSI引脚*/
GPIO_InitStructure.GPIO_Pin = PGA_SPI_MOSI_PIN;
GPIO_Init(PGA_SPI_MOSI_PORT, &GPIO_InitStructure);

/* 停止信号 PGA: CS引脚高电平*/
SPI_PGA_CS_HIGH();

/* SPI 模式配置 */

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_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;

SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(PGA_SPIx , &SPI_InitStructure);

/* 使能 SPI */
SPI_Cmd(PGA_SPIx , ENABLE);

}


void SPI_PAG_SendData (uint8_t data)
{
time_out = 10000;
while(SPI_I2S_GetFlagStatus( SPI2,SPI_I2S_FLAG_TXE) == SET)
{

SPI_I2S_SendData(SPI2,data);
}
}


static void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}

void WriteByte(u8 command)
{
unsigned char i;

SPI_PGA_CS_LOW();
Delay(0xffffee);
for(i = 0; i < 16;i++)
{
SPI_PGA_SCK_LOW();
if(command&0x80)
SPI_PGA_MOSI_HIGH();
else
SPI_PGA_MOSI_LOW();
SPI_PGA_SCK_HIGH();
command <<= 1;
}
SPI_PGA_SCK_LOW();
Delay(0xffffee);
SPI_PGA_CS_HIGH();
}
void configPGA(u8 ch,u8 gain)
{
unsigned char i;
switch(gain)
{
case 1: gain=pgaGain1;
break;
case 2: gain=pgaGain2;
break;
case 4: gain=pgaGain4;
break;
case 8: gain=pgaGain8;
break;
case 16: gain=pgaGain16;
break;
case 32: gain=pgaGain32;
break;
case 64: gain=pgaGain64;
break;
case 128: gain=pgaGain128;
break;
default: gain=pgaGain2;
break;
}
i=ch+gain;
SPI_PGA_CS_LOW();
WriteByte(0x01);
WriteByte(i);
SPI_PGA_CS_HIGH();
}