OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5658|回复: 1

BQ32000 i2c通讯

[复制链接]

4

主题

8

帖子

0

精华

新手上路

积分
46
金钱
46
注册时间
2014-8-21
在线时间
0 小时
发表于 2014-8-25 15:09:25 | 显示全部楼层 |阅读模式
5金钱
[mw_shl_code=c,true]//BQ32000???????÷ void BQ3200_WriteRegister(uint32_t I2Cx, unsigned char RegisterAddress, unsigned char Data) { //·??????· I2C_GenerateSTART(BQ32000_I2C_PORT); I2C_Send7bitAddress(BQ32000_I2C_PORT,BQ32000_IIC_ADDRESS,kI2C_Write); I2C_WaitAck(BQ32000_I2C_PORT); //·????è?????????????÷???· I2C_SendData(BQ32000_I2C_PORT,RegisterAddress); I2C_WaitAck(BQ32000_I2C_PORT); //·??????? I2C_SendData(BQ32000_I2C_PORT,Data); I2C_WaitAck(BQ32000_I2C_PORT); //?á?? I2C_GenerateSTOP(BQ32000_I2C_PORT); while(I2C_IsBusy(BQ32000_I2C_PORT) == 0); } //BQ32000???????÷ uint8_t BQ32000_ReadRegister(uint32_t I2Cx, uint8_t Addr) { uint8_t result; //·??????ú???· I2C_GenerateSTART(I2Cx); I2C_Send7bitAddress(I2Cx,BQ32000_IIC_ADDRESS,kI2C_Write); I2C_WaitAck(I2Cx); //?è?????????????÷ I2C_SendData(I2Cx, Addr); I2C_WaitAck(I2Cx); //???????? I2C_GenerateRESTART(I2Cx); //?÷?ú?? I2C_Send7bitAddress(I2Cx,BQ32000_IIC_ADDRESS,kI2C_Read); I2C_WaitAck(I2Cx); //?è??Kinetis?????????? I2C_SetMasterMode(I2Cx,kI2C_Read); result = I2C_ReadData(I2Cx); I2C_GenerateAck(I2Cx); I2C_WaitAck(I2Cx); //·??????????? I2C_GenerateSTOP(I2Cx); //???????? result = I2C_ReadData(I2Cx); while(I2C_IsBusy(BQ32000_I2C_PORT) == 0); return result; } //??????BQ32000 void BQ32000_Init(void) { I2C_QuickInit(I2C0_SCL_PB00_SDA_PB01, 96000); } //?è???????±?? void Settime(char tyear,char tmonth,char tdayofweek,char tdate,char thour, char tminute, char tseconds) { secondunits=(tseconds%10); secondtens=(tseconds/10); mintens=(tminute/10); minunits=(tminute%10); hourtens=(thour/10); hourunits=(thour%10); tdayofweek=tdayofweek; datetens=(tdate/10); dateunits=(tdate%10); monthtens=(tmonth/10); monthunits=(tmonth%10); yeartens=(tyear/10); yearunits=(tyear%10); timearrW[0]=secondunits+(secondtens<<4); BQ3200_WriteRegister(BQ32000_I2C_PORT,0x00,timearrW[0]); timearrW[1]=minunits+(mintens<<4); BQ3200_WriteRegister(BQ32000_I2C_PORT,0x01,timearrW[1]); timearrW[2]=hourunits+(hourtens<<4); BQ3200_WriteRegister(BQ32000_I2C_PORT,0x02,timearrW[2]); timearrW[3]=tdayofweek; BQ3200_WriteRegister(BQ32000_I2C_PORT,0x03,timearrW[3]); timearrW[4]=dateunits+(datetens<<4); BQ3200_WriteRegister(BQ32000_I2C_PORT,0x04,timearrW[4]); timearrW[5]=monthunits+(monthtens<<4); BQ3200_WriteRegister(BQ32000_I2C_PORT,0x05,timearrW[5]); timearrW[6]=yearunits+(yeartens<<4); BQ3200_WriteRegister(BQ32000_I2C_PORT,0x06,timearrW[6]); } void Readtime(void) { timearrR[0] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x00); timearrR[1] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x01); timearrR[2] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x02); timearrR[3] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x03); timearrR[4] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x04); timearrR[5] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x05); timearrR[6] = BQ32000_ReadRegister(BQ32000_I2C_PORT,0x06); } [/mw_shl_code]

我用的是飞思卡尔的单片机,不知道这么写问题在哪里,新手上路,跪求指点

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2014-8-25 23:29:39 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-2 12:19

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表