Posted on Leave a comment

How to interface potentiometer to ESP32 to read ADC Values

Here is the simple code to read the ADC value and show it in the serial monitor of Arduino ide.

const int Analog_channel_pin= 34;
int ADC_VALUE = 0;
float voltage_value = 0; 
void setup() 
{
Serial.begin(115200);
}
void loop() 
{
ADC_VALUE = analogRead(Analog_channel_pin);
Serial.print("ADC VALUE = ");
Serial.println(ADC_VALUE);
delay(1000);
voltage_value = (ADC_VALUE * 3.3 ) / (4095);
Serial.print("    Voltage = ");
Serial.print(voltage_value);
Serial.println("volts");
delay(1000);
}
The output of serial monitor
Posted on Leave a comment

Do not connect microcontroller pins to the VGA monitor directly

I tried to generate VGA signal on stm32f103

I used two timers, the TIMER 2 generate the horizontal sync and then the second timer TIMER 3 is configured in gated slave mode which generates the vertical sync.

Then I used HAL_SPI_TRANSMIT_DMA function inside the timer 2 interrupt handler.

I in a hurried manner connected the video signal to the monitor directly. And that has burned the image onto the monitor.

I connected the green video signal directly from the stm32f103 to the VGA connector.

image is now burned in the monitor.

Posted on 4 Comments

SIMcom A7670c LTE Module with UART

This module can be used with Indian 4G bands. This means it can be used with Vodafone, Airtel or Jio networks.

This module comes preconfigured with AT commands.

The module offers UART to issue commands.

Since the communication speed is really high so the 3.3V and 5V UART lines can not be used for communication with the board.

The company offers technical documents on hardware design for the UART.

Here is the circuit I am using for converting the 1.8V to 5V using the BC547 NPN BJT transistor.

I connected the UART on the module to a USB-to-Serial convertor.

I can then use AT commands to control the module functions like call, SMS, data etc.

Here is the basic AT commands

  • For making calls,SMS or data etc from the module you will need a Registered SIM card
  • For making calls from module
    ATDxxxxxxxxxx;
    x’s are your telephone number
    semi colon must be inserted at the end
  • For issuing DTMF tones
    AT+VTS=[number],[duration]
    Example: DTMF tone for digit 8
    AT+VTS=8,500
  • For Receiving Incoming Calls
    ATA
  • For Disconeccting On-going call
    AT+CVHU=0
    ATH
  • For Sending SMS
    AT+CMGF=1
    AT+CMGF=”+[country ISD code][Mobile number]”
    after sending the above commands you can send your message.
    At the end of your message you need to send number 26 (hex 1A) to mark the end of your message.
Posted on Leave a comment

Raspberry Pi Pico

This board is using an RP2040 microcontroller. Which is using a dual-core arm cortex m0+ processor. The speed of the clock signal can be changed on the fly up to 133MHz.

The Pico board is castellated so that you can mount this board directly on your PCB. This board also has options for mounting male/female headers. which is handy for prototyping on a breadboard.

It can be programmed using micropython and ‘C’ programming language.

Raspberry Pi Pico datasheet
Getting started with Raspberry Pi Pico: C/C++ development
Raspberry Pi Pico C/C++ SDK
Raspberry Pi RP2040 datasheet
Hardware design with RP2040

Technical Specifications

21 mm × 51 mm form factor
RP2040 microcontroller chip designed by Raspberry Pi in the UK
Dual-core Arm Cortex-M0+ processor, flexible clock running up to 133 MHz
264KB on-chip SRAM
2MB on-board QSPI Flash
26 multifunction GPIO pins, including 3 analogue inputs
2 × UART, 2 × SPI controllers, 2 × I2C controllers, 16 × PWM channels
1 × USB 1.1 controller and PHY, with host and device support
8 × Programmable I/O (PIO) state machines for custom peripheral support
Supported input power 1.8–5.5V DC
Operating temperature -20°C to +85°C
Castellated module allows soldering direct to carrier boards
Drag-and-drop programming using mass storage over USB
Low-power sleep and dormant modes
Accurate on-chip clock
Temperature sensor
Accelerated integer and floating-point libraries on-chip

