2023-03-31 12:35 AM
Hello.
Transmission from the master in full-duplex mode is possible, but when transmitted from the slave, only the first character is not transmitted correctly.
The signal was misaligned for the first letter, what is the cause?
STM32G431 Nucleo
SPI2 settings
SPI3 settings
__IO uint8_t spi2Status = 0;
__IO uint8_t spi3Status = 0;
uint8_t spi2Buffer[12];
uint8_t spi3Buffer[12];
// This works.
memset( spi2Buffer, 0x00, sizeof(uint8_t) *12 );
memset( spi3Buffer, 0x00, sizeof(uint8_t) *12 );
sprintf( (char *)spi2Buffer, "STM32F401RE" );
HAL_SPI_Receive_IT(&hspi3, spi3Buffer, strlen((char const *) spi2Buffer));
HAL_SPI_Transmit_IT(&hspi2, spi2Buffer, strlen((char const *) spi2Buffer));
// This didn't work.
memset( spi2Buffer, 0x00, sizeof(uint8_t) *12 );
memset( spi3Buffer, 0x00, sizeof(uint8_t) *12 );
sprintf( (char *)spi3Buffer, "STM32F401RE" );
HAL_SPI_Receive_IT(&hspi2, spi2Buffer, strlen((char const *) spi3Buffer));
HAL_SPI_Transmit_IT(&hspi3, spi3Buffer, strlen((char const *) spi3Buffer));
result when sent from SPI2
result when sent from SPI3
result when sent from SPI2
orange: NSS
yellow: Clock
green: MOSI
result when sent from SPI3
green: MISO
Thank you for your response.
Solved! Go to Solution.
2023-04-03 02:58 AM
Try this:
memset( spi2Buffer, 0x00, sizeof(uint8_t) *12 );
memset( spi3Buffer, 0x00, sizeof(uint8_t) *12 );
sprintf( (char *)spi3Buffer, "STM32F401RE" );
HAL_SPI_Transmit_IT(&hspi3, spi3Buffer, strlen((char const *) spi3Buffer));
HAL_SPI_Receive_IT(&hspi2, spi2Buffer, strlen((char const *) spi3Buffer));
ie. start slave Tx *before* master's Rx.
JW
2023-03-31 02:13 AM
Hello @TKawa.9,
just a general advice, you are using strlen() to determine the length of the data to be transmitted/received...
To ensure that the correct number of bytes are transmitted/received, you should use a variable to store the length of the data, rather than relying on strlen().
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-04-02 10:59 PM
a
2023-04-02 11:03 PM
Thank you for your reply.
>To ensure that the correct number of bytes are transmitted/received, you should use a variable to store the length of the data, rather than relying on strlen().
I will do that next time.
Is there any possible cause for the problem that only the first character sent from the slave to the master has the data bits out of alignment?
Transmission from the master to the slave is working.
2023-04-03 12:49 AM
just guessing:
(in your diagram orange = NSS -- right?)
nss active level is same as "idle" , not active. this could create one transistion in beginning of transfer, so you get 1bit shift wrong.
set in cube: spi .. parameter :
and maybe to try: at slave : set pullup on nss, pulldown on data+clk. test...
2023-04-03 02:58 AM
Try this:
memset( spi2Buffer, 0x00, sizeof(uint8_t) *12 );
memset( spi3Buffer, 0x00, sizeof(uint8_t) *12 );
sprintf( (char *)spi3Buffer, "STM32F401RE" );
HAL_SPI_Transmit_IT(&hspi3, spi3Buffer, strlen((char const *) spi3Buffer));
HAL_SPI_Receive_IT(&hspi2, spi2Buffer, strlen((char const *) spi3Buffer));
ie. start slave Tx *before* master's Rx.
JW
2023-04-03 08:19 PM
Thank you for your help.
I made the changes as advised by waclawek.jan and it solved the problem.
2023-04-03 09:53 PM
It worked fine.
Thank you very much.
But HAL_SPI_TxCpltCallback() is not called.
HAL_SPI_RxCpltCallback() is called and the send should be working as well since the received contents are stored exactly in spi2Buffer.
Please let me know if you know what the cause is.
2023-04-04 03:31 AM
I don't know why HAL_SPI_TxCpltCallback() is not called, I don't use Cube, sorry.
JW