你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STM32C0测评】Nucleo-C092开发板IIC通信测试(软件IIC)

[复制链接]
C70EH 发布时间:2025-5-6 16:34

我不知道为什么,感觉论坛的文本编辑设备贼难用,关于IIC的请以本篇为准吧,那些没有写好的我也没有办法了,如果管理员可以看到麻烦帮忙删除一下那些没有写好的文章吧。

各位同志好,这一篇我们使用IIC通信来设置与读取DS3231的数据,我们采用第一篇的程序模板。IIC分为硬件IIC和软件IIC。我们先来使用软件IIC来实现对DS3231的数据读取工作。

这里简单介绍一下本次试验用到的模组,这个是我去年自制的一个RTC时钟模块,准度非常可以。

8b98acb05ea44b3463761a405b64865.jpg

软件IIC并不是ST官方要求的评测内容,但是我觉得这个软件IIC也是挺重要的,所以在这里也搞了一个DEMO出来。软件IIC指的是并没有启用IIC模块,而是配置两个GPIO口当作IIC数据线来模拟IIC通信的时序,最后读取到DS3231中的信息。值得注意的是,由于我们模拟IIC的时序,这里不需要开芯片的IIC外设,相关配置如下:

软件IIC引脚配置.png

程序基本原理是:MCU上电后先初始化一堆东西,并使用串口打印相关作者信息,接着进入主函数中,每间隔1s打印一次串口信息,读取DS3231内部的数据信息并且翻转LED2表示它工作正常,如下图所示:

软件IIC现象.gif

串口打印如下:

软件IIC串口.png

程序实现如下:

STM32C092_SoftwareIIC.c的库文件(模拟时序用的库)

#include "STM32C092_SoftwareIIC.h"

uint8_t Freq=0;

//GPIO口宏定义中配置,方便更改
#define SoftWareIIC_PORT  GPIOB //使用GPIOB
#define SDA_PIN           SoftwareIIC_SDA_Pin//配置第9号脚
#define SCL_PIN           SoftwareIIC_SCL_Pin//配置第8号脚

void STM32C092_SoftwareIIC_us (unsigned long __us);

