AnsweredAssumed Answered

Issue SPI transfer using HAL_SPI_Transmit_DMA

Question asked by Karthik Srinivas Ghantasala on Aug 9, 2017

Hi 

First I will give info about my project.

I am generating PWM using timer, then SPI using Full Duplex slave mode and a GPIO pin. 

PWM is connected to SPI sclk and GPIO is connected to NSS.

I am transferring data from 1 to 550 and 1100 to 1650. Now the problem is the first block of data i.e 1 to 550 going well. when I restart the SPI transfer I see some 2 bytes of junk data that is transferring through SPI. Below is the code and waveform.

Please suggest me and let me know where I am going wrong.

 

MX_GPIO_Init();
MX_DMA_Init();
MX_SPI1_Init();
MX_TIM3_Init();

/* USER CODE BEGIN 2 */

 

int j = 1;
for (uint16_t i = 0; i < 1100; i = i+2)
{
testDataToSend[i] = j;
testDataToSend[i+1] = j >> 8;
j++;
}

 


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
HAL_SPI_Transmit_DMA(&hspi1, testDataToSend, 1100);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);

HAL_Delay(1);
HAL_TIM_Base_Start_IT(&htim3);

while(flag != 1){
}
flag = 0;
for (uint16_t i = 0; i < 75; i++);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);

HAL_SPI_DMAStop(&hspi1);
HAL_SPI_Abort(&hspi1);
*testDataToSend = NULL;

 

 

j = 1100;
for (uint16_t i = 0; i < 1100; i = i+2)
{
testDataToSend_1[i] = j;
testDataToSend_1[i+1] = j >> 8;
j++;
}

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
HAL_SPI_Transmit_DMA(&hspi1, testDataToSend_1, 1100);
HAL_TIM_Base_Start_IT(&htim3);


while(flag != 1){
}
flag = 0;
for (uint16_t i = 0; i < 35; i++);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
*testDataToSend_1 = NULL;

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{

}
/* USER CODE END WHILE */

 

 

 

 

void DMA1_Channel3_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel3_IRQn 0 */

 

flag = 1;
/* USER CODE END DMA1_Channel3_IRQn 0 */
HAL_DMA_IRQHandler(&hdma_spi1_tx);
/* USER CODE BEGIN DMA1_Channel3_IRQn 1 */

/* USER CODE END DMA1_Channel3_IRQn 1 */
}


void TIM3_IRQHandler(void)
{
/* USER CODE BEGIN TIM3_IRQn 0 */

 

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_TIM_Base_Stop_IT(&htim3);

/* USER CODE END TIM3_IRQn 0 */
HAL_TIM_IRQHandler(&htim3);
/* USER CODE BEGIN TIM3_IRQn 1 */

/* USER CODE END TIM3_IRQn 1 */
}

Attachments

Outcomes