cancel
Showing results for 
Search instead for 
Did you mean: 

SPI problem in STM32F446 NUCLEO

mrkayaalp
Associate III

Hello everyone im currently working on a adc AD7708. I want to read chip from the device but i cant get any valid value. Here is the register sturucture of AD7708:

mrkayaalp_0-1707326670954.png

I wrote a basic code to read the chip id from id register. Here is the code:

 

 

 

 

 

  while (1)
  {
	    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 0);
	    status = HAL_SPI_Transmit(&hspi1, txdata, 1, 500);
	    while (hspi1.State != HAL_SPI_STATE_READY)1;

	    status = HAL_SPI_Receive(&hspi1, rxdata, 1, 500);
	    while (hspi1.State != HAL_SPI_STATE_READY);
	    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 1);

	    HAL_Delay(10);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

 

 

 

 

 

I examined it with the scope and i think there is no problem in MOSI line. But i cant see any signal in MISO line.  Here is my spi settings in stm32cubeide.

mrkayaalp_1-1707327149557.png

I couldn't find the problem. What should i do?

19 REPLIES 19

>After that in while loop first im sending 79 value ('01001111'accesing id_reg in read mode) and then next 8 bit value will be the readded value

-- But you do only 1 byte transfer...so how you ever should get " then next 8 bit value" ?

+ make the arrays a little bigger, it cost not too much.  xxdata[8] - or so. you dont want to overwrite any code, when using 3 or 4 byte sequence, to get adc bytes received

-> Just as i understand this adc:   (always HAL_SPI_TransmitReceive( ..) tx , rx byte. now 2-byte sequence )

1. tx 0x4F , rx (no use)

2. tx 0x80 , rx = id-reg data

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

-- But you do only 1 byte transfer...so how you ever should get " then next 8 bit value" ?

Yes i noticed that after i posted and then i fixed it. 

status = HAL_SPI_TransmitReceive(&hspi1, txdata, rxdata, 2, 250)

But there was no change in results. Thank you for your advices btw. But idk what else to try.

Did you try (my) sequence ?

    txdata[0] = 0x4F; //read operation from id register (im setting the comm register)
    txdata[1] = 0x80;  //dummy data for response

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 0);
	    status = HAL_SPI_TransmitReceive(&hspi1, txdata, rxdata, 2, 25)
If you feel a post has answered your question, please click "Accept as Solution".

yes i did now. The code looks like this:

  /* USER CODE BEGIN 2 */
  	uint8_t txdata[2];
    uint8_t rxdata[2] = {0x00, 0x00};
    HAL_StatusTypeDef status;
    //first byte setting up the comm register.
    //second byte writing to the mode register
    txdata[0] = 0x01;
    txdata[1] = 0x12;

    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 0);
    status = HAL_SPI_TransmitReceive(&hspi1, txdata, rxdata, 2, 250);
    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 1);

    txdata[0] = 0x4f; //read operation from id register (im setting the comm register)
    txdata[1] = 0x80;  //dummy data for response

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 0);
	    status = HAL_SPI_TransmitReceive(&hspi1, txdata, rxdata, 2, 250); //rxdata[1] will be my chip id register value
	    HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, 1);

	    HAL_Delay(10);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

The result:

mrkayaalp_0-1707393558502.png

rxdata[1] is still 0. Is there somehing else that i should try?

hmmm...

Hardware is like this : avdd, dvdd = 3,3V ?

AScha3_0-1707395695331.png

+ look with scope on the lines...mosi , miso ...see something?

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

vdd's = 5v and my CS pin connected to my mcu (STM32f446RET6 Nucleo). I have already look looked with scope and i can see my MOSI (0b01001111) as i send it. But there is no signal in MISO line only small fluctuations. 

STM32 is a 3,3V system, so use also 3v3 on DVDD or both vdd's on ADC.

+ reset ? 32k crystal running ? whats on refin+ ?

AScha3_0-1707398132013.png

 

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

mrkayaalp_0-1707399049585.png

Here is the schematic

ok .

+

STM32 is a 3,3V system, so use also 3v3 on DVDD.

32k crystal running ?

C9 /10 = ?

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

yes 32k crystal is running. c9 and c10 22pF.