/******************************************************************
 * 函 数 名 称:STM32C092_SoftwareIIC_Init
 * 函 数 说 明:初始化软件IIC的引脚并将两个引脚置高电平
 * 函 数 形 参:uint8_t __Freq 写入加入项目中的RCC频率(例如配置64000000hz则写入64即可)
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void STM32C092_SoftwareIIC_Init(uint8_t __Freq)
{   
      Freq=__Freq;

      HAL_GPIO_WritePin(SoftWareIIC_PORT,SDA_PIN|SCL_PIN,GPIO_PIN_SET);//将SDA线,SCL线置高电平,待后续处理
}

/******************************************************************
 * 函 数 名 称:IIC_DigitalWrite_SDA
 * 函 数 说 明:对SDA线进行操作(1或者0)
 * 函 数 形 参:uint8_t Value 
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void IIC_DigitalWrite_SDA(uint8_t Value)
{
    if(Value==0){
        HAL_GPIO_WritePin(SoftWareIIC_PORT,SDA_PIN,GPIO_PIN_RESET);
    }
    else{
        HAL_GPIO_WritePin(SoftWareIIC_PORT,SDA_PIN,GPIO_PIN_SET);
    }
    STM32C092_SoftwareIIC_us(10); 
}

/******************************************************************
 * 函 数 名 称:IIC_DigitalWrite_SCL
 * 函 数 说 明:对SCL线进行操作(1或者0)
 * 函 数 形 参:uint8_t Value 
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void IIC_DigitalWrite_SCL(uint8_t Value)
{
     if(Value==0){
        HAL_GPIO_WritePin(SoftWareIIC_PORT,SCL_PIN,GPIO_PIN_RESET);
    }
    else{
        HAL_GPIO_WritePin(SoftWareIIC_PORT,SCL_PIN,GPIO_PIN_SET);

    }
    STM32C092_SoftwareIIC_us(10);
}

/******************************************************************
 * 函 数 名 称:IIC_DigitalRead_SDA
 * 函 数 说 明:对SDA线进行读操作
 * 函 数 形 参:无
 * 函 数 返 回:Value
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t IIC_DigitalRead_SDA(void){
    uint8_t Value;
    Value=HAL_GPIO_ReadPin(SoftWareIIC_PORT,SDA_PIN);
    STM32C092_SoftwareIIC_us(10);
    return Value;
}
/******************************************************************
 * 函 数 名 称:STM32C092_SoftwareIIC_us
 * 函 数 说 明:使用nop()产生IIC通信时序需要的延时
 * 函 数 形 参:unsigned long __us
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void STM32C092_SoftwareIIC_us (unsigned long __us) 
{
   __us*=Freq/4;
    while(__us){
        __NOP();
        __us--;
    }
}
/******************************************************************
 * 函 数 名 称:STM32C092_SoftwareIIC_Start
 * 函 数 说 明:软件IIC启动
 * 函 数 形 参:无
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void STM32C092_SoftwareIIC_Start(void){
    IIC_DigitalWrite_SDA(1);
    IIC_DigitalWrite_SCL(1);
    IIC_DigitalWrite_SDA(0);
    IIC_DigitalWrite_SCL(0);
}
/******************************************************************
 * 函 数 名 称:STM32C092_SoftWareIIC_Stop
 * 函 数 说 明:软件IIC停止
 * 函 数 形 参:无
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void STM32C092_SoftWareIIC_Stop(void){
    IIC_DigitalWrite_SDA(0);
    IIC_DigitalWrite_SCL(1);
    IIC_DigitalWrite_SDA(1);
}

/******************************************************************
 * 函 数 名 称:STM32C092_SoftWareIIC_SendByte
* 函 数 说 明:软件IIC发送一个字节
 * 函 数 形 参:uint8_t Byte
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void STM32C092_SoftWareIIC_SendByte(uint8_t Byte){
    uint8_t i;
    for(i=0;i<8;i++){
        IIC_DigitalWrite_SDA(Byte&(0x80>>i));
        IIC_DigitalWrite_SCL(1);
        IIC_DigitalWrite_SCL(0);
    }
 }

/******************************************************************
 * 函 数 名 称:STM32C092_SoftWareIIC_ReadByte
* 函 数 说 明:软件IIC接收一个字节
 * 函 数 形 参:无
 * 函 数 返 回:Byte
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t STM32C092_SoftWareIIC_ReadByte(void){
    uint8_t i,Byte=0;
    IIC_DigitalWrite_SDA(1);  
    for(i=0;i<8;i++){
        IIC_DigitalWrite_SCL(1);
        if(IIC_DigitalRead_SDA()==1){
            Byte|=(0x80>>i);
        }
        IIC_DigitalWrite_SCL(0);
    }
    return Byte;
 }

/******************************************************************
 * 函 数 名 称:STM32C092_SoftWareIIC_SendACK
* 函 数 说 明:软件IIC发送一个应答信号
 * 函 数 形 参:uint8_t ACK
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
 void STM32C092_SoftWareIIC_SendACK(uint8_t ACK){
    IIC_DigitalWrite_SDA(ACK);
        IIC_DigitalWrite_SCL(1);
        IIC_DigitalWrite_SCL(0);
 }

 /******************************************************************
 * 函 数 名 称:STM32C092_SoftWareIIC_ReadACK
* 函 数 说 明:软件IIC接收一个应答信号用来监测从设备
 * 函 数 形 参:无
 * 函 数 返 回:Byte
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t STM32C092_SoftWareIIC_ReadACK(void){
    uint8_t ACK=0;
    IIC_DigitalWrite_SDA(1);  
    IIC_DigitalWrite_SCL(1);
    ACK=IIC_DigitalRead_SDA();
        IIC_DigitalWrite_SCL(0);
    return ACK;
}

STM32C092_SoftwareIIC.h的库文件(模拟时序用的库)

#ifndef __STM32C092_SoftwareIIC_H
#define __STM32C092_SoftwareIIC_H
#include "main.h"

void STM32C092_SoftwareIIC_Init(uint8_t __Freq);
void IIC_DigitalWrite_SDA(uint8_t Value);
void IIC_DigitalWrite_SCL(uint8_t Value);
uint8_t IIC_DigitalRead_SDA(void);
void STM32C092_SoftwareIIC_Start(void);
void STM32C092_SoftWareIIC_Stop(void);
void STM32C092_SoftWareIIC_SendByte(uint8_t Byte);
uint8_t STM32C092_SoftWareIIC_ReadByte(void);
void STM32C092_SoftWareIIC_SendACK(uint8_t ACK);
uint8_t STM32C092_SoftWareIIC_ReadACK(void);

#endif

STM32C092_DS3231.c的库文件

#include "STM32C092_DS3231.h"

#define DS3231_ADDRESS 0xD0  //DS3231 IIC通信地址
//DS3231寄存器地址
#define DS3231ADD_Sec 0x00
#define DS3231ADD_Min 0x01
#define DS3231ADD_Hour 0x02
#define DS3231ADD_Week 0x03
#define DS3231ADD_Date 0x04
#define DS3231ADD_Mouth 0x05
#define DS3231ADD_Year 0x06
#define DS3231ADD_Control 0x0E

#define DS3231ADD_TempH 0x11
#define DS3231ADD_TempL 0x12

/******************************************************************
 * 函 数 名 称:BCD_DEC
 * 函 数 说 明:BCD码转换DEC数字
 * 函 数 形 参:Value
 * 函 数 返 回:(Value / 16 * 10) + (Value % 16)
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t BCD_DEC(uint8_t Value){  //BCD码转换DEC数字
    return ( (Value / 16 * 10) + (Value % 16) );
}

/******************************************************************
 * 函 数 名 称:DEC_BCD
 * 函 数 说 明:DEC码转换BCD数字
 * 函 数 形 参:Value
 * 函 数 返 回:(Value / 10 * 16) + (Value % 10)
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DEC_BCD(uint8_t Value){  //DEC码转换BCD数字
 return ( (Value / 10 * 16) + (Value % 10) );
}

/******************************************************************
 * 函 数 名 称:DS3231_Init
 * 函 数 说 明:DS3231初始化,将RCC频率写入软件IIC库初始化,写入项目中的RCC频率(例如配置64000000hz则写入64即可)
 * 函 数 形 参:uint8_t __Freq 
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void DS3231_Init(uint8_t __Freq){  
    STM32C092_SoftwareIIC_Init(__Freq);
}
/******************************************************************
 * 函 数 名 称:DS3231_WriteByte
 * 函 数 说 明:DS3231写入一个字节
 * 函 数 形 参:寄存器地址Address   写入数据Data
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void DS3231_WriteByte(uint8_t Address,uint8_t Data){
    STM32C092_SoftwareIIC_Start();
    STM32C092_SoftWareIIC_SendByte(DS3231_ADDRESS);
    STM32C092_SoftWareIIC_ReadACK();
    STM32C092_SoftWareIIC_SendByte(Address);
    STM32C092_SoftWareIIC_ReadACK(); 
    STM32C092_SoftWareIIC_SendByte(DEC_BCD(Data));
    STM32C092_SoftWareIIC_ReadACK();
    STM32C092_SoftWareIIC_Stop();

}
/******************************************************************
 * 函 数 名 称:DS3231_ReadByte
 * 函 数 说 明:DS3231读取一个字节
 * 函 数 形 参:寄存器地址Address   
 * 函 数 返 回:读出数据Data
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_ReadByte(uint8_t Address){
    uint8_t Data;
    STM32C092_SoftwareIIC_Start();
    STM32C092_SoftWareIIC_SendByte(DS3231_ADDRESS);
    STM32C092_SoftWareIIC_ReadACK();
    STM32C092_SoftWareIIC_SendByte(Address);
    STM32C092_SoftWareIIC_ReadACK(); 

    STM32C092_SoftwareIIC_Start();
    STM32C092_SoftWareIIC_SendByte(DS3231_ADDRESS | 0x01);
    STM32C092_SoftWareIIC_ReadACK();
    Data=STM32C092_SoftWareIIC_ReadByte();
    STM32C092_SoftWareIIC_SendACK(1);
    STM32C092_SoftWareIIC_Stop();
    return Data;
}

/******************************************************************
 * 函 数 名 称:DS3231_SQW
 * 函 数 说 明:DS3231设置SQW频率值
 * 函 数 形 参:DS3231_SQWState(枚举变量,支持DS3231_SQW_1S、DS3231_SQW_NONE)
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void DS3231_SQW(DS3231_SQWState SQW_SOURCE){
if(SQW_SOURCE==DS3231_SQW_1S){
    DS3231_WriteByte(DS3231ADD_Control,0x00);
    }
else{
    DS3231_WriteByte(DS3231ADD_Control,0x04);
 }
}

/******************************************************************
 * 函 数 名 称:DS3231_SetTime1
 * 函 数 说 明:DS3231设置时间1
 * 函 数 形 参:Hour:设置小时 Min:设置分钟 Sec:设置秒
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void DS3231_SetTime1(uint8_t Hour,uint8_t Min,uint8_t Sec){
    DS3231_WriteByte(DS3231ADD_Sec,Sec);
    DS3231_WriteByte(DS3231ADD_Min,Min);
    DS3231_WriteByte(DS3231ADD_Hour,Hour);
 }

 /******************************************************************
 * 函 数 名 称:DS3231_SetTime2
 * 函 数 说 明:DS3231设置时间2
 * 函 数 形 参:Year:设置年 Mouth:设置月 Date:设置日期  Week:设置周
 * 函 数 返 回:无
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
void DS3231_SetTime2(int Year,uint8_t Mouth,uint8_t Date,uint8_t Week){

  DS3231_WriteByte(DS3231ADD_Week,Week);
    DS3231_WriteByte(DS3231ADD_Date,Date);
    DS3231_WriteByte(DS3231ADD_Mouth,Mouth);
    DS3231_WriteByte(DS3231ADD_Year,Year-2000);
 }
/******************************************************************
 * 函 数 名 称:DS3231_RaedSec
 * 函 数 说 明:DS3231读出时间(秒数)
 * 函 数 形 参:无
 * 函 数 返 回:Sec
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_RaedSec(void){
uint8_t Sec=BCD_DEC(DS3231_ReadByte(DS3231ADD_Sec));  
return Sec;  
}

/******************************************************************
 * 函 数 名 称:DS3231_RaedMin
 * 函 数 说 明:DS3231读出分钟
 * 函 数 形 参:无
 * 函 数 返 回:Min
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_RaedMin(void){
uint8_t Min=0;
Min=BCD_DEC(DS3231_ReadByte(DS3231ADD_Min));  
return Min;  
}
/******************************************************************
 * 函 数 名 称:DS3231_RaedHour
 * 函 数 说 明:DS3231读出小时
 * 函 数 形 参:无
 * 函 数 返 回:Min
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_RaedHour(void){
uint8_t Hour=0;
    Hour=BCD_DEC(DS3231_ReadByte(DS3231ADD_Hour));  
return Hour;  
}
/******************************************************************
 * 函 数 名 称:DS3231_RaedWeek
 * 函 数 说 明:DS3231读出星期
 * 函 数 形 参:无
 * 函 数 返 回:Week
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_RaedWeek(void){
uint8_t Week=0;
Week=BCD_DEC(DS3231_ReadByte(DS3231ADD_Week));  
return Week;  
}
/******************************************************************
 * 函 数 名 称:DS3231_RaedDate
 * 函 数 说 明:DS3231读出日期
 * 函 数 形 参:无
 * 函 数 返 回:Date
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_RaedDate(void){
uint8_t Date=0;
Date=BCD_DEC(DS3231_ReadByte(DS3231ADD_Date));  
return Date;  
}

/******************************************************************
 * 函 数 名 称:DS3231_RaedMouth
 * 函 数 说 明:DS3231读出月份
 * 函 数 形 参:无
 * 函 数 返 回:Mouth
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
uint8_t DS3231_RaedMouth(void){
uint8_t Mouth=0;
Mouth=BCD_DEC(DS3231_ReadByte(DS3231ADD_Mouth));  
return Mouth;  
}

/******************************************************************
 * 函 数 名 称:DS3231_RaedYear
 * 函 数 说 明:DS3231读出年
 * 函 数 形 参:无
 * 函 数 返 回:Mouth
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
int DS3231_RaedYear(void){
int Year=0;
Year=BCD_DEC(DS3231_ReadByte(DS3231ADD_Year))+2000;  
return Year;  
}

/******************************************************************
 * 函 数 名 称:DS3231_RaedTemp
 * 函 数 说 明:DS3231读出温度
 * 函 数 形 参:无
 * 函 数 返 回:Temp
 * 作       者:C70E 1720223
 * 备       注:无
******************************************************************/
float DS3231_RaedTemp(void){
float Temp=BCD_DEC(DS3231_ReadByte(DS3231ADD_TempH))+(DS3231_ReadByte(DS3231ADD_TempL)/2.56)*0.01;
return Temp;
}

