1
\$\begingroup\$

When I first used the PCAP04 chip for measuring capacitance, I felt very annoyed, because the information on this chip was really a bit garbage. Many things are not found in the official manuals, and few people use them. The examples that can be found online are also limited.

This chip is to evaluate my capacitance sensor and output digitally.

This method is- configure the various parameters to be used on the software of the official development board , then export the data, and then write these data to the chip of our own board. What DSP, firmware library, there are all here, what register configuration, all are configured for you.

I have now set all the configuration registers. But I cannot start a single measurement with my chip with the following code:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "PCAP_04.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
I2C_HandleTypeDef hi2c1;

UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */
//const uint8_t PCap04_standard_config_reg[] = {
//
//        0x12,0x00,0xA8,   // Config Register  0,  1,  2, -> 0 = 100kHz low Frequency Oscillator | 2 = 30kOhm for PC4-PC5 (Sensor) and PC0-PC3 (Reference Capacitor)
//        0x00,0x21,0x00,   // Config Register  3,  4,  5, -> 4 = Compensation mechanism and select floating sensors
//        0x33,0x03,0x00,   // Config Register  6,  7,  8, -> 6 = CDC Ports Enable (PC0, PC1, PC4, PC5) | 7 = Sample Size [3]
//        0x88,0x13,0x00,   // Config Register  9, 10, 11, -> 9 & 10 = 5000 (100ms Conversion)
//        0x0A,0x18,0x0A,   // Config Register 12, 13, 14, -> 12 = Discharge Time 10 us | 13 = OP-Code triggered
//        0x08,0x0A,0x00,   // Config Register 15, 16, 17, -> 15 = Precharge Time 10 us and 2 fake dummys
//        0x00,0x00,0x00,   // Config Register 18, 19, 20,
//        0x00,0x64,0xF0,   // Config Register 21, 22, 23, -> 22 = CDC Trigger synchronous and Sample Size (averaging) 4-fold | 23 = Enable PIN for PT1000 and REF_OHM
//        0x00,0x00,0x00,   // Config Register 24, 25, 26,
//        0x00,0x5A,0x00,   // Config Register 27, 28, 29, -> 28 = Watchdog has to be disabled
//        0x41,0x00,0x00,   // Config Register 30, 31, 32, -> 30 = INTN PG4 and DSP-Start by end of RDC
//        0x00,0x00,0x00,   // Config Register 33, 34, 35,
//        0x00,0x00,0x00,   // Config Register 36, 37, 38,
//        0x00,0x00,0x00,   // Config Register 39, 40, 41,
//        0x00,0x00,0x00,   // Config Register 42, 43, 44, -> 42 = Asynchronus mode (update the results after each successful read out by SIF)
//        0x00,0x00,0x00,   // Config Register 45, 46, 47,
//        0x00};            // Config Register 48


