cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32F103RET6 with external DAC 7614e

AKh.1
Associate II

Dear all,

This is supposed to be simple, but I have a serious problem that left me no choice but ask for a help! So any contribution is appreciated =)

I have interfaced a STM32F103RET6 with an external 7614e DAC using SPI. According to the DAC datasheet I have set the values and it seemed easy. I am trying to make analoge signal in the outpout​, but what I get is just triangle wave and I don't know why!

I would be thankful if you help me with this matter.​

I think the problem is in my code or configuration of SPI in Cubemx!​ briefly: I used a spi interrupt to tell me when the transmission is done to set or reset CS or LOADDAC pins in DAC.

PIN B7: refers to DAC CS

PIN B5: refers to DAV LOADDAC

Here is my code:

include "main.h"

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

SPI_HandleTypeDef hspi2;

/* USER CODE BEGIN PV */

uint8_t buffer_tx[2]={0x0c,0x00};

uint8_t x=0;

/* USER CODE END PV */

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

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_SPI2_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)

{

if(hspi->Instance == SPI2)

{

x=1;

}

}

/* USER CODE END 0 */

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

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

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_SPI2_Init();

/* USER CODE BEGIN 2 */

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_RESET);

HAL_SPI_Transmit_IT(&hspi2,buffer_tx,2);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);

if(x==1){

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET);

HAL_Delay(2000);

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET);

x=0;

}

/* USER CODE END 2 */

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

/* USER CODE END 3 */

}

0 REPLIES 0