cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure USART for 9bit SPI Master

Matt Barclay
Associate

I'm using CubeMX to configure my STM32F413. I need 9-bit SPI, so I'm using the USART2.

CubeMX is initializing the USART like this:

/* USART2 init function */
 
static void MX_USART2_Init(void)
 
{
 
 
 husart2.Instance = USART2;
 
 husart2.Init.BaudRate = 100000;
 
 husart2.Init.WordLength = USART_WORDLENGTH_9B;
 
 husart2.Init.StopBits = USART_STOPBITS_1;
 
 husart2.Init.Parity = USART_PARITY_NONE;
 
 husart2.Init.Mode = USART_MODE_TX;
 
 husart2.Init.CLKPolarity = USART_POLARITY_HIGH;
 
 husart2.Init.CLKPhase = USART_PHASE_1EDGE;
 
 husart2.Init.CLKLastBit = USART_LASTBIT_DISABLE;
 
 if (HAL_USART_Init(&husart2) != HAL_OK)
 
 {
 
   _Error_Handler(__FILE__, __LINE__);
 
 }
 
 
}

I've tried every combination of Polarity, Phase, and "Clock Last Bit".

The problem I'm seeing is that the is driven out before the clock starts running. It's approximately one clock cycle ahead of the clock:

0690X000006BviwQAC.png

How do I configure the USART2 for 9-bit SPI Master?

Thanks,

Matt

0 REPLIES 0