/*It already contains the firmware library and register configuration used by the PCAP04 chip*/
     uint8_t Pcap04_Firmware[] =
    {
            0x24,0x05,0xA0,0x01,0x20,0x55,0x42,0x5C,0x48,0xB1,0x07,0x92,0x02,0x20,0x13,0x02,
            0x20,0x93,0x02,0xB2,0x02,0x78,0x20,0x54,0xB3,0x06,0x91,0x00,0x7F,0x20,0x86,0x20,
            0x54,0xB6,0x03,0x72,0x62,0x20,0x54,0xB7,0x00,0x00,0x42,0x5C,0xA1,0x00,0x49,0xB0,
            0x00,0x49,0x40,0xAB,0x5D,0x92,0x1C,0x90,0x02,0x7F,0x20,0x86,0x66,0x67,0x76,0x77,
            0x66,0x7A,0xCF,0xCD,0xE6,0x43,0xF1,0x44,0x29,0xE0,0x7A,0xDC,0xE7,0x41,0x32,0xAA,
            0x01,0x99,0xFD,0x7B,0x01,0x7A,0xCF,0xEB,0xE6,0x43,0xF1,0x44,0x29,0xE0,0x7A,0xC1,
            0xE7,0x41,0x32,0x6A,0xDE,0x44,0x7A,0xCF,0xEA,0xE6,0x43,0xF1,0x44,0x29,0xE0,0x6A,
            0xDF,0x44,0x7A,0xC4,0xE7,0x41,0x32,0xAB,0x05,0x7A,0xC1,0xE1,0x43,0xE0,0x3A,0x7A,
            0xC0,0xE1,0x43,0xE0,0x3A,0x02,0x7A,0xCF,0xE6,0xE6,0x43,0xF1,0x44,0x29,0xE0,0x7A,
            0xEF,0x44,0x02,0x20,0x9D,0x84,0x01,0x21,0x2E,0x21,0x74,0x20,0x37,0xC8,0x7A,0xE7,
            0x43,0x49,0x11,0x6A,0xD4,0x44,0x7A,0xC1,0xD8,0xE6,0x43,0xE9,0x44,0x1C,0x43,0x13,
            0xAB,0x63,0x6A,0xDE,0x41,0xAB,0x0B,0x46,0x46,0x46,0x7A,0xDF,0xFF,0xFF,0xFF,0xFF,
            0xE3,0x41,0x32,0x1C,0x44,0xE9,0x13,0x6A,0xD4,0x13,0x41,0xAA,0xDF,0x7A,0xC5,0xE1,
            0x43,0x49,0xE0,0x34,0x7A,0xCF,0xE3,0xE6,0x43,0xF1,0x44,0x29,0xE0,0xDB,0xC0,0x27,
            0xE5,0x6A,0xDF,0x43,0x7A,0xC8,0xE7,0x41,0x30,0xAB,0x03,0x86,0x01,0x92,0x37,0x7A,
            0xC6,0xE7,0x41,0x7A,0xFA,0xE7,0x43,0xEA,0x44,0x7A,0xC1,0xE1,0xE6,0x43,0xE9,0x44,
            0x25,0xE0,0x7A,0xC6,0xE7,0x41,0x7A,0xFA,0xE7,0x43,0xEA,0x44,0x7A,0xC0,0xE7,0x43,
            0xE9,0x44,0x25,0xE0,0x92,0x10,0x7A,0xE1,0x44,0xE2,0x44,0xE3,0x44,0xE4,0x44,0xE5,
            0x44,0xE6,0x44,0xE7,0x44,0xE8,0x44,0xC1,0xD8,0x24,0x3E,0x92,0xFF,0x02,0x7A,0xCF,
            0xD7,0xE6,0x43,0xF1,0x44,0x7A,0xD0,0xE7,0x43,0x2A,0x2A,0x32,0xAB,0x03,0x42,0x5C,
            0x92,0x03,0x7A,0xC0,0xE1,0x43,0xD9,0x27,0x90,0x6A,0xDF,0x43,0x7A,0xC8,0xE7,0x41,
            0x32,0xAB,0x03,0x86,0x01,0x92,0x11,0x7A,0xC2,0x43,0x7A,0xE7,0x44,0x6A,0xC6,0x44,
            0x7A,0xC3,0x43,0x7A,0xE8,0x44,0x6A,0xC7,0x44,0xC1,0xD4,0x24,0x57,0x7A,0xC8,0xE1,
            0x43,0xE0,0x3A,0x02,0x7A,0xCF,0xE7,0xE6,0x43,0xF1,0x44,0x29,0xE0,0x7A,0xC7,0xE1,
            0x41,0x6A,0xD4,0x45,0x5A,0x25,0x36,0x46,0x46,0x46,0x46,0x7A,0xE9,0x44,0x7A,0xC0,
            0xE7,0x43,0x55,0x7A,0xEA,0x45,0x7A,0xE9,0x51,0x1C,0x43,0x6A,0xCA,0x44,0x1D,0x43,
            0x6A,0xCB,0x44,0x7A,0xC1,0xCA,0xE6,0x43,0xE9,0x44,0x7A,0xC1,0xE1,0x43,0x7A,0xCC,
            0xE0,0xE6,0x41,0x2C,0x42,0x7A,0xC5,0xE1,0x43,0x49,0xE0,0x34,0x7A,0xC1,0xCC,0xE6,
            0x43,0xE9,0x44,0x7A,0xC1,0xE1,0x43,0x2C,0x70,0x7A,0xCC,0x43,0x7A,0xCF,0x44,0x7A,
            0xCD,0x43,0x7A,0xCE,0x44,0x6A,0xCA,0x43,0xC1,0xCA,0x7A,0xE6,0x41,0xE9,0x45,0x2B,
            0xAE,0xEE,0x44,0x7A,0xC1,0xCA,0xE6,0x43,0xE9,0x44,0x7A,0xC1,0xE1,0x43,0x7A,0xCC,
            0xEC,0xE6,0x41,0x2C,0x42,0x7A,0xC5,0xE1,0x43,0x49,0xE0,0x34,0x7A,0xC1,0xCC,0xE6,
            0x43,0xE9,0x44,0x7A,0xC1,0xE1,0x43,0x2C,0x70,0x7A,0xCC,0x43,0x7A,0xCF,0x44,0x7A,
            0xCD,0x43,0x7A,0xCE,0x44,0x6A,0xCB,0x43,0xC1,0xCA,0x7A,0xE6,0x41,0xE9,0x45,0x2B,
            0xAE,0xED,0x44,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x35,0x33,0x33,0x07,0xCD,0xCC,0xCC,0x08,0x01,0x00,0xFE,0x03,0x66,0x66,0x66,0x01,
            0x33,0x33,0x33,0x02,0x01,0x00,0xFE,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
            0x1D,0x00,0x08,0x10,0x11,0x00,0x03,0x20,0x00,0xF4,0x01,0x00,0x00,0x08,0xFF,0x03,
            0x00,0x24,0x00,0x00,0x00,0x01,0x50,0x30,0x73,0x04,0x50,0x08,0x5A,0x00,0x44,0x08,
            0x08,0x00,0x47,0x40,0x00,0x00,0x00,0x71,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x01,
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    };



