资源简介

某宝买上的MAX17043模块,测试的环境为KEIL5,使用芯片STM32F103ZET6

资源截图

代码片段和文件信息

#include “max17043.h“
#include “stdio.h“
#include “Drive_1602.h“
#define Max17043_Address  0x6C //设置max17043的基地址
static void Max17043_PortInit(){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIOENABLE);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB&GPIO_InitStructure); //初始化max17043的IIC接口
}
static void Max17043_AwakeSetPort(){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIOENABLE);

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB&GPIO_InitStructure); //初始化max17043的IIC接口
}
#define I2C_Speed              200000
#define I2C1_OWN_ADDRESS7    0x0A
void Max17043_Init(){
// I2C_InitTypeDef I2C_InitStructure;
  I2C_InitTypeDef  I2C_InitStructure; 

Max17043_PortInit();

  /* I2C 配置 */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 =I2C1_OWN_ADDRESS7; 
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable ;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = I2C_Speed;
  
  /* 使能 I2C1 */
  I2C_Cmd(I2C1 ENABLE);

  /* I2C1 初始化 */
  I2C_Init(I2C1 &I2C_InitStructure);
}
u8 Max17043_ReadData(uint8_t Data){
u8 Buffer_mBuffer_l;
while(I2C_GetFlagStatus(I2C1I2C_FLAG_BUSY));
I2C_GenerateSTART(I2C1ENABLE);
while(!I2C_CheckEvent(I2C1I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C1Max17043_AddressI2C_Direction_Transmitter);
while(!I2C_CheckEvent(I2C1I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C1Data);
while(!I2C_CheckEvent(I2C1I2C_EVENT_MASTER_BYTE_TRANSMITTED));
// I2C_GenerateSTOP(I2C1ENABLE);

I2C_GenerateSTART(I2C1ENABLE);
while(!I2C_CheckEvent(I2C1I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C1Max17043_AddressI2C_Direction_Receiver);
while(!I2C_CheckEvent(I2C1I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
Buffer_m=I2C_ReceiveData(I2C1);
Buffer_l=I2C_ReceiveData(I2C1);
I2C_AcknowledgeConfig(I2C1DISABLE);
I2C_AcknowledgeConfig(I2C1ENABLE);
I2C_GenerateSTOP(I2C1ENABLE);

return ((Buffer_l|(Buffer_m<<8))>>4);
}
void Max17043_WriteData(u8 Max17043_RomAddressu8 Data0u8 Data1){
int Sleep_Mode=0xffff;
while(I2C_GetFlagStatus(I2C1I2C_FLAG_BUSY)){
if(Sleep_Mode!=0){
Sleep_Mode--;
if(Sleep_Mode==0){
Max17043_AwakeSetPort();
GPIO_ResetBits(GPIOBGPIO_Pin_6);
Delay_Ms(50);
GPIO_SetBits(GPIOBGPIO_Pin_6);
Delay_Ms(50);
GPIO_ResetBits(GPIOBGPIO_Pin_6);
printf(“唤醒Max17043\n“);
Max17043_PortInit();
}
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-09-26 14:17  MAX17043源码\
     目录           0  2018-08-07 09:51  MAX17043源码\battery\
     文件        3748  2016-09-11 11:00  MAX17043源码\battery\MAX17043.c
     文件         210  2016-09-11 10:43  MAX17043源码\battery\MAX17043.h
     文件        3003  2018-07-24 18:09  MAX17043源码\battery\myiic.c
     文件        1345  2018-07-24 18:19  MAX17043源码\battery\myiic.h
     文件        1353  2018-07-23 10:48  MAX17043源码\battery\software_IIC.c
     文件         791  2018-09-26 14:16  MAX17043源码\battery\software_IIC.h
     目录           0  2018-08-07 09:51  MAX17043源码\CMSIS\
     文件       17273  2010-06-07 10:25  MAX17043源码\CMSIS\core_cm3.c
     文件       85714  2011-02-09 14:59  MAX17043源码\CMSIS\core_cm3.h
     目录           0  2018-08-07 09:51  MAX17043源码\CMSIS\startup\
     文件       15766  2011-03-10 10:52  MAX17043源码\CMSIS\startup\startup_stm32f10x_cl.s
     文件       15503  2011-03-10 10:52  MAX17043源码\CMSIS\startup\startup_stm32f10x_hd.s
     文件       15692  2011-03-10 10:52  MAX17043源码\CMSIS\startup\startup_stm32f10x_hd_vl.s
     文件       12376  2011-03-10 10:52  MAX17043源码\CMSIS\startup\startup_stm32f10x_ld.s
     文件       13656  2011-03-10 10:52  MAX17043源码\CMSIS\startup\startup_stm32f10x_ld_vl.s
     文件       12765  2011-03-10 10:52  MAX17043源码\CMSIS\startup\startup_stm32f10x_md.s
     文件       14073  2011-03-10 10:51  MAX17043源码\CMSIS\startup\startup_stm32f10x_md_vl.s
     文件       15955  2011-03-10 10:51  MAX17043源码\CMSIS\startup\startup_stm32f10x_xl.s
     文件      633941  2016-09-09 11:55  MAX17043源码\CMSIS\stm32f10x.h
     文件       36557  2011-03-10 10:51  MAX17043源码\CMSIS\system_stm32f10x.c
     文件        2085  2011-03-10 10:51  MAX17043源码\CMSIS\system_stm32f10x.h
     目录           0  2018-08-07 09:51  MAX17043源码\FWlib\
     目录           0  2018-08-07 09:51  MAX17043源码\FWlib\inc\
     文件        8982  2011-03-10 10:47  MAX17043源码\FWlib\inc\misc.h
     文件       21690  2011-03-10 10:47  MAX17043源码\FWlib\inc\stm32f10x_adc.h
     文件        7555  2011-03-10 10:47  MAX17043源码\FWlib\inc\stm32f10x_bkp.h
     文件       27559  2011-03-10 10:47  MAX17043源码\FWlib\inc\stm32f10x_can.h
     文件        6573  2011-03-10 10:47  MAX17043源码\FWlib\inc\stm32f10x_cec.h
     文件        2162  2011-03-10 10:47  MAX17043源码\FWlib\inc\stm32f10x_crc.h
............此处省略184个文件信息

评论

共有 条评论