金牌会员
- 积分
- 1000
- 威望
- 550
- 贡献
- 288
- 兑换币
- 335
- 注册时间
- 2013-12-3
- 在线时间
- 81 小时
- 毕业学校
- 上海工程技术大学
|
6#
楼主 |
发表于 2014-8-25 15:05:47
|
只看该作者
- //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);
- }
复制代码 对于BQ32000这样操作对吗?可是没有读出数据,玩过的指点一下呗
|
|