白小姐四肖必选一肖

芯片IC单片机解密百科

十年专注单片机解密

解密STM32的IIC接口主要特性与具体代码

STM32JUYOUIICJIEKOU,JIEKOUYOUYIXIAZHUYAOTEXING

白小姐四肖必选一肖DUOZHUJIGONGNENG:GAIMOKUAIJIKEZUOZHUSHEBEIYEKEZUOCONGSHEBEI

ZHUSHEBEIGONGNENG

CDIZHIJIANCE

白小姐四肖必选一肖CHANSHENGHEJIANCE7WEI/10WEIDIZHIHEGUANGBOHUJIAO

ZHICHIBUTONGDETONGXUNSUDU

ZHUANGTAIBIAOZHI:

白小姐四肖必选一肖FASONGQI/JIESHOUQIMOSHIBIAOZHI

ZIJIEFASONGJIESHUBIAOZHI

ZONGXIANMANGBIAOZHI

CUOWUBIAOZHI

2GEZHONGDUANXIANGLIANG

KEXUANDELAZHANGSHIZHONGGONGNENG

白小姐四肖必选一肖JUDANZIJIEHUANCHONGQIDEDMA

1.DUIYUYINGJIANIICDECHUSHIHUALIUCHENGBAOKUO

1.PEIZHIIOKOU,PEIZHIWEIGPIO_Mode_AF_ODMOSHI

2.XUANZEIICMOSHI

3.XUANZESHIFOUSHINENGZIDONGYINGDAYIJISHEBEIDIZHIZHANGDU

4.SHEZHIIICZONGXIANDECHUANSHUSULV

白小姐四肖必选一肖2.YINGJIANIICDEDUXIECAOZUOQISHILUOJISHANGHEBIAOZHUNZONGXIANLEISI,YESHIFASONGDIZHIDENGDAIackFASONGSHUJUDENGDAIACK,DANSHIYINWEIYOUYINGJIANDEZIDONGCANYU,SUOYIWOMENBUXUYAOYANSHILE

JUTIDAIMARUXIA

voidHmcIICInit(void)

{

白小姐四肖必选一肖/*GPIOCHUSHIHUA*/

白小姐四肖必选一肖GPIO_InitTypeDefGPIO_InitStructure;

/*PEIZHIYINGJIANIICXUYAODEBIANLIANG*/

白小姐四肖必选一肖I2C_InitTypeDefI2C_InitStructure;

白小姐四肖必选一肖/*SHINENGYUI2C1YOUGUANDESHIZHONG*/

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE);

/*PB6-I2C1_SCL、PB7-I2C1_SDA*/

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_OD;

GPIO_Init(GPIOB,&GPIO_InitStructure);

白小姐四肖必选一肖/*IICWAISHECHUSHIHUA*/

/*I2CPEIZHI*/

I2C_InitStructure.I2C_Mode=I2C_Mode_I2C;//PEIZHIWEIPUTONGIICMOSHI

白小姐四肖必选一肖//I2C_InitStructure.I2C_DutyCycle=I2C_DutyCycle_2;

白小姐四肖必选一肖//I2C_InitStructure.I2C_OwnAddress1=SlaveAddress;

白小姐四肖必选一肖I2C_InitStructure.I2C_Ack=I2C_Ack_Enable;//SHINENGZIDONGYINGDA

I2C_InitStructure.I2C_AcknowledgedAddress=I2C_AcknowledgedAddress_7bit;

I2C_InitStructure.I2C_ClockSpeed=50000;//5KDESUDU?

/*I2C1CHUSHIHUA*/

I2C_Init(I2C1,&I2C_InitStructure);

/*SHINENGI2C1*/

I2C_Cmd(I2C1,ENABLE);

/*YUNXUYINGDAMOSHI*/

I2C_AcknowledgeConfig(I2C1,ENABLE);

}

voidHmcByteWrite(u8addr,u8dataValue)

{

I2C_GenerateSTART(I2C1,ENABLE);

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));

白小姐四肖必选一肖I2C_Send7bitAddress(I2C1,HMC_ADDR,I2C_Direction_Transmitter);

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

白小姐四肖必选一肖I2C_SendData(I2C1,addr);

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED));

I2C_SendData(I2C1,dataValue);

白小姐四肖必选一肖while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED));

I2C_GenerateSTOP(I2C1,ENABLE);

}

白小姐四肖必选一肖u8HmcByteRead(u8addr)

{

u8dataValue;

while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));

I2C_GenerateSTART(I2C1,ENABLE);//QISHIXINHAO

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));

白小姐四肖必选一肖I2C_Send7bitAddress(I2C1,HMC_ADDR,I2C_Direction_Transmitter);//FASONGSHEBEIDIZHI+XIEXINHAO

白小姐四肖必选一肖while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));//

I2C_Cmd(I2C1,ENABLE);

白小姐四肖必选一肖I2C_SendData(I2C1,addr);//FASONGCUNCHUDANYUANDIZHI,CONG0KAISHI

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED));

I2C_GenerateSTART(I2C1,ENABLE);//QISHIXINHAO

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));

I2C_Send7bitAddress(I2C1,HMC_ADDR,I2C_Direction_Receiver);//FASONGSHEBEIDIZHI+DUXINHAO

while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

I2C_AcknowledgeConfig(I2C1,DISABLE);

白小姐四肖必选一肖I2C_GenerateSTOP(I2C1,ENABLE);

白小姐四肖必选一肖while(!(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)));

dataValue=I2C_ReceiveData(I2C1);//DUCHUJICUNQISHUJU

returndataValue;

}