STM32 Learning Notes 6——Writing floating point numbers to the 24C02 chip

Publisher:码农创想家Latest update time:2019-02-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Method: Use union


(1) Union type definition


#define FLOAT_BYTE_NUM 4 //Number of bytes occupied by float type


//Floating point storage common

typedef union

{

    float value;

    uint8_t byte[FLOAT_BYTE_NUM];

} largeFloatData;


(2) Function definition


/********************************************************************************************************

Function name:

Function: Write a floating point number to the specified address

Details:

Input:

*********************************************************************************************************/


void Storage_WriteFloatNum( uint16_t addr, storFloatData data )

{

    uint8_t i = 0;

    uint8_t a = 0;


    for( i = 0; i <= FLOAT_BYTE_NUM - 1; i++ )

    {

      AT24CXX_WriteOneByte( addr + i, data.byte[i] );

    }

return;

}


/********************************************************************************************************

Function name:

Function: Read a floating point number from the specified address

Details:

Input:

*********************************************************************************************************/

storFloatData Storage_ReadFloatNum( uint16_t addr )

{

    uint8_t i = 0;

    largeFloatData read_data;


    for( i = 0; i <= FLOAT_BYTE_NUM - 1; i++ )

    {

        read_data.byte[i] = AT24CXX_ReadOneByte( addr + i );

    }


    return read_data;

}



(3) Use routines


largeFloatData data0={12.34};

largeFloatData data1;

Storage_WriteFloatNum(0,data0);

delay_ms(20);

data1 = Storage_ReadFloatNum(0);


Keywords:STM32 Reference address:STM32 Learning Notes 6——Writing floating point numbers to the 24C02 chip

Previous article:STM32 study notes 7 - floating point rounding
Next article:STM32F4 study notes 4——Please pay attention to the initialization order when using DMA mode for STM32 AD

Recommended ReadingLatest update time:2024-11-16 14:53

STM32 series MCU IO port mode setting
  Each IO port of the STM32 microcontroller has 4 32-bit configuration registers for configuring GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR and GPIOx_PUPDR, 2 32-bit data registers for configuring input and output registers GPIOx_IDR and GPIOx_ODR, 1 32-bit reset register GPIOx_BSRR, 1 32-bit lock register GPIOx_LCKR an
[Microcontroller]
STM32 series MCU IO port mode setting
Introduction to signals and message mailboxes of STM32 running ucosII system
Written in front: "Signal" can be simply understood as a semaphore (used for triggering by triggering). If a signal is passed from task 1 to task 2, then task 2 will receive this signal and continue to execute. "Message mailbox" can also be understood as a semaphore, except that the message can carry content: such
[Microcontroller]
Solar LED Street Light Solution Using STM32 MCU
As fossil energy is decreasing and the problem of global warming caused by excessive greenhouse gas emissions is becoming more and more important, people are actively developing various types of renewable energy on the one hand, and advocating green environmental protection technologies for energy
[Power Management]
Solar LED Street Light Solution Using STM32 MCU
STM32 interrupt priority and switch total interrupt
1. Interrupt priority: Priority concept in STM32 (Cortex-M3) There are two priority concepts in STM32 (Cortex-M3) - preemptive priority and response priority. Some people call response priority 'sub-priority' or 'sub-priority'. Each interrupt source needs to be assigned these two priorities. An interrupt with a hi
[Microcontroller]
Solution to "no target connect" when downloading STM32 SWD
1. Reappearance of the problem 2. Causes of the problem The two download pins of swd download are reused in the program, and then st-link cannot connect to your microcontroller through the download pins, so it shows that the target cannot be detected. 3. Solution The first: STEP1: Pull the BOOT0 pin high
[Microcontroller]
Solution to
stm32 study notes system clock
In STM32, there are five clock sources: HSI, HSE, LSI, LSE, and PLL. ①. HSI is a high-speed internal clock, an RC oscillator, with a frequency of 8MHz. ②. HSE is a high-speed external clock, which can be connected to a quartz/ceramic resonator or an external clock source, with a frequency range of 4MHz~16MHz. ③. LSI
[Microcontroller]
stm32 study notes system clock
STM32 Learning: DMA Detailed Explanation
The DMA part I used is relatively simple. Of course, maybe this is a new thing, and I can't use its complex functions for the time being. The following is a question and answer format to express my thoughts. What is DMA used for?        Direct memory access is used to provide high-speed data transfer between periphera
[Microcontroller]
STM32 Learning: DMA Detailed Explanation
Keil5.15 uses GCC compiler to compile STM32 project
We use Keil to compile MCU project code using ARMCC. In fact, Keil also supports embedded GCC compiler. We can use GCC to compile our project code. 1. Download the GCC compiler GCC compiler download address  2. Install GCC We can unzip GCC to the installation directory of Keil. As shown below 3. Configure Keil t
[Microcontroller]
Keil5.15 uses GCC compiler to compile STM32 project
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号