Getting Started with MicroPython on Raspberry Pi Pico using Thonny IDE

Posted on 3 Comments

Mini STM32 V3.0

This development board has an STM32F103RB microcontroller. In this development board,

  • 8 Mhz Crystal
  • 32.768 Khz Crystal
  • 2.8 inch TFT-LCD Touch screen.
    The screen is a TFT-LCD Panel driven by the ili9325 driver.
  • PL2303 USB to Serial IC
  • User Programmable USB port
  • battery holder
  • Potentiometer
  • JTAG Port for debug and programming
  • 2 User programmable LED (both Red Colour)
  • 2 User configurable Push button
  • Boot 0 Button
  • Reset Button
  • AMS117 3.3 V LDO

Mini STM32 Schematic Diagram

2.8 inch TFT LCD Schematic

You can develop a program for this board using Keil, IAR or STM32 Cube IDE

You can program the microcontroller by holding the BOOT0 button and then while holding the boot button pressing the RESET button.
Which enable you to program the microcontroller using UART.

You will need STM32 Cube Programmer to upload hex files into the microcontroller

You can also program the Board using the JTAG port.

You can use the below application note for that.

How to use the ST-LINK/V2-1 in STM32L476G-DISCO Board to program the STM32 on an external application board

How To / Guides

Posted on Leave a comment

How to redirect printf() to USART in STM32f103RB using STM32Cube IDE

Printf() function can be redirected to USART and also towards SWO.

Here you will see how to redirect printf() to USART in STM32f103RB

You need to rewrite this code in your main.c file

/*
* Function Name: _write
* Function Description: Redirect the printf() statement towards the UART using the HAL_UART_Transmit
Author: Abhay

*/
int _write(int fd, char* ptr, int len) {
    HAL_UART_Transmit(&huart1, (uint8_t *) ptr, len, HAL_MAX_DELAY);
    return len;
}

If you have created your project using STM32CubeMX or STM32 Cube IDE, then you can rewrite it in between USER CODE BEGIN 0 as shown

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int _write(int fd, char* ptr, int len) {
    HAL_UART_Transmit(&huart1, (uint8_t *) ptr, len, HAL_MAX_DELAY);
    return len;
}
/* 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();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */
}

After adding the code, connect the uart to your laptop or computer using serial to USB adapter and open serial Terminal application like YAT.
Then you will be able to see printf message over there.

Posted on Leave a comment

How to use the ST-LINK/V2-1 in STM32L476G-DISCO Board to program the STM32 on an external application board

Here is the video showing all the steps.

ST-Link V2-1 on STM32L476G-Disco Board

To use the ST-LINK/V2-1 to program the STM32 on an external application board (out of the STM32L476VGT6 onboard), remove the two jumpers from CN3 as shown in the above figure in red, and connect the board to the CN4 software debug connector according to Table.
Make sure the jumpers JP6.3V3, and JP5.OFF are set.
JP3, must be ON if CN4 pin 5 (NRST) is used in the external application board.

PinCN4 FunctionJTAG PIN NumberJTAG NameNote
1VappVDD from ApplicationDo not Connect Vapp to JTAG.
2SWCLKSWD Clock9TCK
3GNDGround1 to 9GND
4SWDIOSWD data input/output7TMS
5NRSTRESET of target MCU15nSRST
6SWORESERVED

Note: Do not connect Vapp to JTAG on the external board unless you know about the power domain of the external board.
Power the board separately.

You can use STM32CubeProgrammer to read the memory and also write the hex file into the microcontroller.

Here I am using mini stm32 v3.0 as an example.

The mini stm32 v3.0 has an STM32F103RB microcontroller along with a JTAG interface for programming and debugging.

Posted on Leave a comment

Up Counting Timer using STM32L476

I have created this Upcounting timer using the RTC of STM32L476vgt. In this timer, time will keep on incrementing and it will be displayed using the onboard LCD.

How to Read RTC of STM32L476G-DISCO

Here is the code that I have used to make this.

