国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

STM32基于HAL工程硬件I2C讀寫AT24C02/04/08數(shù)據(jù)

這篇具有很好參考價值的文章主要介紹了STM32基于HAL工程硬件I2C讀寫AT24C02/04/08數(shù)據(jù)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

STM32基于HAL工程硬件I2C讀取AT24C02數(shù)據(jù)


  • ?申明:本文章僅發(fā)表在CSDN網(wǎng)站,任何其他網(wǎng)站,未注明來源,見此內(nèi)容均為盜鏈和爬取,請多多尊重和支持原創(chuàng)!
  • ??對于文中所提供的相關(guān)資源鏈接將作不定期更換。
  • 相關(guān)篇針對AT24C32及以上容量《STM32基于STM32-HAL工程硬件I2C讀取AT24Cxx數(shù)據(jù)》
  • ??本工程使用STM32F103VE+AT24C02實物驗證沒有問題。由于手上只有AT24C02,沒有對低于AT24C32型號下的其它容量型號進(jìn)行測試。
  • ?說明:本庫文件僅支持容量大于4095Bytes(AT24C32)以下型號的讀取。
  • ??型號和容量參照:
#define AT24C01		127
#define AT24C02		255
#define AT24C04		511
#define AT24C08		1023
#define AT24C16		2047
#define AT24C32		4095
#define AT24C64	    8191
#define AT24C128	16383
#define AT24C256	32767 

??AT24C02/C4/C8/C16地址說明

  • ??AT24C02/C4/C8/C16的I2C地址取決于引腳A0、A1和A2的電平設(shè)置,可以有8個不同的地址。以下是每個地址對應(yīng)的引腳配置:
0b1010000:A0 = 0,A1 = 0,A2 = 0
0b1010001:A0 = 1,A1 = 0,A2 = 0
0b1010010:A0 = 0,A1 = 1,A2 = 0
0b1010011:A0 = 1,A1 = 1,A2 = 0
0b1010100:A0 = 0,A1 = 0,A2 = 1
0b1010101:A0 = 1,A1 = 0,A2 = 1
0b1010110:A0 = 0,A1 = 1,A2 = 1
0b1010111:A0 = 1,A1 = 1,A2 = 1
  • ??如果引腳A0-A1-A2都接地,則AT24Cxx的I2C地址為0b1010000(或0x50)。

?AT24C02/C4/C8/C16讀寫說明

  • ??AT24C02是一種2 Kb(256 × 8)串行電子可擦可編程只讀存儲器(EEPROM)芯片,支持標(biāo)準(zhǔn)I2C總線通信協(xié)議。AT24C02的編程操作是以頁為單位完成的,每次最多可編程8個連續(xù)字節(jié)。

具體來說,AT24C02的一頁大小為8個字節(jié),每次寫入數(shù)據(jù)時,需要確保寫入的數(shù)據(jù)不跨頁。因此,如果要在AT24C02中寫入10個字節(jié)的數(shù)據(jù),需要先將前8個字節(jié)寫入一個頁,再將后兩個字節(jié)寫入另一個頁。

  • ??AT24C08是一種8 Kb(1024 × 8)串行電子可擦可編程只讀存儲器(EEPROM)芯片,支持標(biāo)準(zhǔn)I2C總線通信協(xié)議。AT24C08的編程操作是以頁為單位完成的,每次最多可編程8個連續(xù)字節(jié)。

具體來說,AT24C08的一頁大小為8個字節(jié),每次寫入數(shù)據(jù)時,需要確保寫入的數(shù)據(jù)不跨頁。因此,如果要在AT24C08中寫入10個字節(jié)的數(shù)據(jù),需要先將前8個字節(jié)寫入一個頁,再將后兩個字節(jié)寫入另一個頁。

  • ??在AT24C16中,每個頁大小為16Bytes,因此一次最多可以進(jìn)行編程16個字節(jié)。

具體來說,AT24C016的一頁大小為16個字節(jié),每次寫入數(shù)據(jù)時,需要確保寫入的數(shù)據(jù)不跨頁。因此,如果要在AT24C16中寫入20個字節(jié)的數(shù)據(jù),需要先將前16個字節(jié)寫入一個頁,再將后4個字節(jié)寫入另一個頁。

