void DS3231_WR_Byte(uint8_t addr,uint8_t bytedata)
{
static uint8_t DS3231_Data[2];
DS3231_Data[0]=addr;
DS3231_Data[1]=bytedata;
HAL_I2C_Master_Transmit(&hi2c1,DS3231_WriteAddress,DS3231_Data, 2, 1000); //判断容量大小的
/*
I2C_Start();
I2C_SendByte(DS3231_WriteAddress);
I2C_WaitAck();
I2C_SendByte(addr);
I2C_WaitAck();
I2C_SendByte(bytedata);
I2C_WaitAck();
I2C_Stop();*/
}
uint8_t DS3231_RD_Byte(uint8_t addr)
{
这块以下可能有问题
uint8_t Arec[2],value;
HAL_I2C_Master_Receive(&hi2c1, DS3231_ReadAddress,addr, sizeof Arec, 1000);
value=(Arec[0]<<8)|(Arec[1]);
return value;
/* uint8_t Dat=0;
I2C_Start();
I2C_SendByte(DS3231_WriteAddress);
I2C_WaitAck();
I2C_SendByte(addr);
I2C_WaitAck();
I2C_Start();
I2C_SendByte(DS3231_ReadAddress);
I2C_WaitAck();
Dat=I2C_ReceiveByte();
I2C_Stop();
return Dat;*/
}
我想用HAL_HAL_I2C_Master_Transmit和HAL_I2C_Master_Receive库函数替换标准函数,现在发送字节应该是没问题了,读取各位给看一下要怎么改一下呢
|