STM32C092_DS3231.h的库文件

#ifndef __STM32C092_DS3231_H
#define __STM32C092_DS3231_H

#include "STM32C092_SoftWareIIC.h"

typedef enum  
{
    DS3231_SQW_1S=0,
        DS3231_SQW_NONE
}   DS3231_SQWState;
  //枚举变量 DS3231_SQW枚举变量

/******************************************************************************/
/* Include files                                                              */
/******************************************************************************/
uint8_t BCD_DEC(uint8_t Value);//BCD码转换DEC数字
uint8_t DEC_BCD(uint8_t Value);//DEC码转换BCD数字

void DS3231_Init(uint8_t __Freq);//DS3231初始化,将RCC频率写入软件IIC库初始化,写入项目中的RCC频率(例如配置64000000hz则写入64即可)
void DS3231_WriteByte(uint8_t Address,uint8_t Data);//DS3231写入一个字节
uint8_t DS3231_ReadByte(uint8_t Address);//DS3231读取一个字节

void DS3231_SQW(DS3231_SQWState SQW_SOURCE);//DS3231设置SQW频率值
void DS3231_SetTime1(uint8_t Hour,uint8_t Min,uint8_t Sec);//DS3231设置时间1
void DS3231_SetTime2(int Year,uint8_t Mouth,uint8_t Date,uint8_t Week);//DS3231设置时间2

