cancel
Showing results for 
Search instead for 
Did you mean: 

SPI driver for MCP410 Controllable potentiometer

LPetr.1
Senior

Hello. I am writing an SPI driver for STM32F407 Microcontroller to control the resistance of the MCP410 chip.

The datasheet for the chip can be found here:

https://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf

The I use a cheap logic analyzer together with SALE software to check and debug SPI signals

0693W00000LyaItQAJ.jpg 

My SPI configuration in CubeMX:

0693W00000LyaLYQAZ.png 

According to the documentation:

0693W00000LyaKQQAZ.png 

I need to send 1 command byte and 1 data byte.

So in my main.c I do the following:

uint8_t spi_data1[2] = {0x01,0x00};
while (1)
        {
	 HAL_Delay(1000);
	 HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, 0); // chip select LOW
	 HAL_SPI_Transmit(&hspi1, spi_data1, 2, 0xff);
	 HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, 1); // chip select HIGH
         }

Now in my SALAE software, I see the following:

0693W00000LyaHIQAZ.pngI would like to understand why the first clock cycle is very short. Is that a problem with my logic analyzer or that is normal behaviour?

1 REPLY 1
TDK
Guru

Send a byte with CS high to enable the peripheral (the data will be ignored, but the peripheral will be enabled as a side effect).

The peripheral is not enabled until the first HAL_SPI_Transmit call which means the pins aren't being driven until that point.

uint8_t spi_data1[2] = {0x01,0x00};
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, 1); // chip select HIGH
HAL_SPI_Transmit(&hspi1, spi_data1, 2, 0xff);
while (1)
        {
	 HAL_Delay(1000);
	 HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, 0); // chip select LOW
	 HAL_SPI_Transmit(&hspi1, spi_data1, 2, 0xff);
	 HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12, 1); // chip select HIGH
         }

If you feel a post has answered your question, please click "Accept as Solution".