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

Posted on Leave a comment

Memory Space in ATmega16A

To effectively program AVR based microcontroller you must have knowledge about its memory space. Since there is not just one memory space. There are three different address spaces. They are:

  1. Data memory (SRAM)
    Here all your the intermediate results are stored and all the run time calculation get carried in this memory space.
  2. Program memory
    It is the memory where your application code is stored. And also it stores the constants. It could be divided into two sections by setting appropriate fuse bits. The two section will be:
    1. Application Section
    2. Boot Section
  3. EEPROM
    This is the memory where you can save the run time data such as configuration options, intermediate result for future processing. But it is very limited in size. So proper managment had to be taken care. Since it limits the size of certain applications.

Out of the three memories present in the ATmega16a, only the SRAM is volatile.

Size and address of memory space

  1. Data Memory
    1024 Bytes (Starting Address: 0x0060 – Last Address: 0x045F)
    96 Address which contain two section General purpose Register and I/O Registers.
    General Purpose Register ( Starting Address: 0x0000 – Last address: 0x001F)
    I/O register (Starting Address: 0x0020 – Last address: 0x005F)
  2. Program Memory
    Flash Type memory organised into 8000 memory location each pointing to a 16 bit wide data.
    Starting Address: 0x0000
    Last Address: 0x1FFF

NOTE: Care must be taken while Read/Write operations of EEPROM. It is very sensitive to operating conditions. Variations outside the tolerance limits could result in corruption of data in the worst case total loss of stored data. It is highly recommended that a stable power source must be used if performing frequent EEPROM operations.

Posted on Leave a comment

Express a number in IEEE-754 single-precision floating-point format

Sign

0 = positive number
1 = negative number

Biased Exponent(E)

A bias of 127 is to be added to the exponent number.
The biased exponent can range from -126 to +128
Which can fit in 8-bit’s.

Mantissa(F)

There is a one-bit towards the left of the floating point.
It must be noted here that is the number is shorter than 23 bits in length. Zeroes are padded towards the right side. to fit in the 23-bit field.

Posted on Leave a comment

Boolean Algebra

  • A + 0 = A
  • A + 1 = A
  • A . 0 = 0
  • A . 1 = A
  • A + A’ = 1
  • A . A’ = 0
  • Commutative Law
    A + B = B + A
  • Associative Law
    A + ( B + C ) = (A + B) + C
  • Distributive Law
    A . (B+C) = A.B + A.C
  • (A’)’ = A
  • De Morgan Theorem
    (A + B)’ = A’ . B’
    (A.B)’ = A’ + B’

Posted on Leave a comment

IEEE-754 32-bit Single Precision Floating Point Representation

IEEE 754 format for the representation of 32 bit single-precision floating-point numbers
IEEE 754 format for the representation of 32 bit single-precision floating-point numbers

In an ARM Cortex, M4F processor-based microcontroller such as STM32L476vg; the floating-point number is stored in accordance to the IEEE-754.

In the above video, I have written a small code using IAR workbench. When I debugged the program using IAR. I have observed that the floating-point number is converted by the compiler into IEEE 754 format and it is being stored in S# registers of the STM32L476vg. Which are the register present in the FPU(Floating Point Unit) or VFP(Vectored Floating Point) unit.

If you want to go into details, here is the abstract

Abstract: This standard specifies interchange and arithmetic formats and methods for binary and decimal floating-point arithmetic in computer programming environments. This standard specifies exception conditions and their default handling. An implementation of a floating-point system conforming to this standard may be realized entirely in software, entirely in hardware, or in any combination of software and hardware. For operations specified in the normative part of this standard, numerical results and exceptions are uniquely determined by the values of the input data, sequence of operations, and destination formats, all under user control.

“IEEE Standard for Floating-Point Arithmetic,” in IEEE Std 754-2008 , vol., no., pp.1-70, 29 Aug. 2008, doi: 10.1109/IEEESTD.2008.4610935.

A great tool to have is the online IEEE 754 convertor

https://www.h-schmidt.net/FloatConverter/IEEE754.html

Posted on Leave a comment

Logic Gates

The logic gates are basic building blocks for any digital electronic computer.

The AND, OR and NOT gates can be made from types of technology such as TTL, MOSFET, FET, or vacuum Tubes etc.

AND Gate

ABoutput (Y = A.B)
001
100
010
110
The truth table for AND gate

OR Gate

AB output (Y = A + B)
000
011
101
111
The truth table for OR gate

NOT Gate

AO/p = A’
01
10
The truth table for NOT gate

NAND Gate

AB output (Y = (A.B)’ )
001
011
101
110
The truth table for the NAND gate

NAND gate is known as a universal gate. All the other logic circuits can be derived from it.

NOR Gate

AB output (Y = (A+B)’ )
001
010
100
110
The truth table for NOR gate

NOR gate is known as a universal gate. All the other logic circuits can be derived from it.

XOR Gate

AB output (Y = A’B + AB’ )
000
011
101
110
The truth table for XOR gate

XNOR Gate

AB output (Y = AB + A’B’ )
001
010
100
111
The truth table for XNOR gate