2022-12-06 07:04 AM
I set up my spi5 as follows
hspi5.Init.Mode = SPI_MODE_MASTER;
hspi5.Init.Direction = SPI_DIRECTION_2LINES;
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi5.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi5.Init.NSS = SPI_NSS_SOFT;
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi5.Init.CRCPolynomial = 0x0;
hspi5.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
hspi5.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi5.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi5.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi5.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
hspi5.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi5.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi5.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi5.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi5.Init.IOSwap = SPI_IO_SWAP_DISABLE;
but using SPI_BAUDRATEPRESCALER_4 or less causes the SPI to show no data. The entire MCU seems to stop working. I have a GPIO controlled cable section and it also does not show up on the scope when the prescaller is 4.
What might cause this?
2022-12-06 10:14 AM
Did some debugging and it runs the HAL_SPI_TransmitReceive one time or but on the second occurrence its froze in that function
if I step in it reaches
/* Transmit and Receive data in 8 Bit mode */
else
{
while ((initial_TxXferCount > 0UL) || (initial_RxXferCount > 0UL))
{
and never exits the loop
I assume its my time out, I understand this to mean a timeout in ms. but I do not really need one. Either way a timer out of 1 or greater causes the freezing. Anything less gives me a partial command. Like it starts the SPI and then stops.
works with partial spi
HAL_SPI_TransmitReceive (&hspi5, data_to_send, test, sizeof(data_to_send), .999);
freezes
HAL_SPI_TransmitReceive (&hspi5, data_to_send, test, sizeof(data_to_send), 1);
2022-12-06 10:42 AM
Doesn't take floats.
Assuming this is the H7 part
Show the surrounding code, and buffer definitions. Paste your actual code.
Use a long timeout, long enough for the bytes in question to clock out.
The transaction is symmetrical, the input and output buffers need to be of equivalent size, and you're passing in pointers.
2022-12-06 10:54 AM
Yes h7
my spi code is like so
CS_ACTIVE;
//0101 1010 0100 0101 1010 0100
//0x5a 0x45 0xa4
uint8_t test[]={1,1,1, 1,1,1, 1,1,1, 1,1,1};
// CH3 CH2 CH1 CH0 output
// [010][010][010][010] [0000] [000][00][000] 01001001 00100000 00000000
// |16/18 bits reply -------| pad CHID SP input
uint8_t data_to_send[]={0x25, 0x20, 0x00,
0x00, 0x00, 0x00, //next 24.
0x00, 0x00, 0x00,//next 24.
0x00, 0x00, 0x00};//next 24.
//HAL_SPI_Transmit(&hspi5,data_to_send, sizeof(data_to_send),100);
HAL_SPI_TransmitReceive (&hspi5, data_to_send, test, sizeof(data_to_send), .999);
while(HAL_SPI_GetState(&hspi5) != HAL_SPI_STATE_READY);
CS_DEACTIVE;
Using a SPI_BAUDRATEPRESCALER_8 and a timeout of 100 works fine. But using a SPI_BAUDRATEPRESCALER_4 causes everything to stop. This is where I noticed a float show at lease some attempt on the wire. The entire SPI is under 10 us.
2022-12-06 11:22 AM
There is no need for a delay concept in SPI Master mode.
2022-12-07 09:18 AM
I'm thinking its my slave. It says 25MHz max. but just very odd that the trace shows no sign of SPI at all. I'd expect at least the beginning of it. My scope does 100.
does the spi interface automatically enable pullups on the clock? thinking what 40k? bet it wont help.
2022-12-08 03:59 AM
How have you configured the pins for SPI, in particular the output-speed GPIOx_OSPEEDR?
If you're using HAL, it might be GPIO_InitTypeDef.Speed, and you might need GPIO_SPEED_FREQ_VERY_HIGH - see the data-sheet for how these values translate to usable I/O pin speeds depending on load-capacitance and supply-voltage.
That's a trade-off between how fast you want to send data and how much EMC emissions you're willing to generate (that might need screening to prevent radio interference).
SPI pins are totem-pole/push-pull, so there's no benefit to pull-ups.
2022-12-20 05:14 AM
Is there only the one setting (BaudRatePrescaler )for SPI on ST chips for speed? I know on AVR you have a scaller and a doubler. I'm sitting at 16.6MHz and I'd like to hit 25 but a BaudRatePrescaler of 4 is too fast.
sth735 @ 550 MHz fCPU
if I'm trully running at 550 then a 32 divider but be what SPI_BAUDRATEPRESCALER_8 means. and the 4 must mean 16 @ 34MHz.
2022-12-20 07:08 AM
Read the response by Danish above. To use any pins at 25 MHz you must set the pins' drive strength in GPIO OSPEEDR register to the highest value.
2022-12-20 08:14 AM
pretty sure its already highest.
I have this
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;//GPIO_PULLUP GPIO_PULLDOWN
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
setting to anything but highest causes my clock cycles to become less square.
I think my problem is SPI_BAUDRATEPRESCALER_4 makes it 32MHz not 25MHz and that is too fast for my slave. Is there a way to do a SPI_BAUDRATEPRESCALER in between 4 and 8?
read up on this I forgot there was a clock config for the stm32's.. I just need to use the 96 and then / 4