打印
[应用相关]

afe4300 控制問題

[复制链接]
1505|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wayne770403|  楼主 | 2015-8-26 15:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
示波器抓ADC_CONTROL_REGISTER1沒任何輸出

#include "stm32f4xx_hal.h"


/* USER CODE BEGIN Includes */
#define MEANTIMES 1500
#define REF_R0_REAL_VALUE 157.5
#define REF_R1_REAL_VALUE 48
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
void AFE4300_WriteRegister(unsigned char address,unsigned char data1,unsigned char data2);
void AFE4300_ReadRegister(unsigned char address);
/* USER CODE BEGIN PFP */

/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */
unsigned char aTxBuffer[] = {0xAA};
unsigned char RxBuffer[] = {0};
/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */
int  i = 0;
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();

  /* USER CODE BEGIN 2 */
        HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_SET);
       
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
                AFE4300_WriteRegister(0X01,0XC9,0XC0);
                AFE4300_WriteRegister(0X02,0X00,0X00);
                AFE4300_WriteRegister(0X03,0XFF,0XFF);
                AFE4300_WriteRegister(0X09,0X60,0X06);
                AFE4300_WriteRegister(0X0A,0X04,0X00);
                AFE4300_WriteRegister(0X0B,0X04,0X00);
                AFE4300_WriteRegister(0X0C,0X00,0X00);
                AFE4300_WriteRegister(0X0D,0X00,0X00);
                AFE4300_WriteRegister(0X0E,0X00,0X10);
                AFE4300_WriteRegister(0X0F,0X00,0X00);
                AFE4300_WriteRegister(0X10,0X00,0X63);
                AFE4300_WriteRegister(0X1A,0X00,0X30);
                AFE4300_WriteRegister(0X01,0XC9,0X40);
                HAL_Delay(1);
                AFE4300_ReadRegister (0x0A);
               
//        for( i = 0; i <MEANTIMES; i++)
//                {
//                  RefResistance1 = AFE4300_ReadADC_ContinuousMode();
//                }
               
  }
  /* USER CODE END 3 */

}

/** System Clock Configuration
*/
void SystemClock_Config(void)
{

  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_ClkInitTypeDef RCC_ClkInitStruct;

  __PWR_CLK_ENABLE();

  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 256;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  HAL_RCC_OscConfig(&RCC_OscInitStruct);

  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1
                              |RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);

  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

}

/* SPI1 init function */
void MX_SPI1_Init(void)
{

  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  hspi1.Init.CRCPolynomial = 10;
  HAL_SPI_Init(&hspi1);

}

/** Configure pins as
        * Analog
        * Input
        * Output
        * EVENT_OUT
        * EXTI
*/
void MX_GPIO_Init(void)
{

  GPIO_InitTypeDef GPIO_InitStruct;

  /* GPIO Ports Clock Enable */
  __GPIOC_CLK_ENABLE();
  __GPIOH_CLK_ENABLE();
  __GPIOA_CLK_ENABLE();

  /*Configure GPIO pin : PA0 */
  GPIO_InitStruct.Pin = GPIO_PIN_0;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /*Configure GPIO pin : PC4 */
  GPIO_InitStruct.Pin = GPIO_PIN_4;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /*Configure GPIO pin : PC5 */
  GPIO_InitStruct.Pin = GPIO_PIN_5;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */
void AFE4300_WriteRegister(unsigned char address,unsigned char data1,unsigned char data2)
{
        unsigned char TxBuffer[] = {address,data1,data2};

                HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_RESET);
                HAL_SPI_Transmit(&hspi1,TxBuffer,3,5000);
                HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_SET);

}

void AFE4300_ReadRegister(unsigned char address)
{
                unsigned char TxBuffer[] = {address|0x20,0xFF,0xFF};
                HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_RESET);
                HAL_SPI_Transmit(&hspi1,TxBuffer,1,5000);
                HAL_SPI_TransmitReceive(&hspi1,TxBuffer+1,RxBuffer, 2,5000);
                HAL_GPIO_WritePin(GPIOC,GPIO_PIN_4,GPIO_PIN_SET);
}
/* USER CODE END 4 */

#ifdef USE_FULL_ASSERT

/**
   * @brief Reports the name of the source file and the source line number
   * where the assert_param error has occurred.
   * @param file: pointer to the source file name
   * @param line: assert_param error line source number
   * @retval None
   */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
    ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */

}

#endif
沙发
309030106| | 2015-8-29 11:44 | 只看该作者
设个断点看看哪些代码没运行到

使用特权

评论回复
板凳
mintspring| | 2015-8-29 12:39 | 只看该作者
void SystemClock_Config(void);

使用特权

评论回复
地板
598330983| | 2015-8-29 12:59 | 只看该作者
调试看看,看看那些代码到底执行了没。

使用特权

评论回复
5
yiyigirl2014| | 2015-8-29 13:32 | 只看该作者
抓是肯定抓不到吧,都是输入信号怎么抓。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

13

帖子

0

粉丝