2024-02-07 09:36 AM
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:
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.
I couldn't find the problem. What should i do?
2024-02-08 03:01 AM - edited 2024-02-08 03:02 AM
>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
2024-02-08 03:12 AM
-- 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.
2024-02-08 03:38 AM
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)
2024-02-08 04:00 AM
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:
rxdata[1] is still 0. Is there somehing else that i should try?
2024-02-08 04:36 AM
hmmm...
Hardware is like this : avdd, dvdd = 3,3V ?
+ look with scope on the lines...mosi , miso ...see something?
2024-02-08 05:02 AM
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.
2024-02-08 05:11 AM - edited 2024-02-08 05:15 AM
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+ ?
2024-02-08 05:31 AM
Here is the schematic
2024-02-08 05:38 AM
ok .
+
STM32 is a 3,3V system, so use also 3v3 on DVDD.
32k crystal running ?
C9 /10 = ?
2024-02-08 08:04 AM
yes 32k crystal is running. c9 and c10 22pF.