Skip to main content
DKuma.10
Associate
September 9, 2019
Question

I'm trying to interface my STM32F103C6 with ADE7753, So anyone can help me regarding this. I have made the hardware connection correctly but stuck with programming..

  • September 9, 2019
  • 9 replies
  • 3648 views

..

This topic has been closed for replies.

9 replies

DKuma.10
DKuma.10Author
Associate
September 9, 2019

I'm not able to establish the communication (unable to read default reg value). Please help me in programming section as soon as possible. 

Tesla DeLorean
Guru
September 9, 2019

Don't see any pin connectivity described, ​don't see any software.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DKuma.10
DKuma.10Author
Associate
September 9, 2019

sorry, I didn't get you.

Tesla DeLorean
Guru
September 9, 2019

You make several assertions and statements, but provide no actionable detail. Present your problem more effectively.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DKuma.10
DKuma.10Author
Associate
September 9, 2019

You can find my circuit connection attached below.

This code below is just to establish communication between stm32f103c8 and ADE7753 by reading its reg default value in CUBE IDE.

In Clock configuration-36Mhz APB2 peripheral clock.

in SPI-CPOL=high, CPOH=2edge.........Prescaller=64(please describe this)

thank you in advance.

#include "main.h"

#include "spi.h" //SPI1

#include "usart.h" //UART1

#include "gpio.h"

#include <string.h> //using strlen function

void SystemClock_Config(void);

int main(void)

{

void uprintf(char* str) {

HAL_UART_Transmit(&huart1, (uint8_t *) str, strlen(str), 100); //

}

char buffer[32];

uint8_t reg_r=0x00; // 0x00 is for read operation.

uint8_t reg_w=0x80; // For write operation

uint8_t reg = 0x1E; //register address to read its default value.

uint8_t V1; //to store the incomming data from ADE7753

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_SPI1_Init();

 MX_USART1_UART_Init(); //UART used to transmit data to capture in PUTTY.

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // output low to CS

  HAL_Delay(2); //2 milli second delay.

    HAL_SPI_Transmit(& hspi1,&reg_w,1,1); //set MSB

    HAL_Delay(5); //5milli second delay.

    HAL_SPI_Transmit(& hspi1,&reg,1,1); //reg addr

    HAL_Delay(5); // 5milli second delay

 while (1)

 {

V1= HAL_SPI_Receive(& hspi1,&V1,1,1); //receive data on V1 variable.

    sprintf(buffer, "VRMS:%d\r\n",V1); // for UART data transmit.

  uprintf(buffer);

  HAL_Delay(500);

  HAL_GPIO_TogglePin (GPIOC, GPIO_PIN_13); //led toggle.

  HAL_Delay(100);

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB busses clocks 

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)

 {

  Error_Handler();

 }

}

void Error_Handler(void)

{

}

#ifdef USE_FULL_ASSERT

void assert_failed(uint8_t *file, uint32_t line)

}

#endif 

DKuma.10
DKuma.10Author
Associate
September 9, 2019

i missed 1line of code i.e  

HAL_SPI_Transmit(& hspi1,&reg_r,1,1); //transmit 0x00 for read operation

  HAL_Delay(5); // 5milli second delay

This line of code I wrote just below after sending the address of register.(not in while loop)

DKuma.10
DKuma.10Author
Associate
September 10, 2019

@Community member​ waiting for your replay sir.

Tesla DeLorean
Guru
September 10, 2019

From my reading of the documentation, you're not sending the register/command properly.

https://www.analog.com/media/en/technical-documentation/data-sheets/ADE7753.pdf

I'd probably start by creating a simple register reading function, and pull out things like the DIEREV and CHECKSUM register, and confirm you can do that properly. Would probably use the chip select more frequently rather that dwell in an infinite loop.

Use a scope or analyzer to look at the signals on the wire, to confirm it matches the diagrams in the manual.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DKuma.10
DKuma.10Author
Associate
September 10, 2019

I read the data sheet before ,but i didn't understand what output i will get in DIEREV and CHECKSUM cause its undefined.

I checked my circuit with SPI connection,its working fine as im getting 2.4V in VREF pin in ADE7753.

I used CRO to check my signals, accept DOUT-MISO singnal, other signals looks fine. I will provide you the MISO output in CRO tommorow.

DKuma.10
DKuma.10Author
Associate
September 28, 2019

hello sir, now i'm able to get the values of IRMS and VRMS when i execute the program individually inside the while loop.

the problem here i face is when i try to get the values of IRMS and VRMS together , inside the while loop i get the correct reading with the incorrect values and so forth.

while (1) {

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

//voltage measurement

reg = reg_V|reg_r; //0x17|0x00

READ_24bit(reg); //function described below

V = (0.5 / 1551400.0 / sqrt(2)) * data * 476; //voltage calculation

sprintf(buffer1, "data=%ld, VRMS=%.2f \r\n", data, V); //uart

uprintf(buffer1);

HAL_Delay(10);

reg = reg_I|reg_r; //0x16|0x00

READ_24bit(reg); //function described below

I = (0.5 / 1868467.0 / sqrt(2)) * data / 10.0 * 1800; //current measurement

sprintf(buffer, " data=%ld,   IRMS=%.2f \r\n", data, I); //uart

uprintf(buffer);

HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);

HAL_Delay(100);

}

}

uint32_t READ_24bit(uint8_t reg) {

Slave_select();

data=0;

uint8_t data0=0, data1=0, data2=0;

DWT_Delay_us(10);

spi_transmit(reg); //transmit register value

DWT_Delay_us(25);

data0 = spi_transmit(0x00); //first 8 bit read operation

DWT_Delay_us(5);

data1 = spi_transmit(0x00); //second 8 bit read operation

DWT_Delay_us(5);

data2 = spi_transmit(0x00); //third 8 bit read operation

DWT_Delay_us(5);

Slave_deselect();

data = ((uint32_t) data0 << 16) | ((uint32_t) data1 << 8)| ((uint32_t) data2);

return data;

}

help me.

TDK
Super User
September 28, 2019

“i get the correct reading with the incorrect values and so forth�?

What the heck does that mean? If you want help on an internet forum, the better you lay our your problem the more helpful the responses can/will be.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DKuma.10
DKuma.10Author
Associate
September 29, 2019

answer me please.

Tesla DeLorean
Guru
September 29, 2019

I'm not able to debug this through a keyhole. You have code fragments, talking to a device I don't have, and no supporting data showing any of the registers, values read. intermediate computations. Your code outputs messages, don't see any of this output, or the data supporting it.

I don't seen any registers dumps, or scope output.

Best you work this out with your colleagues, and ST / Analog Devices support staff.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..