cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC or USART (with or except using printf) problem when using 1 seconds timer to output DAC(external DAC)

edmond yun
Associate II
Posted on May 28, 2018 at 09:58

Hello,

I need your help to recognize my issue correctly, please help me,

issue :

when using timer as 1 second period to control main flow including printf output,

and at that time if using another timer to control the output of DAC with spi communication, the period is 1 us or others,

the problem is that the waveform (square or sine) is instantly disconnected every 1 seconds,

it is related with the output of printf, if not using printf, the output of waveform is normal...

I wonder whether I need to control the group priority related with the timers or not, 

anyway, if you can help to solve issue or give any advice, I am very thankful for your kindness in advance,

thanks. 

ref) my email is

mailto:foolove1004@naver.com

.

I update the code of DAC SPI control.....

void dacTransmit24bits_dac1(uint8_t reg[])//(uint32_t data)//love_0316 the range of data variable is 0 ~ 65536,

{//refer to

www.avrfreaks.net/forum/tutsoft-ad5061-sample-code

// uint8_t *p = (uint8_t*)&data ;

uint8_t *p = (uint8_t*)reg ;

// printf('TEST : %d \r\n', *p);

SPI_AD5063_SPI1_CS_LOW();

for (int8_t i=2; i>=0; i--)

HAL_SPI_Transmit_DMA(&hspi1, &p[i], 1);//love_0508

SPI_AD5063_SPI1_CS_HIGH();

}

void MX_SPI1_Nss_Pin_init(void)//love_0316 For PC1 (NSS PIN),

{

GPIO_InitTypeDef gpioInitStructure;

__HAL_RCC_GPIOC_CLK_ENABLE();//love_0316

gpioInitStructure.Pin = GPIO_PIN_1;

gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;

gpioInitStructure.Pull = GPIO_NOPULL;

gpioInitStructure.Speed = GPIO_SPEED_FREQ_HIGH;//GPIO_SPEED_FREQ_HIGH GPIO_SPEED_HIGH

HAL_GPIO_Init(GPIOC, &gpioInitStructure);

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET);//love_0316 To be initialized for NSS Pin status as 1 (No seletion status),

//love_0425 For 30V_On Pin,

__HAL_RCC_GPIOE_CLK_ENABLE();//love_0316

gpioInitStructure.Pin = GPIO_PIN_4;

gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;

gpioInitStructure.Pull = GPIO_NOPULL;

gpioInitStructure.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOE, &gpioInitStructure);

HAL_GPIO_WritePin(GPIOE, GPIO_PIN_4, GPIO_PIN_SET);//GPIO_PIN_RESET GPIO_PIN_SET

}

/* SPI1 init function */

void MX_SPI1_Init(void)//SPI mode to 1 or 2 For ADC5063,

{

/* SPI1 parameter configuration*/

hspi1.Instance = SPI1;

hspi1.Init.Mode = SPI_MODE_MASTER;

hspi1.Init.Direction = SPI_DIRECTION_1LINE;

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_2;

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(__FILE__, __LINE__);

}

/**

* Enable DMA controller clock

*/

void AD5063_SPI1_MX_DMA_Init(void)//love_0508

{

/* DMA controller clock enable */

__HAL_RCC_DMA2_CLK_ENABLE();

/* DMA interrupt init */

/* DMA2_Stream3_IRQn interrupt configuration */

HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);

}

#stm32f429
6 REPLIES 6
AvaTar
Lead
Posted on May 28, 2018 at 10:27

Have you thought about priorizing your interrupts ?

Or else, you could use DMA (and not interrupts) to push your SPI data to the DAC.

ref) my email is

mailto:foolove1004@naver.com

I usually avoid publishing my mail address here, or on another forum.

The forum is visible to anyone, not just logged-in users. ST has no control over mail address harvesters...

Posted on May 28, 2018 at 10:41

Hello, AvaTar,

thankful for good points, but I already used DMA for SPI communication, and then I got this problem,

and I have a question, which interrupt do you mean ? please help to let me know your opinion with detailed information like how to do ....

thankful for your support in advance,

thanks.

Posted on May 28, 2018 at 11:01

The more imortant / time critical task (interrupt) gets the higher priority. Thus it supposedly can interrupt a running USB/printf.

... but I already used DMA for SPI communication, and then I got this problem, ...

Not sure what interrupt it is (probably DMA TC), and how you use it.

Make sure you understand the interaction of your code, the interrupts, and the DMA usage.

You need to synchronize the update of your DAC output data with the DMA (or whatever means you use).

In circular mode, DMA restarts at your configured buffer address without core interaction. Having the core writing at this buffer at the same time will yield unpredictable results (DAC outputs).

Posted on May 28, 2018 at 11:27

I updated the code, please check it and help to let me know what is wrong...

thanks.

Posted on May 28, 2018 at 11:41

I updated the code, please check it and help to let me know what is wrong...

thanks.

Posted on May 28, 2018 at 12:12

I can't see what interrupt DMA supposedly uses, and in which context the SPI/DMA transfer runs.

But I don't do Cube / HAL, perhaps others can comment on the code.