Skip to main content
Associate
June 20, 2025
Question

NUCLEO-F072RB with DAC8775EVM via SPI

  • June 20, 2025
  • 3 replies
  • 566 views

Hi all,

I am currently trying to configure the NUCLEO-F072RB to work with an EVM board from TI via SPI. I am very new at using STM32 and I am not quite sure how to go about it. 
1) I have already used CubeMX to do the recommended settings. Do I also need to write the control registers in spi.c as indicated in the F072RB reference manual? For example:

void configSpi_SSM(void)
{
//CONFIGURE SPI1_CR1 REGISTER
//CLEAR BITS
SPI1->CR1 &= ~((1u << 15) //FULL DUPLEX MODE
|(1u << 13) //NOT INTERESTED IN CRC CLACULATIONS, DISABLE CRC
|(1u << 10) //NOT INTERESTED IN SIMPLEX MODE
|(1u << 7) //MSB FIRST
|(7u << 3) //RESET BITS THAT DIVIDE THE FREQUENCY BEFORE SETTING THEM AGAIN
);

//SET BITS
SPI1->CR1 |= ((1u << 9) //SOFTWARE SLAVE MANAGEMENT
|(1u << ‌‌ //INTERNAL SLAVE SELECT
|(4u << 3) //DIVIDE SPI FREQUENCY BY 32
|(1u << 2) //MASTER MODE
|(0u << 1) //CLOCK POLARITY OF 0
|(1u << 0) //CLOCK PHASE OF 1
);


//CONFIGURE SPI1_CR2 REGISTER
//CLEAR BITS
SPI1->CR2 &= ~((1u << 12) //RXNE EVENT TRIGGERED AT 1/2 (16-BIT) RX FIFO LEVEL
|(7u << 5) //CLEAR INTERRUPT RELATED BITS AS WON'T BE USING INTERRUPTS
|(1u << 4) //SPI IN MOTOROLA FORMAT
|(1u << 3) //WON'T BE DOING CONSECUTIVE TRANSFERS
|(3u << 0) //WON'T BE USING DMA, DISABLE TX AND RX DMA REQUEST GENERATION
);

//SET BITS
SPI1->CR2 |= (15u << 8); //16-BIT DATA TRANSFERS

//ENABLE SPI1
SPI1->CR1 |= (1u << 6);
}


2) I know that the DAC demands 24 bit data (8-bit address, 16-bit data) and that I should write 3 8-bit data to it. I saw someone use HAL to transfer 3 8-bit data like so: 

HAL_StatusTypeDef dac8775_Write(uint8_t cmd, uint16_t data) {
uint8_t tx[3] = {
(cmd & 0x7F), // MSB = 0 for write
(uint8_t)(data >> 8),
(uint8_t)(data & 0xFF)
};

CS_Select();
HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, tx, 3, HAL_MAX_DELAY);
CS_Deselect();

return status;
}

Is this correct? I need to send the configuration data to the DAC in (8-bit address, 16-bit data) but I'm not sure if this is the way to send 24-bit data. I've tried it, but it doesn't seem to work.

Please let me know what other information you need and thanks in advance.

3 replies

Andrew Neil
Super User
June 23, 2025

@e230182 wrote:

1) I have already used CubeMX to do the recommended settings. Do I also need to write the control registers in spi.c as indicated in the F072RB reference manual?.


If you're going to use CubeMX to write your setup, then use the HAL functions to drive the SPI.

See UM1785Description of STM32F0 HAL and low-layer drivers:

https://www.st.com/resource/en/user_manual/um1785-description-of-stm32f0-hal-and-lowlayer-drivers-stmicroelectronics.pdf

via: https://www.st.com/en/embedded-software/stm32cubef0.html#documentation

 

Note that SPI transfers generally involve both sending and receiving - so HAL_SPI_TransmitReceive() is most likely the function you'll need ...

 

You haven't said what TI part you're using. You'll have to see its documentation for what it needs to receive, and what it will return.

 

EDIT: Sorry, it's in the title!

This: https://www.ti.com/tool/DAC8775EVM ?

So the chip documentation is here: https://www.ti.com/product/DAC8775

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
Super User
June 23, 2025

I need to send the configuration data to the DAC in (8-bit address, 16-bit data) but I'm not sure if this is the way to send 24-bit data

Yes this looks correct if the data is big endian (MSByte goes first).

Please use a logic analyzer to verify that the correct bits go on the wire.

 

e230182Author
Associate
June 24, 2025
 CS_EN();
 uint8_t RESET_REG[3] = {0x01, 0x00, 0x01};
 HAL_SPI_Transmit(&hspi2, RESET_REG, 3, HAL_MAX_DELAY);
 HAL_Delay(50);
 CS_DIS();

 CS_EN();
 uint8_t RESET_CFG_REG[3] = {0x02, 0x00, 0x11}; // enable Internal ref & UBT = 1
 HAL_SPI_Transmit(&hspi2, RESET_CFG_REG, 3, HAL_MAX_DELAY);
 HAL_Delay(50);
 CS_DIS();

 CS_EN();
 uint8_t SBB_A[3] = {0x06, 0x00, 0x01}; //set Buck Boost A
 HAL_SPI_Transmit(&hspi2, SBB_A, 3, HAL_MAX_DELAY);
 HAL_Delay(50);
 CS_DIS();

 CS_EN();
 uint8_t CFG_BB_A[3] = {0x07, 0x00, 0x03}; //configure buck boost A
 HAL_SPI_Transmit(&hspi2, CFG_BB_A, 3, HAL_MAX_DELAY);
 HAL_Delay(50);
 CS_DIS();

 CS_EN();
 uint8_t SEL_CHANNEL_A[3] = {0x03, 0x00, 0x20}; // select channel A
 HAL_SPI_Transmit(&hspi2, SEL_CHANNEL_A, 3, HAL_MAX_DELAY);
 HAL_Delay(50);
 CS_DIS();

 CS_EN();
 uint8_t CFG_CHANNEL_A[3] = {0x04, 0x10, 0x01}; // configure channel A to output 0-10V
 HAL_SPI_Transmit(&hspi2, CFG_CHANNEL_A, 3, HAL_MAX_DELAY);
 HAL_Delay(50);
 CS_DIS();

 CS_EN();
 uint8_t DATA_A[3] = {0x05, 0xFF, 0xFF}; // Max value for 10V
 HAL_SPI_Transmit(&hspi2, DATA_A, 3, HAL_MAX_DELAY);
 CS_DIS();

 

I was using this instead, and someone said this was correct? But I am not getting any outputs either. I am not sure what kind of logic analyzer is available nor how to use it. I have an oscilloscope but when I connect them to any of the wires I do not see any wave forms or clocks but I can confirm that the board works and the wires are correct.

Ozone
Principal
June 24, 2025

> I have an oscilloscope but when I connect them to any of the wires I do not see any wave forms or clocks but I can confirm that the board works and the wires are correct.

Almost certainly because your initialisation of the SPI peripheral is not correct.
You can use the Cube/HAL code from a matching SPI example to do that.
Or study the exact sequence of config register writes, and reproduce it in your code.

On that note, avoid magic numbers like you did :

SPI1->CR2 |= (15u << 8); //16-BIT DATA TRANSFERS

The device-specific header files defines proper macos for all the peripheral register bits and values.
Using those will make you code mostly self-documenting and much easier to understand.
Once you need to touch code like yours after a break of several weeks or months you understand what I mean ...