cancel
Showing results for 
Search instead for 
Did you mean: 

Problem useing SPI together with UART as SPI

kirlik
Associate II

As soon as I add USART initialization, SPI starts sending data using LSB and receiving with MSB(as it was intended) bit order.

SPI init code:

/* SPI configuration */
  SPI_DeInit();
  /* Initialize SPI in Slave mode  */
//  SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW,
  SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW,
           SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_HARD,(uint8_t)0x07);
	SPI_ITConfig(SPI_IT_RXNE,ENABLE);
	SPI_ITConfig(SPI_IT_TXE,ENABLE);
	SPI_Cmd(ENABLE);

UART init code:

UART1_DeInit();
  
  UART1_Init((uint32_t)1000000, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, 
              (UART1_SyncMode_TypeDef)(UART1_SYNCMODE_CLOCK_ENABLE | UART1_SYNCMODE_CPOL_LOW |UART1_SYNCMODE_CPHA_MIDDLE |UART1_SYNCMODE_LASTBIT_ENABLE),
              UART1_MODE_TXRX_ENABLE);
							
	UART1->BRR2 &= (uint8_t)(~UART1_BRR2_DIVF); 
  UART1_Cmd(ENABLE);

3 REPLIES 3
WilkoL
Senior

What does the rest of the code look like? Initialization only doesn't seem to do anything, although I have never seen anyone using the USART as a SPI peripheral. And how are the USART and the SPI connected? To what?

The rest of the code is, in theory, not so important, as it works correctly until the UART is initialized.

In the end, I replaced UART as SPI with software SPI. However, I found a bug that led to this strange behavior. CS was not connected and, as a result, was constantly active(although this is not prohibited).

As for the task description, I make a "layer" between the sensor and another MCU. So I need to communicate with the sensor as the master and process requests from another microcontroller over the same protocol as the slave... Strange, but that's the task. =)

cihadkck
Associate II

"I am facing the similar issue too but i can monitorize data i send to motor driver."

I am using g431rb and sabertooth 2x32 to drive motors. UART handles communication between these two devicesbut i need to control LED Strip also and i am using SPI for that. I can control them seperately it is really easy but when i want to run motors and turn on the led strip in the same time, i cant drive the motors. They never move but i am monitoring data (which i sent to ride to motors) with arduino serialthrough application. i have to make them work together, I am also looking for solution for this problem.

Let me know if you have any question about my issue.