??使用注意事項

  • ??將需要存儲的字符串或數(shù)組長度不要超過16個字符。
  • ??如果需要存儲超過16個字節(jié)長度的數(shù)據(jù)最好截斷,分段存儲。
  • ??讀取AT24Cxx的數(shù)據(jù),如果使用數(shù)組接收,不要直接使用printf–>%s來輸出,因為%s輸出結(jié)尾是以\0為結(jié)束符,直接使用%s輸出可能會導(dǎo)致輸出的數(shù)據(jù)重復(fù)輸出。以如下方式輸出:
				for(int i=0;i< BufferSize1;i++)
					{
						HAL_UART_Transmit(&huart1 , &Read_Buffer[i] , 1 , 1000);					
					}

??STM32CubeMX工程配置

  • ??使能一個I2C接口。(如果選擇I2C2,需要在at24_hal_i2c.c,修改相關(guān)函數(shù)的形參。)
    STM32基于HAL工程硬件I2C讀寫AT24C02/04/08數(shù)據(jù)
  • ??使能一個串口,用于調(diào)試信息輸出。
    STM32基于HAL工程硬件I2C讀寫AT24C02/04/08數(shù)據(jù)

??時鐘源根據(jù)個人具體的STM32型號自己配置。

??AT24C02/04/08驅(qū)動代碼

-?? at24_hal_i2c.c文件文章來源地址http://www.zghlxwxcb.cn/news/detail-410525.html

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
#include "stm32f1xx_hal_i2c.h"
#include <string.h>
#include <stdio.h>
#include "at24_hal_i2c.h"


/**
  * @brief               : This function handles Writing Array of Bytes on the specific Address .
  *                        This program have this feature that don't force you to use absolute 16 bytes
  *                        you can use more than 16 bytes buffer.
  * @param  hi2c         : Pointer to a I2C_HandleTypeDef structure that contains
  *                        the configuration information for the specified I2C.
  * @param  DevAddress   : specifies the slave address to be programmed(EEPROM ADDRESS).
  * @param  MemAddress   : Internal memory address (WHERE YOU WANNA WRITE TO)
  * @param  pData        : Pointer to data buffer
  * @param  TxBufferSize : Amount of data you wanna Write
  * @retval
  */
int at24_HAL_WriteBytes(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t TxBufferSize)
{
    /*
     * program just get the DevAddress of the Slave (not master) and for the next step
     * You know that the most of the EEprom address start with 0xA0
     * give MemAddress for the location you want to write to
     * give Data buffer so it can write Data on this location
     */
    //Note that this function works properly to 31 bytes
    if (MemAddress + TxBufferSize > 16)
    {
        //Write to 16bytes
        while (HAL_I2C_Mem_Write(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)16 - MemAddress, 1000) != HAL_OK);
        //write remaining bytes
        *pData = *pData + (16 - MemAddress);
        while (HAL_I2C_Mem_Write(hi2c, (uint16_t)DevAddress, (uint16_t)16, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)((MemAddress + TxBufferSize) - 16), 1000) != HAL_OK);

    }
    else
    {
        while ((TxBufferSize - 16) > 0)
        {
            //if your data is more than 16 bytes,you are here
            while (HAL_I2C_Mem_Write(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)16, 1000) != HAL_OK);
            TxBufferSize -= 16;
            pData += 16;
            MemAddress += 16;
        }
        //remaining data
        while (HAL_I2C_Mem_Write(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)TxBufferSize, 1000) != HAL_OK);
    }
    return 1;
}


int at24_HAL_ReadBytes(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t RxBufferSize)
{
    int TimeOut;
    /*
     * program just get the DevAddress of the Slave (not master) and for the next step
     * You know that the most of the EEprom address start with 0xA0
     * get the MemAddress for the location you want to write data on it
     * get the Data buffer so it can write Data on this location
     */
    //Note that this function works properly to 31bytes

    while ((RxBufferSize - 16) > 0)
    {
        //if your data is more than 16 bytes,you are here
        TimeOut = 0;
        while (HAL_I2C_Mem_Read(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)16, 1000) != HAL_OK && TimeOut < 10)
        {
            TimeOut++;
        }

        RxBufferSize   -= 16;
        pData  += 16;
        MemAddress += 16;
    }
