2019-09-09 12:34 AM
2019-09-09 12:35 AM
I'm not able to establish the communication (unable to read default reg value). Please help me in programming section as soon as possible.
2019-09-09 03:21 AM
Don't see any pin connectivity described, don't see any software.
2019-09-09 03:29 AM
sorry, I didn't get you.
2019-09-09 03:50 AM
You make several assertions and statements, but provide no actionable detail. Present your problem more effectively.
2019-09-09 04:48 AM
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,®_w,1,1); //set MSB
HAL_Delay(5); //5milli second delay.
HAL_SPI_Transmit(& hspi1,®,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
2019-09-09 05:21 AM
i missed 1line of code i.e
HAL_SPI_Transmit(& hspi1,®_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)
2019-09-10 03:08 AM
@Community member waiting for your replay sir.
2019-09-10 08:33 AM
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.
2019-09-10 09:12 AM
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.