2022-04-21 02:37 AM
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
My SPI configuration in CubeMX:
According to the documentation:
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:
I 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?
2022-04-21 06:17 AM
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
}