//          //remaining data
    TimeOut = 0;
    while (HAL_I2C_Mem_Read(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)RxBufferSize, 1000) != HAL_OK && TimeOut < 10)
    {
        TimeOut++;
    }

    return 1;
}

/*
 * @brief               : This function handles Reading Array of Bytes from the specific Address .
 *                        This program have this feature that don't force you to use absolute 16 bytes
 *                        you can use more than 16 bytes buffer.
 * @param  hi2c         : Pointer to a I2C_HandleTypeDef structure that contains
 *                        the configuration information for the specified I2C.
 * @param  DevAddress   : specifies the slave address to be programmed(EEPROM ADDRESS).
 * @param  MemAddress   : Internal memory address (WHERE YOU WANNA READ FROM)
 * @param  pData        : Pointer to data buffer
 * @param  TxBufferSize : Amount of data to be Read
 * @retval
 */
int at24_HAL_SequentialRead(I2C_HandleTypeDef *hi2c , uint8_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t RxBufferSize)
{
    /*
     * just like WriteByte but get what it want
     * but maybe you should know that the Data is location you want to save data
     * for future use
     */
    while ((RxBufferSize - 16) > 0)
    {
        while (HAL_I2C_Mem_Read(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)16, (uint32_t)1000) != HAL_OK);
        RxBufferSize -= 16;
        pData += 16;
        MemAddress += 16;
    }
    while (HAL_I2C_Mem_Read(hi2c, (uint16_t)DevAddress, (uint16_t)MemAddress, I2C_MEMADD_SIZE_8BIT, pData, (uint16_t)RxBufferSize, (uint32_t)1000) != HAL_OK) {}
    /*
     * if DataRecive  is 0xFF or 255 ,this means that block was empty
     */
    return 1;
}

/*
 * @brief               : This function handles Erase Full chip.
 * @param  hi2c         : Pointer to a I2C_HandleTypeDef structure that contains
 *                        the configuration information for the specified I2C.
 * @retval
 */

