cancel
Showing results for 
Search instead for 
Did you mean: 

Clarifications regarding SPI transmission

skuma.8
Associate III

I was working on a MP3 DECODER called VS1003. during reading the registers either i can send and receive data at SPI bus separately like

 

 

uint16_t result;
	uint8_t temp = 0;
	vs1003_control_mode_on();
	delayMicroseconds(1); // tXCSS

	HAL_SPI_Transmit(&hspi2, &VS_READ_COMMAND, 1, HAL_MAX_DELAY); //command for read
	HAL_SPI_Transmit(&hspi2, &_reg, 1, HAL_MAX_DELAY); //register
	//READ DATA
	HAL_SPI_Receive(&hspi2, &temp, 1, HAL_MAX_DELAY);
	result = temp << 8;
	temp = 0;
	HAL_SPI_Receive(&hspi2, &temp, 1, HAL_MAX_DELAY);
	result |= temp;

 

 

or i can do it using the function transmitReceive like

 

 

	uint16_t result;
	uint8_t temp = 0;
	vs1003_control_mode_on();
	delayMicroseconds(1); // tXCSS

	uint8_t tx_data[] = { VS_READ_COMMAND, _reg };
	uint8_t rx_data[2] = { 0, 0 };
	HAL_SPI_TransmitReceive(&hspi2, tx_data, rx_data, 2, HAL_MAX_DELAY);
	result = (rx_data[0] <<  | rx_data[1];

 

 

ISSUE i am facing is while transmitting the data using separate transmit and receive function it is working fine, but while using transmitrReceive function, i am unable to read any data. 

Any suggestion would be highly appreceiable.

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

Well, SPI can be compared to a shift register: when one side is sent, the data in the buffer on the other side is shifted at the same time. So if your VS1003 does not yet contain the expected data in its own transmit register that you are currently requesting from the master with e.g. the command, TransmitReceive cannot produce anything meaningful.

Regards
/Peter

In order 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.

View solution in original post

1 REPLY 1
Peter BENSCH
ST Employee

Well, SPI can be compared to a shift register: when one side is sent, the data in the buffer on the other side is shifted at the same time. So if your VS1003 does not yet contain the expected data in its own transmit register that you are currently requesting from the master with e.g. the command, TransmitReceive cannot produce anything meaningful.

Regards
/Peter

In order 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.