cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Strange behaviour with two slaves

HBesi.1
Associate II

Hello,

I have a SPI interface with two slaves. This is my code:

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_ADC1_Init();

 MX_ADC2_Init();

 MX_TIM6_Init();

 MX_USART3_UART_Init();

 MX_SPI1_Init();

 MX_USB_DEVICE_Init();

 /* USER CODE BEGIN 2 */

 HAL_Delay(100);

/*

 //Programm DDS2

 DDS_freq_calc(2500, 0, &spi_tx_buf[0]);

 HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_RESET);

 HAL_SPI_Transmit(&hspi1,(uint8_t*) &spi_tx_buf[0], 5, 1);

 HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_SET);

 HAL_Delay(5);

 //Enable comparator

 HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_RESET);

 HAL_SPI_Transmit(&hspi1,(uint8_t*) &comparator_en, 1, 1);

 HAL_GPIO_WritePin(CS2_GPIO_Port, CS2_Pin, GPIO_PIN_SET);

 HAL_Delay(5);

*/

 //Program DDS1

 DDS_freq_calc(1000, 0, &spi_tx_buf[0]);

 HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);

 HAL_SPI_Transmit(&hspi1,(uint8_t*) &spi_tx_buf[0], 5, 1);

 HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);

 HAL_Delay(5);

 //Enable comparator

 HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_RESET);

 HAL_SPI_Transmit(&hspi1,(uint8_t*) &comparator_en, 1, 1);

 HAL_GPIO_WritePin(CS1_GPIO_Port, CS1_Pin, GPIO_PIN_SET);

 HAL_Delay(5);

 //reset DDS1 & DDS2

 HAL_GPIO_WritePin(DDS_reset_GPIO_Port, DDS_reset_Pin, GPIO_PIN_SET);

 HAL_Delay(1);

 HAL_GPIO_WritePin(DDS_reset_GPIO_Port, DDS_reset_Pin, GPIO_PIN_RESET);

 HAL_Delay(5);

I manage to program only the second slave but not the first in this configuration. If I swap the code for slave 1 and slave 2 Then the second gets cpnfigured and the first not . If I coment the coude out for the first to be configured the second wont be configured to. Has somebody encountered a problem like this?

Best regards

1 REPLY 1

Check initial states of the pins, especially CS, make sure both are high

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..