2022-01-06 06:15 AM
Hello, ı m use stm32h750vb, I'm trying to use spi half duplex_tx in slave mode, When I transmit for the first time, it sends data, but then it does not. When I checked the registers, the udr flag seems to be set. Why is the Udr Flag 1?(I'm sending 16 pulses per second over the clock systict timer.
static void MX_SPI3_Init(void)
{
/* USER CODE BEGIN SPI3_Init 0 */
/* USER CODE END SPI3_Init 0 */
LL_SPI_InitTypeDef SPI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
LL_RCC_SetSPIClockSource(LL_RCC_SPI123_CLKSOURCE_PLL2P);
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3);
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOC);
/**SPI3 GPIO Configuration
PC10 ------> SPI3_SCK
PC11 ------> SPI3_MISO
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_10|LL_GPIO_PIN_11;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/* USER CODE BEGIN SPI3_Init 1 */
/* USER CODE END SPI3_Init 1 */
/* SPI3 parameter configuration*/
SPI_InitStruct.TransferDirection = LL_SPI_HALF_DUPLEX_TX;
SPI_InitStruct.Mode = LL_SPI_MODE_SLAVE;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_16BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
SPI_InitStruct.CRCPoly = 0x0;
LL_SPI_Init(SPI3, &SPI_InitStruct);
LL_SPI_SetStandard(SPI3, LL_SPI_PROTOCOL_MOTOROLA);
LL_SPI_DisableNSSPulseMgt(SPI3);
/* USER CODE BEGIN SPI3_Init 2 */
/* USER CODE END SPI3_Init 2 */
}
/* USER CODE BEGIN 0 */
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
/* USER CODE BEGIN SysTick_IRQn 1 */
if(count<=32)
{
LL_GPIO_TogglePin(GPIOB, LL_GPIO_PIN_10);
}
else if(count==100000)//100000
{
count=0;
}
else
{
LL_GPIO_ResetOutputPin(GPIOB, LL_GPIO_PIN_10);
}
/* USER CODE END SysTick_IRQn 1 */
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
LL_APB4_GRP1_EnableClock(LL_APB4_GRP1_PERIPH_SYSCFG);
NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),15, 0));
SystemClock_Config();
PeriphCommonClock_Config();
MX_GPIO_Init();
MX_SPI3_Init();
LL_SPI_Enable(SPI3);
SysTick_Config(SystemCoreClock/100000);
while (1)
{
if(LL_SPI_IsActiveFlag_TXP(SPI3))
{
LL_SPI_TransmitData16(SPI3,0x2AAA);
}
}
}
)
2022-01-06 06:54 AM
An UDR flag means the master clocked the SCK line before you were able to send data to the SPI peripheral. Perhaps your master is using a high clock rate and asking for data quicker than you can keep up.
Once UDR is set, you need to clear it before continuing.
2024-12-02 07:13 PM
Does this mean the master would send data on MOSI, stop clk and disable CS/SS, wait a duration of time, enable CS/SS, and then read on MISO?