65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
/*
|
|
* @Author: DaMingSY zxm5337@163.com
|
|
* @Date: 2024-10-10 11:17:45
|
|
* @LastEditors: DaMingSY zxm5337@163.com
|
|
* @LastEditTime: 2024-10-11 15:09:07
|
|
* @FilePath: \signal_generator\App\DAC7811\dac7811.c
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
*/
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
#include "dac7811.h"
|
|
#include "ads1220.h"
|
|
#include "spi.h"
|
|
#include "gpio.h"
|
|
#include "stm32f407xx.h"
|
|
|
|
BOOL dac7811_spi_init_flag = FALSE;
|
|
|
|
void fun_dac7811_spi1_init()
|
|
{
|
|
hspi1.Instance = SPI1;
|
|
hspi1.Init.Mode = SPI_MODE_MASTER;
|
|
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
|
hspi1.Init.DataSize = SPI_DATASIZE_16BIT;
|
|
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
|
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
hspi1.Init.NSS = SPI_NSS_SOFT;
|
|
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
|
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
hspi1.Init.CRCPolynomial = 10;
|
|
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
ADS1220_CS(GPIO_PIN_SET);
|
|
DAC7811_CS(GPIO_PIN_SET);
|
|
}
|
|
|
|
void fun_dac7811_operate(float32 *data_sv)
|
|
{
|
|
if (data_sv == NULL)
|
|
return;
|
|
|
|
uint16_t reg_data = 0;
|
|
|
|
reg_data = (uint16_t)(*data_sv);
|
|
reg_data |= 0x1000;
|
|
reg_data &= 0x1fff;
|
|
|
|
if (dac7811_spi_init_flag == FALSE)
|
|
{
|
|
fun_dac7811_spi1_init();
|
|
ads1220_spi_init_flag = FALSE;
|
|
dac7811_spi_init_flag = TRUE;
|
|
}
|
|
else
|
|
{
|
|
DAC7811_CS(GPIO_PIN_RESET);
|
|
HAL_SPI_Transmit(&hspi1, (uint8_t *)(®_data), 1, 1000);
|
|
DAC7811_CS(GPIO_PIN_SET);
|
|
}
|
|
}
|