2020-09-07 12:48 AM
Hello
Im trying to implement stm32 spi multi-master function on a stm32f765 according to the below presentation
I keep getting MODF error when transmitting as a master, that would indicate that the slave sets the masters NSS pin low. Even if I set the NSS pin permantently high, by hooking it to a 3,3v pin , I get the same error!
below is my setup:
--------MSP SETUP--------------------------------------
GPIO_InitStruct.Pin = SPI_CS_Pin;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT | GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SPI_CS_GPIO_Port, &GPIO_InitStruct);
// SPI master com trigger GPIO pin configuration
GPIO_InitStruct.Pin = SPI_MASTER_TRIG_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP ;
HAL_GPIO_Init(SPI_MASTER_TRIG_Port, &GPIO_InitStruct);
--------MSP SETUP--------------------------------------
------------SPI Handle setup--------------------------
static void setupSPIbaseStruct(SPI_HandleTypeDef *pSpiHandle, uint32_t mode)
{
pSpiHandle->Instance = SPI2;
if (mode == SPI_MODE_MASTER) {
pSpiHandle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
}else{
pSpiHandle->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
}
pSpiHandle->Init.Direction = SPI_DIRECTION_2LINES;
pSpiHandle->Init.CLKPhase = SPI_PHASE_2EDGE;
pSpiHandle->Init.CLKPolarity = SPI_POLARITY_HIGH;
pSpiHandle->Init.DataSize = SPI_DATASIZE_8BIT;
pSpiHandle->Init.FirstBit = SPI_FIRSTBIT_MSB;
pSpiHandle->Init.TIMode = SPI_TIMODE_DISABLE;
pSpiHandle->Init.CRCCalculation = SPI_CRCCALCULATION_ENABLE;
pSpiHandle->Init.CRCPolynomial = 7;
pSpiHandle->Init.NSSPMode = SPI_NSS_PULSE_DISABLED;
pSpiHandle->Init.NSS = SPI_NSS_HARD_INPUT;
pSpiHandle->Init.Mode = mode ;
}
------------SPI Handle setup--------------------------
what Im I doing wrong?
2020-09-08 03:07 AM
I had setting Mode= GPIO_MODE_AF_PP | GPIO_MODE_IT_RISING , this meant that when the HAL function HAL_GPIO_Init checked if AF should be used, the result was faulty ->no AF was set.
Anyway, now I have scaled back to only using AF
GPIOx->MODER = 0xaaa86aa0/ 10101010101010000110101010100000
AFR = 0x40020400/ 1000000000000100000010000000000
AFR[0] = 0xa666900/ 1010011001100110100100000000
AFR[1] = 0x55bbbb50/ 1010101101110111011101101010000
Which is correct right?
The problem now is that the slave does not have a way to detect end of message(thats why I had "|GPIO_MODE_IT_RISING " and then a EXTI interrupt), RxCPLT callback is never called either