/* Variables for communication with EXTI0 */
//volatile uint8_t DataIn[4];
//volatile bool FlagDataReady=false;

/* Variables for main */
uint8_t TestData; //Dummy variable
uint8_t BufTX[50]; //Buffer for send
uint8_t BufRX[50]; //Buffer for receive

//uint16_t MemAddressWrite = 0xA3C0;
//uint16_t MemAddressRead = 0x23C0;

volatile HAL_StatusTypeDef Status;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_I2C1_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */


/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
    volatile uint8_t PCAP04Status[3];

    /*Set Array to 0*/
    for(int i=0; i<3; i++)
        PCAP04Status[i] = 0;


  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_I2C1_Init();
  /* USER CODE BEGIN 2 */


  /* Check I2C communication
   * Send 0x7E
   * If OK receive 0x11*/
  PCAP_ReceiveDummy((uint8_t)PCAP04_OP_TEST_READ, &TestData, 1);
  if(TestData == 0x11)
  {

        /* Disable watchdog first */
        Status = PCAP_DisableWatchdog();
        if(Status != HAL_OK)
            while(1); //Endless loop

        HAL_Delay(10);

        /* Send POR OP */
        Status = PCAP_SendOPCode(PCAP04_OP_POR);
        if(Status != HAL_OK)
            while(1); //Endless loop

        HAL_Delay(10);

        /*Initalize PCAP02*/
        Status = PCAP_SendOPCode(PCAP04_OP_INITIALIZE);
        if(Status != HAL_OK)
            while(1); //Endless loop

        HAL_Delay(10);

        /* Write Firmware */
        Status = PCAP_WriteConfig(0, Pcap04_Firmware,(uint8_t) sizeof(Pcap04_Firmware));
        if(Status != HAL_OK)
            while(1); //Endless loop

//      HAL_Delay(10);
//
//        /* Set Runbit to switch the frond-end and DSP */
//          ZeroBufu8(BufTX, sizeof BufTX);
//          BufTX[0] = 0x01;
//          Status = PCAP_WriteConfig(47, BufTX, 1);
//          if(Status != HAL_OK)
//              while(1); //Endless loop

          Status = PCAP_ReadResult(32, (uint8_t*) PCAP04Status, 3);
          if(Status != HAL_OK)
            while(1); //Endless loop

        HAL_Delay(10);

        /* Start CDC Measurement */
        PCAP_SendOPCode(PCAP04_OP_CDC_START_CONVERSION);

        HAL_Delay(100);

          Status = PCAP_ReadResult(32, (uint8_t*) PCAP04Status, 3);
          if(Status != HAL_OK)
            while(1); //Endless loop
  }
  else
  {
      while(1); //Endless loop
  }