uint8_t DS3231_RaedSec(void);//DS3231读出时间(秒数)
uint8_t DS3231_RaedMin(void);//DS3231读出分钟
uint8_t DS3231_RaedHour(void);//DS3231读出小时
uint8_t DS3231_RaedWeek(void);//DS3231读出星期
uint8_t DS3231_RaedDate(void);//DS3231读出日期
uint8_t DS3231_RaedMouth(void);//DS3231读出月份
int DS3231_RaedYear(void);//DS3231读出年

float DS3231_RaedTemp(void);//DS3231读出温度


#endif

主函数

/*
  *作者:下行路轨上的C70E 论坛ID钟详
    *Nucleo-C092 demo程序任务5:使用I/O模拟IIC时序,并读取DS3231获得时间,将收到的时间发出给串口助手,同时控制LED2灯闪烁。
    *使用意法半导体Nucleo板卡,配置外置晶体48M,波特率9600

    *本次列车开往萧山国际机场,下一站,港城大道,开左边门
*/

/*包含所需头文件*/
#include "main.h"
#include "usart.h"
#include "gpio.h"
#include "stdio.h"
#include "stm32c0xx_it.h"
#include "STM32C092_DS3231.h"

/*函数声明*/
void SystemClock_Config(void);

/*定义变量*/
float Temp;

