AnsweredAssumed Answered

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

Question asked by edmond yun on May 28, 2018
Latest reply on May 28, 2018 by AvaTar

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 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 https://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);
}

Outcomes