Debugging method of using new IC chip in single chip microcomputer project

Time:2021-9-11
Debugging method of using new IC chip in single chip microcomputer project

Two days ago, a friend asked me how to use a new IC chip. I took this opportunity to introduce a debugging method often used in my daily work to my friends, hoping to be helpful to you. The preparation is hasty, and there are inevitable technical errors in the text. You are welcome to correct and give good suggestions

preface:We often encounter the use of new IC chips in the project development of single chip microcomputer. A treasure seller sometimes can’t provide the corresponding development program, and can’t find information on the Internet; Many beginners are often helpless in the face of such problems. Here I introduce one of the new IC debugging methods I often use.

Because this chip is relatively simple, I use the following steps:


Step 1:First, use Arduino + bread board to quickly build the circuit to verify the function of the chip


Step 2:Use stm32cube ide to quickly build the project and verify whether it works normally on STM32


Tips:Since I don’t have a multimeter on hand, I use the analog voltage acquisition function of Arduino to print it out through the serial port as the voltage monitoring of the potentiometer.


First, let’s quickly browse the chip data manual to get important information

IC model:TPL0501


Voltage range:2.7~5.5V


Temperature range:-40~125℃


Communication mode:SPI


Resistance value:100KΩ


Resistance deviation:±20%

The chip is a single channel digital potentiometer of a state instrument. The communication mode is SPI bus and unidirectional, that is, it can only control the chip and can not read the input data. The following is the specific introduction of the data manual.


Environmental parameters:It mainly includes the temperature range, voltage range, error, temperature drift and the corresponding relationship of physical pins


Environmental parameters

Functional block diagram:This paper mainly introduces the internal composition and working principle of the chip

Functional block diagram

Pin definition:Function description of each pin


Pin definition

SPI communication Description:This paper mainly introduces the communication mode of the chip. Because the chip has no mode function, it only needs to write data directly to the chip. The communication mode is similar to that of the 74HC595 we use


SPI communication description

Truth comparison table:That is, the actual resistance value corresponding to the digital quantity. I only intercepted part here. For the rest, you can refer to the detailed manual by yourself


Truth comparison table

For the chip to be tuned, these introductions basically meet our needs


Rapid fabrication of chip modules

I bought two chips in the chip mall and came back for debugging. The cost of chip purchase was paid by my partner




Ready chip + adapter board




Two pieces are welded to prevent accidental damage during use, and the other can be repaired immediately to ensure normal commissioning without delaying too much time




Weld the row pins and add a 0.1uF filter capacitor at the power supply end to reduce the interference of high-frequency power supply




In this way, our module is completed


Arduino rapid construction project

The circuit principle diagram

Arduino uno pin 4 -> CLK


Arduino uno pin 5 -> DIN


Arduino uno pin 6 -> CS


Arduino uno pin 5V -> VCC、VREF


Arduino uno pin GND -> GND、L


Arduino uno pin A0 -> VRES_OUT


First, build the circuit with bread board + DuPont line


explain:The supply voltage and digital potentiometer reference voltage I use here are 5V, and the corresponding output results are also in the range of 0 ~ 5V




Then use the library provided by Arduino to write code, and then change the resistance parameters to see whether the actual output results correspond to the truth table


Corresponding analog voltage output when the value is 0x00





Corresponding analog voltage output when the value is 0x88





Corresponding analog voltage output when the value is 0xff




After verification, there is no problem running on Arduino. Next, we are ready to run on STM32


Arduino code part:

/*

STM32 construction engineering verification

explain:The supply voltage and digital potentiometer reference voltage used by STM32 are 3v3, and the corresponding output results are also in the range of 0 ~ 3v3


The circuit principle diagram


Pin correspondence:


PA4 -> CLK


PA5 -> DIN


PA6 -> CS


3V3 -> VCC、VREF


Arduino uno pin GND -> GND、L


Arduino uno pin A0 -> VRES-OUT


Development board + bread board building circuit




Build a project with stm32cube IDE




Configure PA4, Pa5 and PA6 pins as output




Generate the code and add the driver code of tpl0501




Compile to see the running effect. The input value is 0x55




Change the input value to 0x22 to verify whether it is correct




Main function code:

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * 

© Copyright (c) 2021 STMicroelectronics. * All rights reserved.

* * 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 */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ #define TLP0501_DIN_H() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET) #define TLP0501_DIN_L() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET) #define TLP0501_CS_H() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET) #define TLP0501_CS_L() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET) #define TLP0501_CLK_H() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET) #define TLP0501_CLK_L() HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET) /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ void TLP0501_WriteByte( uint8_t data ) { uint8_t j; for ( j=8; j>=1; j--) { TLP0501_CLK_L(); __NOP(); if(data & 0x80 ){ TLP0501_DIN_H(); } else { TLP0501_DIN_L(); } data <<= 1; TLP0501_CLK_H(); } } /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ /* 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(); /* USER CODE BEGIN 2 */ TLP0501_CS_L(); TLP0501_WriteByte(0x22); TLP0501_CS_H(); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { Error_Handler(); } } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_PIN_RESET); /*Configure GPIO pins : PA4 PA5 PA6 */ GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Summary:

1. Here we introduce one of many new IC chip debugging methods. Later, we have the opportunity to introduce the debugging methods of other ICs or new modules.

2. This paper simply tests the function of the chip, and there will be tests on the reliability and stability of transplantation and driver in the actual project.

3. We should be good at using the tools at hand and Arduino to quickly verify the development environment; The rapid verification of modules, especially in the process of project development, time is money. Mastering each tool is also an indispensable and important skill in the process of MCU development.

4. There is a big difference between hardware debugging and software debugging. Most of the time, it is one-time and irreversible. Unlike software CTL + Z, it can be revoked; It is normal for the hardware to be accidentally damaged during use: improper welding, accidental wrong insertion, inadequate electrostatic protection, etc; We should be good at using some project skills to weigh time or cost; The reason why we choose to weld two chip modules here is to prevent this accident from causing unnecessary time delay to debugging.