/*主函数*/
int main(void){
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART2_UART_Init();

/*DS3231写入初始时间*/
    DS3231_Init(48);
    DS3231_SetTime1(23,59,30);
  DS3231_SetTime2(2025,4,21,1);
  DS3231_SQW(DS3231_SQW_1S);


    /*打印作者信息*/
    printf("\r\nST Chinese Forum Evaluation Plan\r\n");
    printf("\r\nBoard Mode:Nucleo-C092\r\n");
    printf("\r\nDemo5:DS3231 SoftwareIIC Test\r\n");
    printf("\r\nReviewer:Xiang Zhong Bli:C70E\r\n");


  /*进入循环体*/
    while (1){
    /*打印从DS3231读取到的信息*/
     printf("Time2=%d:%d:%d:%d\n",DS3231_RaedYear(),DS3231_RaedMouth(),DS3231_RaedDate(),DS3231_RaedWeek());
   printf("Time1=%d:%d:%d\n",DS3231_RaedHour(),DS3231_RaedMin(),DS3231_RaedSec());
   printf("Temp=%f\n",DS3231_RaedTemp());
     HAL_GPIO_TogglePin(User_LED2_GPIO_Port,User_LED2_Pin);
     HAL_Delay(1000);

   }
    }

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  __HAL_FLASH_SET_LATENCY(FLASH_LATENCY_1);

  /** 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;
  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_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
  RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;

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

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 */
}

/*printf函数支持(阻塞法打印数据)*/
int fputc(int ch,FILE *f)
{
  HAL_UART_Transmit(&huart2,(uint8_t *)&ch,1,0xFFFF);//阻塞方式打印
  return ch;
}

#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 */

好的,感谢各位的观看,这样我们就实现了IIC通信测试。下一篇进行硬件IIC测试

收藏 评论0 发布时间:2025-5-6 16:34

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版