cancel
Showing results for 
Search instead for 
Did you mean: 

H723 Cubemax:SPI cannot recieve data

begall
Associate II

  I has been devloping an ECG program with ADS1292R and STM32H723VGT6.I has been struggling with a problem.

The ADS1292R uses SPI and it's register can be read if I use STM32C8T6 which configuerd by libray finction.But when I configuer program with H723,the question is coming-----my H723 can't read the registers of H723.I've checked  the datasheet of ADS1292R over an over again,and also asked TI support for help, I can promise that there are no faluts about the configuration of ADS1292.So the problem must be in the configuration of SPI.After debugging ,I noticed that the receive cache has been empty when I tried to read the registers of my SPI device.I really don't know why,it seemed that there wasn't changes of SCLK's wave when the command coming.I've enable the spi but it was useless.I really can't undersantand and don't know where the errors being.Plead help me and check my code.

begall_0-1708768046408.png

begall_1-1708768087740.png

 

 

void MX_SPI4_Init(void)
{

  /* USER CODE BEGIN SPI4_Init 0 */

  /* USER CODE END SPI4_Init 0 */

  /* USER CODE BEGIN SPI4_Init 1 */

  /* USER CODE END SPI4_Init 1 */
  hspi4.Instance = SPI4;
  hspi4.Init.Mode = SPI_MODE_MASTER;
  hspi4.Init.Direction = SPI_DIRECTION_2LINES;
  hspi4.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi4.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi4.Init.NSS = SPI_NSS_SOFT;
  hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
  hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi4.Init.CRCPolynomial = 0x0;
  hspi4.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  hspi4.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  hspi4.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
  hspi4.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi4.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi4.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  hspi4.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  hspi4.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  hspi4.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
  hspi4.Init.IOSwap = SPI_IO_SWAP_DISABLE;
  if (HAL_SPI_Init(&hspi4) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI4_Init 2 */

  /* USER CODE END SPI4_Init 2 */

}

 

 

 

7 REPLIES 7
Andrew Neil
Evangelist

You haven't shown the code that (tries to) do the reading, or the schematic of how the STM32 is connected to the ADS1292R.

What activity are you seeing on the SPI bus?

begall
Associate II
uint8_t SPI2_ReadWriteByte(uint8_t TxData)
{		
	uint8_t retry=0;
	uint8_t RxData=0;	
	while (__HAL_SPI_GET_FLAG(&hspi4, SPI_FLAG_TXE) == RESET) //检查指定的SPI标志位设置与否:发送缓存空标志位
		{
		retry++;
			printf("1111 device_id value: 0x%02X\r\n", RxData);
		if(retry>200)return 0;
		}			  
	HAL_SPI_Transmit(&hspi4, &TxData, 1, HAL_MAX_DELAY); //通过外设SPIx发送一个数据
	retry=0;

	while (__HAL_SPI_GET_FLAG(&hspi4, SPI_FLAG_RXNE) == RESET) //检查指定的SPI标志位设置与否:接受缓存非空标志位
		{
			//printf("1111 device_id value: 0x%02X\r\n", RxData);
			printf("SPI State: %d\n", hspi4.State);

		retry++;
		if(retry>200)return 0;
		}	  
	HAL_SPI_Receive(&hspi4, &RxData, 1, HAL_MAX_DELAY);
		//printf("1111 device_id value: 0x%02X\r\n", RxData);
		
	return RxData; //返回通过SPIx最近接收的数据					    
}  

this is my reading code.Because of the lacking of detectiving device,I opend an ADC channel to try to detect the SPI signal.I compared the SCLK's wave of C8T6 and H723,I found that when the command coming ,SCLK genertated a chaging (

begall_0-1708770541074.png

 

)but H723 still kept a line without changes.

Do you not have a scope with a screenshot facility?

no.maybe tommorrow i can get one scope to use

TDK
Guru

> I can promise that there are no faluts about the configuration of ADS1292

You're having problems, so let's not rule out things without showing evidence.

Your read/write byte code is probably not what you want. It's still unclear what you're trying to do with it. Use HAL_SPI_TransmitReceive to write and read a byte. To read a register, you send 2 bytes and read 2 bytes. Maybe that's what you are trying to do? Perhaps explain and show what you're trying to do with the chip and how you're using SPI2_ReadWriteByte.

The polling for TXE and RXNE is unnecessary. Use the HAL functions. There are SPI examples to go off of in the CubeMX repository.

 

To read a register, set up a transfer of 3+ bytes with HAL_SPI_TransmitReceive. Refer to the datasheet for the protocol you should be using.

TDK_0-1708783825366.png

 

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

@begall SPI in STM32H7 series is different from earlier lines. By the way, what is STM32C8T6?

For one, there is no SPI_FLAG_TXE (line 5 in your code snippet). Instead, H7 has SPI_FLAG_TXP.

You'll need to look at SPI program examples for STM32H7, provided in the CubeH7 library package, and figure out how to change your code to run on H7.

 

begall
Associate II

This is the code I read and write register

//读写多个寄存器
void ADS1292_WR_REGS(u8 reg,u8 len,u8 *data)
{
		u8 i;
		ADS_CS=0;	
		delay_us(1000);
		ADS1292_SPI(reg);
		delay_us(1000);
		ADS1292_SPI(len-1);
		if(reg&0x40) //写
		{
				for(i=0;i<len;i++)
				{
						delay_us(1000);		
						ADS1292_SPI(*data);
						data++;				
				}			
		}
		else //读		
		{
				for(i=0;i<len;i++)
				{
						delay_us(1000);		
						*data = ADS1292_SPI(0);
						data++;
				}
		}			
		delay_us(100);	
		ADS_CS=1;
}


//寄存器数组写入寄存器
u8 ADS1292_WRITE_REGBUFF(void)
{
		u8 i,res=0;
		u8 REG_Cache[12];	//存储寄存器数据
		ADS1292_SET_REGBUFF();//设置寄存器数组		
		ADS1292_WR_REGS(WREG|CONFIG1,11,ADS1292_REG+1);//数组变量写入寄存器
		delay_ms(10);		
		ADS1292_WR_REGS(RREG|ID,12,REG_Cache);//读寄存器
		delay_ms(10);	
		
		for(i=0;i<12;i++	)	//检查寄存器	
		{			
				printf("Write: 0x%02X, Read: 0x%02X\r\n", ADS1292_REG[i], REG_Cache[i]);
				if(ADS1292_REG[i] != REG_Cache[i])
				{
						if(i!= 0 && i!=8 && i != 11)	//0 8 和11是ID 导联脱落和GPIO相关
								res=1;
						else
								continue;
				}					
		}	

		return res;				
}

you can see that there 3+ bytes are  transferred when I write or read registers.The problem exists in the ADS1292_SPI(0),

u8 ADS1292_SPI(u8 com)
{	
		return SPI2_ReadWriteByte(com);
}
uint8_t SPI2_ReadWriteByte(uint8_t TxData)
{		
	uint8_t Rxdata;
  HAL_SPI_TransmitReceive(&hspi4,&TxData,&Rxdata,1, 1000);       
 	return Rxdata;          		    //返回收到的数据			    
}  

the data I recieved is always 0,which means I didn't receive the data which is read form register