I have used STM32 CUBE IDE for programming and debugging purposes.

  MX_RTC_Init();				// RTC initalization and configuration created using integrated cube mx
  /* USER CODE BEGIN 2 */
  BSP_LCD_GLASS_Init();
  BSP_LCD_GLASS_Clear();
  BSP_LCD_GLASS_DisplayString((uint8_t *)"HALLO");
  HAL_Delay(1000);
  BSP_LCD_GLASS_DisplayString((uint8_t *)"EXASUB");
  HAL_Delay(2000);


  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  RTC_TimeTypeDef readTime;	// RTC Time structure
  RTC_DateTypeDef readDate;	// RTC Date structure
  while (1)
  {
    /* USER CODE END WHILE */
    MX_USB_HOST_Process();

    /* USER CODE BEGIN 3 */

    char bufSec[2];
    char bufMin[2];
    char bufHou[2];
    HAL_RTC_GetTime(&hrtc, &readTime, RTC_FORMAT_BIN);	// function to read time from RTC shadow register
    HAL_RTC_GetDate(&hrtc, &readDate, RTC_FORMAT_BIN);	// function to read date from RTC shadow register
   itoa(readTime.Seconds,bufSec,10);
   itoa(readTime.Minutes,bufMin,10);
   itoa(readTime.Hours,bufHou,10);
   if(readTime.Seconds == 0){
	   BSP_LCD_GLASS_Clear();
   }
   if(readTime.Minutes == 0){
	   BSP_LCD_GLASS_Clear();
   }
   /*
    if(readTime.Hours == 0){
   	   BSP_LCD_GLASS_Clear();
      }
   */
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufHou[0], POINT_OFF, DOUBLEPOINT_OFF, 0);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufHou[1], POINT_OFF, DOUBLEPOINT_ON, 1);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufMin[0], POINT_OFF, DOUBLEPOINT_OFF, 2);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufMin[1], POINT_OFF, DOUBLEPOINT_ON, 3);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufSec[0], POINT_OFF, DOUBLEPOINT_OFF, 4);
   BSP_LCD_GLASS_DisplayChar((uint8_t *)&bufSec[1], POINT_OFF, DOUBLEPOINT_OFF, 5);

    HAL_Delay(1000);									// HAL Delay of 1000 millisecond
  }
  /* USER CODE END 3 */
}

Posted on 1 Comment

How to Read RTC of STM32L476G-DISCO

Create a Project in STM32 CUBE IDE for the STM32L476G-DISCO board.

Select LSE as Clock Source for RTC

The default option is LSI which uses an internal RC circuit.

LSE is the external 32KHz crystal that is provided on the board for the RTC.

Activate the Clock source and Calendar

This will enable the RTC clock source and will also enable the calendar for date and timekeeping.

If you want to set some default time and date you can set it in the RTC configuration menu. You can always change them later through your code.

After doing the above-said steps you can now generate code. This will give you an initialization code.

To read the value from the RTC registers. You need to remember the following thing.

From Section 38.3.8 of RM0351 Rev 1 Reference Manual

It says that reading the sub-second register or Time register alone will lock the value. It will remain locked until the Date register is read.

To prevent the lockup from happening. It is suggested to read time and date simultaneously one after the another.

Here I am writing working code

 MX_RTC_Init();				// RTC initalization and configuration created using integrated cube mx 
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  RTC_TimeTypeDef readTime;	// RTC Time structure 
  RTC_DateTypeDef readDate;	// RTC Date structure
  while (1)
  {
    /* USER CODE END WHILE */
    

    /* USER CODE BEGIN 3 */
/*  function to read time from RTC shadow register */
    HAL_RTC_GetTime(&hrtc, &readTime, RTC_FORMAT_BIN);

/* function to read date from RTC shadow register	*/
    HAL_RTC_GetDate(&hrtc, &readDate, RTC_FORMAT_BIN);

    printf("Minute: %d\t",readTime.Minutes);
    printf("Seconds: %d\n",readTime.Seconds);

    HAL_Delay(1000);	// HAL Delay of 1000 millisecond
  }
  /* USER CODE END 3 */
}

I am using print statements for debugging using stm32cube ide.
How to use printf using serial wire debug on STM32L476 Discovery