|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2015-4-24 12:08:28
|
显示全部楼层
以下是程序部分,大家看看有没有什么问题:
#include "ad7606.h"
#include "delay.h"
#include "stm32f10x.h"
#define CONVST_1() GPIOB->BSRR = GPIO_Pin_7
#define CONVST_0() GPIOB->BRR = GPIO_Pin_7
#define RESET_1() GPIOB->BSRR = GPIO_Pin_6
#define RESET_0() GPIOB->BRR = GPIO_Pin_6
#define AD7606_RESULT() *(__IO uint16_t *)0x6C400000
AD7606_VAR_T g_tAD7606;
static void AD7606_CtrlLinesConfig(void);
static void AD7606_FSMCConfig(void);
void AD7606_Init(void)
{
AD7606_CtrlLinesConfig();
AD7606_FSMCConfig();
AD7606_Reset();
CONVST_1();
}
static void AD7606_CtrlLinesConfig(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOG, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_8 | GPIO_Pin_9 |
GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/*
PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
PE.14(D11), PE.15(D12)
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/*!< NOE and NWE configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* NE4 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOG, &GPIO_InitStructure);
//PB7/AD7606_CONVST ---> AD7606_CONVST
//PB6/AD7606_RESET ---> AD7606_RESET
//PB9/AD7606_BUSY ---> AD7606_BUSY
//PB8/AD7606_FRSTDATA ---->AD7606_FRSTDATA
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 ;//| GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
static void AD7606_FSMCConfig(void)
{
FSMC_NORSRAMInitTypeDef init;
FSMC_NORSRAMTimingInitTypeDef timing;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);
/* FSMC_Bank1_NORSRAM4 configuration */
timing.FSMC_AddressSetupTime = 3;
timing.FSMC_AddressHoldTime = 0;
timing.FSMC_DataSetupTime = 5;
timing.FSMC_BusTurnAroundDuration = 1;
timing.FSMC_CLKDivision = 0;
timing.FSMC_DataLatency = 0;
timing.FSMC_AccessMode = FSMC_AccessMode_A;
init.FSMC_Bank = FSMC_Bank1_NORSRAM4;
init.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
//init.FSMC_MemoryType = FSMC_MemoryType_NOR;
init.FSMC_MemoryType = FSMC_MemoryType_SRAM;
init.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
init.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
init.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
init.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
init.FSMC_WrapMode = FSMC_WrapMode_Disable;
init.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
init.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
init.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
init.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
init.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
init.FSMC_ReadWriteTimingStruct = &timing;
init.FSMC_WriteTimingStruct = &timing;
FSMC_NORSRAMInit(&init);
/* - BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
}
void AD7606_Reset(void)
{
RESET_0();
RESET_1();
RESET_1();
RESET_1();
RESET_1();
RESET_0();
}
void AD7606_StartConvst(void)
{
CONVST_0();
CONVST_0();
CONVST_0();
CONVST_1();
}
这是MAIN 函数
int main(void)
{
delay_init();
NVIC_Configuration();
FSMC_SRAM_Init();
LED_Init();
uart_init(9600);
AD7606_Init();
TIM3_Int_Init(4999,7199);
while (1)
{
//delay_ms(500);
AD7606_StartConvst();
delay_us(25);
AD7606_ReadNowAdc();
delay_ms(500);
// printf("%d,",g_tAD7606.sNowAdc[0]);
// g_tAD7606.sNowAdc[0], g_tAD7606.sNowAdc[1],
printf("CH1 = %6d, CH2 = %6d, CH3 = %6d, CH4 = %6d, ",
g_tAD7606.sNowAdc[0], g_tAD7606.sNowAdc[1], g_tAD7606.sNowAdc[2], g_tAD7606.sNowAdc[3]);
printf("CH5 = %6d, CH6 = %6d, CH7 = %6d, CH8 = %6d\r",
g_tAD7606.sNowAdc[4], g_tAD7606.sNowAdc[5], g_tAD7606.sNowAdc[6], g_tAD7606.sNowAdc[7]);
delay_us(25);
// AD7606_Reset();
}
} |
|