2023-01-25 08:56 AM
Hi everyone,
Hope all is well. I am trying to setup a basic SPI demo for the STM32H753ZI using the nucleo H753ZI just seeing if I can output my test word onto the MOSI line.
The conditions in my SPI demo is as follows:
The issues I am seeing is that My SPI demo and STs theres no data on the MOSI line additional to that the CLK is behaving super weird in my SPI demo. You can see boths STs and My SPI demo down below from the logic anayalzer
void initSPI() {
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOA);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOB);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);
LL_GPIO_InitTypeDef LL_GPIO;
LL_SPI_InitTypeDef LL_SPI1;
LL_SPI_InitTypeDef LL_SPI2;
LL_GPIO_StructInit(&LL_GPIO);
LL_SPI_StructInit(&LL_SPI1);
LL_SPI_StructInit(&LL_SPI2);
// Setting up SPI 1 GPIO
LL_GPIO.Alternate = LL_GPIO_AF_5;
LL_GPIO.Mode = LL_GPIO_MODE_ALTERNATE;
LL_GPIO.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO.Pin = LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
LL_GPIO.Pull = LL_GPIO_PULL_NO;
LL_GPIO.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
LL_GPIO_Init(GPIOA, &LL_GPIO);
// Setting up SPI 1 GPIO
LL_GPIO.Alternate = 0x00;
LL_GPIO.Mode = LL_GPIO_MODE_OUTPUT;
LL_GPIO.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO.Pin = LL_GPIO_PIN_4;
LL_GPIO.Pull = LL_GPIO_PULL_UP;
LL_GPIO.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
LL_GPIO_Init(GPIOA, &LL_GPIO);
// Setting up SP1 1 Peri
LL_SPI1.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV256;
LL_SPI1.BitOrder = LL_SPI_MSB_FIRST;
LL_SPI1.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
LL_SPI1.CRCPoly = 0x00;
LL_SPI1.ClockPhase = LL_SPI_PHASE_2EDGE;
LL_SPI1.ClockPolarity = LL_SPI_POLARITY_LOW;
LL_SPI1.DataWidth = LL_SPI_DATAWIDTH_8BIT;
LL_SPI1.Mode = LL_SPI_MODE_MASTER;
LL_SPI1.NSS = LL_SPI_NSS_SOFT;
LL_SPI1.TransferDirection = LL_SPI_FULL_DUPLEX;
LL_SPI_Init(SPI1, &LL_SPI1);
LL_SPI_EnableGPIOControl(SPI1);
}
int main(void)
{
char word = 'H';
HAL_Init();
SystemClock_Config();
initSPI();
LL_SPI_SetTransferSize(SPI1, 1);
GPIOA->BSRR |= (1 << 4); //Sets the SS line HIGH
LL_SPI_Enable(SPI1);
LL_SPI_StartMasterTransfer(SPI1);
GPIOA->BSRR |= (1 << 20); //Sets the SS line LOW
while(LL_SPI_IsActiveFlag_TXP(SPI1) == 0){};
SPI1->TXDR = (uint8_t)word;
while(LL_SPI_IsActiveFlag_EOT(SPI1) == 0){};
GPIOA->BSRR |= (1 << 4); //Sets the SS line HIGH
LL_SPI_Disable(SPI1);
while (1)
{
}
}
My SPI Demo
STs SPI Demo
Any help would be appericiated, super stumped as to why its not behaving as it should.
Solved! Go to Solution.
2023-01-25 02:24 PM
Hi @Community member, I got it working it was due to the Nucleo reserving PIN PA7 for ethernet. Just swapped onto SPI2 and now I am seeing data on the MOSI line.
2023-01-25 09:39 AM
Compare your code with LL example in firmware repo STM32CubeH7/Projects/NUCLEO-H743ZI/Examples_LL/SPI/SPI_FullDuplex_ComIT at master · STMicroelectronics/STM32CubeH7 · GitHub
2023-01-25 09:53 AM
Took your advice, added in any difference and still the samething, nothing output on the MOSI line and SCLK still acting funky.
2023-01-25 01:42 PM
SPI1->TXDR is 32 bits,
*((volatile uint8_t *)&SPI1->TXDR) = byte_0; // 8-bit transaction on the data bus
as said by Tesla DeLorean:
https://community.st.com/s/question/0D53W00000kuqp9SAA/h7-migration-send-spi-without-using-hal
2023-01-25 01:48 PM
Isn't there a LL function for this?
like:
__STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)
{
*((__IO uint8_t *)&SPIx->DR) = TxData;
}
2023-01-25 02:24 PM
Hi @Community member, I got it working it was due to the Nucleo reserving PIN PA7 for ethernet. Just swapped onto SPI2 and now I am seeing data on the MOSI line.