AnsweredAssumed Answered

SPI Receive problem

Question asked by hashem ahmadi on Jun 27, 2017
Latest reply on Jul 6, 2017 by Mathew Hystek

Hi all,

 

I am trying to read a four bytes register from TDC-GP30 ultrasonic flow converter using HAL_SPI_Receive function. Below is the code that I am using for reading the register contents:

 

/*******************************************************************************
* Function Name: gp30_read_n_bytes
* Parameters: n_bytes = how many bytes should be read
* read_opcode = read opcode of the device
* read_addr = read address of the device
*
* Return: n bytes from the specified read address
*
* Description: Reads n bytes from an address in GP30
*
******************************************************************************/
float gp30_read_4_bytes(uint8_t read_opcode, uint8_t read_addr)
{
uint32_t Result_read = 0x00000000;
uint8_t Result_read_buff = 0x00;

GP30_SPI_enable();

HAL_SPI_Transmit(&hspi1,&read_opcode,1,100);
HAL_SPI_Transmit(&hspi1,&read_addr,1,100);


HAL_SPI_Receive(&hspi1,&Result_read_buff,1,100);
Result_read |= (Result_read_buff<<24);

HAL_SPI_Receive(&hspi1,&Result_read_buff,1,100);
Result_read |= (Result_read_buff<<16);

HAL_SPI_Receive(&hspi1,&Result_read_buff,1,100);
Result_read |= (Result_read_buff<<8);

HAL_SPI_Receive(&hspi1,&Result_read_buff,1,100);
Result_read |= (Result_read_buff);

GP30_SPI_disable();

return Result_read;
}

 

The problem is that I cannot receive all four bytes. For example one register contains 0x12345678 and when I read its content I receive 0x12345600 all the time. Its receiving fine for some other values but not for all values.

Outcomes