Acknowledgement condition Added

This commit is contained in:
Manticore 2025-03-20 17:57:44 +05:30
parent d4c252889e
commit 3eae88f16f

View File

@ -15,6 +15,8 @@
#define RXD_PIN GPIO_NUM_16 // RX pin for MCP39F501
#define BUF_SIZE 256 // UART buffer size
#define ACK 6U
static const char *TAG = "MCP39F501";
// Initialize UART
@ -55,7 +57,8 @@ uint32_t read_vrms() {
vTaskDelay(pdMS_TO_TICKS(100));
int len = uart_receive_response(response, sizeof(response));
if (len > 0 ) {
// if (len > 0 ) {
if (response[0] == ACK ) {
vrms_value = (response[2] << 8) | response[3]; // Extract VRMS value
// ESP_LOGI(TAG, "VRMS: %lu", vrms_value);
} else {
@ -75,7 +78,9 @@ uint32_t read_active_power() {
vTaskDelay(pdMS_TO_TICKS(50));
int len = uart_receive_response(response, sizeof(response));
if (len >= 7) {
// if (len > 0 ) {
if (response[0] == ACK ) {
power_value = (response[2] << 24) | (response[3] << 16) | (response[4] << 8) | response[5]; // Extract Power
// ESP_LOGI(TAG, "Active Power: %lu", power_value);
} else {
@ -96,7 +101,8 @@ uint32_t read_current()
vTaskDelay(pdMS_TO_TICKS(50));
int len = uart_receive_response(response, sizeof(response));
if (len >= 7) {
// if (len > 0 ) {
if (response[0] == ACK ) {
current_value = (response[2] << 24) | (response[3] << 16) | (response[4] << 8) | response[5]; // Extract Power
// ESP_LOGI(TAG, "Active Power: %lu", current_value);
} else {
@ -119,7 +125,8 @@ uint32_t read_power_factor(){
vTaskDelay(pdMS_TO_TICKS(50));
int len = uart_receive_response(response, sizeof(response));
if (len > 0) {
// if (len > 0 ) {
if (response[0] == ACK ) {
power_factor = ((response[2] << 8) | response[3]); // Extract Power
// ESP_LOGI(TAG, "====>>> Power Factor: 0x%0X", (unsigned int) power_factor);
} else {
@ -146,7 +153,8 @@ uint32_t reactive_power(){
ESP_LOGI(TAG, "Active Power length : %d", len);
if (len > 0 ) {
// if (len > 0 ) {
if (response[0] == ACK ) {
r_power_value = (response[2] << 24) | (response[3] << 16) | (response[4] << 8) | response[5]; // Extract Power
// ESP_LOGI(TAG, "Active Power: %lu", current_value);
} else {