//  /*n Clear Runbit to allow write config */
//    ZeroBufu8(BufTX, sizeof BufTX);
//    BufTX[0] = 0x00;
//    Status = PCAP_WriteConfig(47, BufTX, 1);
//    if(Status != HAL_OK)
//      while(1); //Edless loop



//  PCAP_SendOPCode(PCAP04_OP_RDC_START_CONVERSION);


//  /* Read config */
//  ZeroBufu8(BufRX, sizeof BufRX);
//  Status = PCAP_ReadConfig(0, BufRX, 1);
//    if(Status != HAL_OK)
//      while(1); //Endless loop


  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
//    /* Read config 1 Byte */
//      ZeroBufu8(BufRX, sizeof BufRX);
//      Status = PCAP_ReadConfig(0, BufRX, 1);
//      if(Status != HAL_OK)
//          while(1); //Endless loop
//    PCAP_SendOPCode(PCAP04_OP_CDC_START_CONVERSION);
//    HAL_Delay(1000);
//
//  /* Read config 48 Byte */
//  ZeroBufu8(BufRX, sizeof BufRX);
//  Status = PCAP_ReadConfig(0, BufRX, 48);
//  if(Status != HAL_OK)
//      while(1); //Endless loop
//
      /* Read status registers  */
      Status = PCAP_ReadResult(32, (uint8_t*) PCAP04Status, 3);
      if(Status != HAL_OK)
        while(1); //Endless loop

        HAL_Delay(1000);


  }
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

  /* USER CODE END 3 */
}

I have already read out the Status Register which is shown as followed enter image description here enter image description here

enter image description here

Can anyone help me with the chip I'm getting really desperate ._.

\$\endgroup\$
2
  • \$\begingroup\$ Include links to all datasheets including PCAP04. \$\endgroup\$ Feb 22, 2021 at 10:44
  • \$\begingroup\$ the information on this chip was really a bit garbage No it is not, it is a lot of information since it is a complex chip. Even an experienced engineer will need a couple of days to figure out how to work with this chip. You might want to ask for support from the chip's manufacturer. \$\endgroup\$ Feb 22, 2021 at 13:13

1 Answer 1

1
\$\begingroup\$

I use this sensor, it is complicated chip, but after lots of efforts it worked. I don't see in your code initialization of the configuration registers with the PCap04_standard_config_reg array. In addition I don't see in your code reading the 8 results registers - you are just reading the 3 status registers.

You must configure the CFG registers, I configured as follow:

uint8_t cfg_register[] =
{
/* 00-03 */ 0x1D , 0x00 , 0x58 ,0x10,
/* 04-07 */ 0x10 , 0x00 , 0x3F ,0x20,
/* 08-11 */ 0x00 , 0xD0 , 0x07 ,0x00,
/* 12-15 */ 0x00 , 0x08 , 0xFF ,0x03,
/* 16-19 */ 0x00 , 0x24 , 0x00 ,0x00,
/* 20-23 */ 0x00 , 0x01 , 0x50 ,0x30,
/* 24-27 */ 0x73 , 0x04 , 0x50 ,0x08,
/* 28-31 */ 0x5A , 0x00 , 0x82 ,0x08,
/* 32-35 */ 0x08 , 0x00 , 0x47 ,0x40,
/* 36-39 */ 0x00 , 0x00 , 0x00 ,0x71,
/* 40-43 */ 0x00 , 0x00 , 0x08 ,0x00,
/* 44-47 */ 0x00 , 0x00 , 0x00 ,0x01,
/* 48-51 */ 0x00 , 0x00 , 0x00 ,0x00
};

In addition, you must burn the NVRAM memory with the right file.

\$\endgroup\$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.