int at24_HAL_EraseMemFull(I2C_HandleTypeDef *hi2c)
{
    /*
     * this may take will don't panic
     */
    uint8_t EraseBuf[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
    int i;
    for (i = 0 ; i < 1024 ; i += 16)
    {
        /*
         * if you know,0xFF means that block is empty
         */
//      sdI2C_WriteBytes(&hi2c,0xA0,(uint16_t )i,EraseBuf,16);
        at24_HAL_WriteBytes(hi2c, 0xA0, (uint16_t)i, EraseBuf, 16);
    }
    return 1;
}

/**
  * @brief               : This function handles Writing String on the specific Address .
  *                        This program have this feature that don't force you to use absolute 16 bytes
  *                        you can use more than 16 bytes buffer.
  * @param  hi2c         : Pointer to a I2C_HandleTypeDef structure that contains
  *                        the configuration information for the specified I2C.
  * @param  DevAddress   : specifies the slave address to be programmed(EEPROM ADDRESS).
  * @param  MemAddress   : Internal memory address (WHERE YOU WANNA Write)
  * @param  pString      : Pointer to data buffer(CHAR DATA)
  * @param  length       : Amount of buffer you wanna Write from
  * @retval
  */

int at24_HAL_WriteString(I2C_HandleTypeDef *hi2c, char *pString , uint16_t MemAddress , uint8_t length)
{
    uint8_t pData[length];
    int i = 0;
    while (*pString)
        (pData[i++]) = (uint8_t)(*pString++);
//  sdI2C_WriteBytes(&hi2c,0xA0,MemAddress,pData,length);
    at24_HAL_WriteBytes(hi2c, 0xA0, MemAddress, pData, length);
    return 1;
}

/**
  * @brief               : This function handles Reading String on the specific Address .
  *                        This program have this feature that don't force you to use absolute 16 bytes
  *                        you can use more than 16 bytes buffer.
  * @param  hi2c         : Pointer to a I2C_HandleTypeDef structure that contains
  *                        the configuration information for the specified I2C.
  * @param  MemAddress   : Internal memory address (WHERE YOU WANNA READ)
  * @param  pString      : Pointer to data buffer(CHAR DATA)
  * @param  length       : Amount of buffer you wanna Read from
  * @retval
  */

int at24_HAL_ReadString(I2C_HandleTypeDef *hi2c, char *pString, uint16_t MemAddress, uint8_t length)
{
    uint8_t pData[length];
    int i = 0;
//  sdI2C_RandomRead(0xA0,MemAddress,pData,length);
    at24_HAL_ReadBytes(hi2c, 0xA0, MemAddress, pData, length);


    while (pData[i])
        (*pString++) = (char)pData[i++];
    return 1;
}




  • ??at24_hal_i2c.h文件
#ifndef _AT24_HAL_I2C_H_
#define _AT24_HAL_I2C_H_

#include "stm32f1xx_hal.h"
#include "stm32f1xx_hal_i2c.h"


int at24_HAL_WriteBytes(I2C_HandleTypeDef *hi2c,uint16_t DevAddress,uint16_t MemAddress, uint8_t *pData,uint16_t TxBufferSize);
int at24_HAL_ReadBytes(I2C_HandleTypeDef *hi2c,uint16_t DevAddress,uint16_t MemAddress, uint8_t *pData,uint16_t RxBufferSize);

int at24_HAL_SequentialRead(I2C_HandleTypeDef *hi2c ,uint8_t DevAddress,uint16_t MemAddress,uint8_t *pData,uint16_t RxBufferSize);
int at24_HAL_EraseMemFull(I2C_HandleTypeDef *hi2c);
int at24_HAL_WriteString(I2C_HandleTypeDef *hi2c,char *pString ,uint16_t MemAddress ,uint8_t length);
int at24_HAL_ReadString(I2C_HandleTypeDef *hi2c,char *pString,uint16_t MemAddress,uint8_t length);


#endif /* DRIVERS_MYLIB_AT24_HAL_I2C_H_ */

??main主程序代碼

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "i2c.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
//#include "stdio.h"http://printf函數(shù)啟用
#include <string.h>
#include "at24_hal_i2c.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
#define AT24Cxx_ADDRESS ((uint16_t)0xA0)
#define  MemAddress  ((uint16_t)0x00)
/* 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 ---------------------------------------------------------*/

/* USER CODE BEGIN PV */
uint8_t Buffer[] = "Perseverance";//Hi!STM32F103VE Hello World Perseverance
#define countof(a) (sizeof(a) / sizeof(*(a)))
#define BufferSize1     (countof(Buffer)-1)
uint8_t Read_Buffer[BufferSize1];
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(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 */

    /* 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_I2C1_Init();
    MX_USART1_UART_Init();
    /* USER CODE BEGIN 2 */
    uint32_t TimerUART = HAL_GetTick();
		at24_HAL_WriteBytes(&hi2c1, AT24Cxx_ADDRESS, MemAddress, Buffer, BufferSize1);
//    if (BufferSize1 < 9)
//    {
//        printf("BufferSize=%d \r\n", BufferSize1);
//        at24_HAL_WriteBytes(&hi2c1, AT24Cxx_ADDRESS, MemAddress, Buffer, BufferSize1);
//    }
//    else
//    {
//        printf("注意:AT24C02一次不能超過8字節(jié) \r\n");
//    }

    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
    {
        /* USER CODE END WHILE */

        /* USER CODE BEGIN 3 */
        if ((HAL_GetTick() - TimerUART) > 2500)
        {

    at24_HAL_SequentialRead(&hi2c1,AT24Cxx_ADDRESS,MemAddress, Read_Buffer, BufferSize1);//連續(xù)讀16字節(jié)數(shù)據(jù)
//            at24_HAL_ReadBytes(&hi2c1, AT24Cxx_ADDRESS, MemAddress, Read_Buffer, BufferSize1);
				for(int i=0;i< BufferSize1;i++)
					{
						HAL_UART_Transmit(&huart1 , &Read_Buffer[i] , 1 , 1000);					
					}
//           printf("Read_Date=%s \r\n", Read_Buffer);//數(shù)組不要使用printf->%s輸出
            TimerUART = HAL_GetTick();
            HAL_GPIO_TogglePin(GPIOE, LED_Pin);
        }
    }
    /* 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_HSE;
    RCC_OscInitStruct.HSEState = RCC_HSE_ON;
    RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
    RCC_OscInitStruct.HSIState = RCC_HSI_ON;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
    RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
    RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
    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_PLLCLK;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

    if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
    {
        Error_Handler();
    }
}

/* 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 */
    __disable_irq();
    while (1)
    {
    }
    /* 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,
       ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

??工程源碼

  • ?申明:本文章僅發(fā)表在CSDN網(wǎng)站,任何其他網(wǎng)站,未注明來源,見此內(nèi)容均為盜鏈和爬取,請多多尊重和支持原創(chuàng)!
  • ??對于文中所提供的相關(guān)資源鏈接將作不定期更換。
鏈接: https://pan.baidu.com/s/1dxbnFDVQ3yJPxMlpESfSzA
提取碼: fc33

到了這里,關(guān)于STM32基于HAL工程硬件I2C讀寫AT24C02/04/08數(shù)據(jù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【STM32】STM32學(xué)習(xí)筆記-硬件I2C讀寫MPU6050(35)

    【STM32】STM32學(xué)習(xí)筆記-硬件I2C讀寫MPU6050(35)

    I2C(Inter-Integrated Circuit)總線是一種由NXP(原PHILIPS)公司開發(fā)的兩線式串行總線,用于連接微控制器及其外圍設(shè)備。多用于主控制器和從器件間的主從通信,在小數(shù)據(jù)量場合使用,傳輸距離短,任意時刻只能有一個主機(jī)等特性。 串行的 8 位雙向數(shù)據(jù)傳輸位速率在標(biāo)準(zhǔn)模式下可

    2024年01月25日
    瀏覽(34)
  • 01_STM32軟件+硬件I2C讀取MPU6050(HAL庫)

    01_STM32軟件+硬件I2C讀取MPU6050(HAL庫)

    目錄 1、I2C簡介 2、I2C時序單元 2.1 起始條件 2.2 終止條件 2.3 發(fā)送一個字節(jié) 2.4 接收一個字節(jié) 2.5 發(fā)送應(yīng)答 2.6 接收應(yīng)答 3、I2C完整時序 3.1 指定地址寫一個字節(jié) 3.2 當(dāng)前地址讀一個字節(jié) 3.2?指定地址讀一個字節(jié) 4、簡單軟件I2C代碼(HAL) 4.1 軟件I2C 4.2 軟件I2C讀MPU6050寄存器 5、ST

    2024年04月17日
    瀏覽(29)
  • 關(guān)于STM32硬件I2C HAL_I2C_Mem_Read,在I2C_WaitOnTXISFlagUntilTimeout返回HAL_ERROR

    關(guān)于STM32硬件I2C HAL_I2C_Mem_Read,在I2C_WaitOnTXISFlagUntilTimeout返回HAL_ERROR

    在使用NUCLEO-L452RE開發(fā)版的IIC總線作為主機(jī)和其他設(shè)備從機(jī)通信時主機(jī)IIC在以下代碼處返回HAL_ERROR. /* Wait until TXIS flag is set */ ? if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, Tickstart) != HAL_OK) ? { ? ? return HAL_ERROR; ? } 在調(diào)試中發(fā)現(xiàn)如果使用模擬IIC,可以與從機(jī)正常通信,但是使用硬件

    2024年04月28日
    瀏覽(23)
  • HAL STM32 硬件I2C方式讀取AS5600磁編碼器獲取角度例程

    HAL STM32 硬件I2C方式讀取AS5600磁編碼器獲取角度例程

    ??相關(guān)篇《STM32 軟件I2C方式讀取AS5600磁編碼器獲取角度例程》 ?stm32使用硬件I2C去讀取角度數(shù)據(jù),通過STM32CubeMX工具配置工程,讀取角度數(shù)據(jù),只需要調(diào)用一個函數(shù),即可完成數(shù)據(jù)的讀取。了解函數(shù)的用法以及從設(shè)備地址命令,上手十分快速和簡單。 ??AS5600資料: https://p

    2024年04月26日
    瀏覽(51)
  • STM32基于CubeMX與HAL庫的I2C應(yīng)用

    STM32基于CubeMX與HAL庫的I2C應(yīng)用

    1.1 物理層 ????????I2C協(xié)議和摩托羅拉公司的SPI協(xié)議一樣,是一種通訊協(xié)議。串行外圍設(shè)備接口,是一種高速全雙工的通信總線,是由 Phiilps 公司開發(fā)的。由于它引腳少,硬件實現(xiàn)簡單,可擴(kuò)展性強(qiáng),不需要 USART、CAN 等通訊協(xié)議的外部收發(fā)設(shè)備,現(xiàn)在被廣泛地使用在系統(tǒng)內(nèi)

    2024年02月21日
    瀏覽(33)
  • 基于HAL庫的stm32的OLED顯示屏顯示(模擬I2C,四腳,0.96寸)

    基于HAL庫的stm32的OLED顯示屏顯示(模擬I2C,四腳,0.96寸)

    參考視頻:江科大oled程序移植stm32hal庫,freertos學(xué)習(xí),cpu使用率_嗶哩嗶哩_bilibili ? STM32入門教程-2023持續(xù)更新中_嗶哩嗶哩_bilibili 高速和低速晶振均選擇為陶瓷晶振即可。 不需更改初始化配置,因為模擬I2C初始化時會設(shè)置這兩個引腳的電平 step1、step2完成后生成工程即可。 代

    2024年02月06日
    瀏覽(29)
  • STM32硬件I2C通信外設(shè)

    STM32硬件I2C通信外設(shè)

    本文主要介紹stm32自帶的I2C通信外設(shè),對比與軟件模擬I2C,硬件I2C可以自動生成時序,時序的操作更加及時規(guī)范,可以實現(xiàn)更加高性能的IIC通信。 本文內(nèi)容與I2C軟件通信有諸多類似之處,I2C軟件通信可見:https://blog.csdn.net/qq_53922901/article/details/136662006?spm=1001.2014.3001.5501 在8位指

    2024年04月08日
    瀏覽(27)
  • 4針0.96寸OLED的HAL庫代碼(硬件I2C/全代碼/stm32f1/CubeMX配置/包含有正負(fù)浮點數(shù)/100%一次點亮)

    4針0.96寸OLED的HAL庫代碼(硬件I2C/全代碼/stm32f1/CubeMX配置/包含有正負(fù)浮點數(shù)/100%一次點亮)

    一、HC-SR04超聲波模塊的使用 二、4針OLED的HAL庫代碼介紹及使用(本篇) 三、7針OLED的HAL庫代碼介紹及使用 四、編碼電機(jī)以及雙電機(jī)驅(qū)動 更多有意思的文章點擊“我的主頁” --------?? 更多有意思的視頻 ----- B站 @想要億只獨角獸 --------?? 之前在做一些小項目時用到了OLED,到

    2024年02月10日
    瀏覽(30)
  • STM32 HAL庫函數(shù)學(xué)習(xí) I2C篇

    本篇內(nèi)容講述STM32的硬件IIC功能。硬件IIC的使用在F1系列上可能會有問題。本次使用的測試平臺是H7,用于AT24C02芯片的讀寫正常,暫不清楚在其他芯片上使用是否正常。 1、HAL_StatusTypeDef HAL_I2C_Init (I2C_HandleTypeDef * hi2c) I2C初始化函數(shù),使用CubeMx生成。需要選中I2C硬件指定的IO口。

    2023年04月08日
    瀏覽(23)
  • STM32 HAL庫 STM32CubeMX -- I2C(IIC)

    STM32 HAL庫 STM32CubeMX -- I2C(IIC)

    I2C 通訊協(xié)議(Inter - Integrated Circuit) 也就是IIC; 由Phiilps 公司開發(fā)的,它引腳少,硬件實現(xiàn)簡單,可擴(kuò)展性強(qiáng),不需要USART、CAN 等通訊協(xié)議的外部收發(fā)設(shè)備。 I2C協(xié)議分為物理層和協(xié)議層。 物理層規(guī)定通訊系統(tǒng)中具有機(jī)械、電子功能部分的特性,確保原始數(shù)據(jù)在物理媒體的傳輸

    2023年04月16日
    瀏覽(20)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包