软件iic怎么一直调不出来呢
This commit is contained in:
+39
-13
@@ -29,19 +29,41 @@ void iic_stop()
|
||||
|
||||
void iic_ack()
|
||||
{
|
||||
iic_scl(0);
|
||||
iic_sda(0);
|
||||
iic_scl(1);
|
||||
iic_scl(0);
|
||||
}
|
||||
|
||||
void IIC_Write_Byte(unsigned char IIC_Byte){
|
||||
iic_scl(0);
|
||||
char iic_wait_ack()
|
||||
{
|
||||
int a=3000;
|
||||
iic_scl(1);
|
||||
iic_sda(1);
|
||||
change_io_function(iic_sda_GPIO_Port, iic_sda_Pin,1);
|
||||
// while(read_iic_sda)
|
||||
// {
|
||||
// a--;
|
||||
// if(a==0)
|
||||
// {
|
||||
// iic_stop();
|
||||
// return 1;
|
||||
// }
|
||||
// }
|
||||
HAL_Delay(1);
|
||||
change_io_function(iic_sda_GPIO_Port, iic_sda_Pin,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void IIC_Write_Byte(unsigned char IIC_Byte)
|
||||
{
|
||||
iic_scl(0);
|
||||
for(unsigned char i=0;i<8;i++)
|
||||
{
|
||||
if(IIC_Byte & 0x80)
|
||||
{
|
||||
iic_sda(1);
|
||||
}else{
|
||||
}else
|
||||
{
|
||||
iic_sda(0);
|
||||
}
|
||||
IIC_Byte<<=1;
|
||||
@@ -54,17 +76,20 @@ unsigned char IIC_Read_Byte()
|
||||
{
|
||||
unsigned char k=0;
|
||||
iic_scl(0);
|
||||
iic_sda(1);
|
||||
change_io_function(iic_sda_GPIO_Port, iic_sda_Pin,1);
|
||||
for(unsigned char i=0; i<8; i++)
|
||||
{
|
||||
iic_scl(1);
|
||||
k<<=1;
|
||||
if(read_iic_sda==1)
|
||||
{
|
||||
k|=0x01;
|
||||
}
|
||||
k<<=1;
|
||||
|
||||
iic_scl(0);
|
||||
}
|
||||
change_io_function(iic_sda_GPIO_Port, iic_sda_Pin,0);
|
||||
return(k);
|
||||
}
|
||||
|
||||
@@ -73,15 +98,16 @@ void IIC_SAND_DATE(unsigned char DEVICE_ADD,unsigned char IN_DEVICE_ADD,char *DA
|
||||
{
|
||||
iic_start();
|
||||
IIC_Write_Byte(DEVICE_ADD);
|
||||
iic_ack();
|
||||
if(iic_wait_ack()){return;}
|
||||
IIC_Write_Byte(IN_DEVICE_ADD);
|
||||
iic_ack();
|
||||
if(iic_wait_ack()){return;}
|
||||
for(int a=0;a<LONG;a++)
|
||||
{
|
||||
IIC_Write_Byte(*DATAS);
|
||||
DATAS++;
|
||||
|
||||
}
|
||||
iic_ack();
|
||||
if(iic_wait_ack()){return;}
|
||||
iic_stop();
|
||||
}
|
||||
|
||||
@@ -89,17 +115,17 @@ void IIC_READ_DATE(unsigned char DEVICE_ADD,unsigned char IN_DEVICE_ADD,char *DA
|
||||
{
|
||||
iic_start();
|
||||
IIC_Write_Byte(DEVICE_ADD);
|
||||
iic_ack();
|
||||
if(iic_wait_ack()){return;}
|
||||
IIC_Write_Byte(IN_DEVICE_ADD);
|
||||
iic_ack();
|
||||
if(iic_wait_ack()){return;}
|
||||
iic_start();
|
||||
IIC_Write_Byte(IN_DEVICE_ADD+1);
|
||||
iic_ack();
|
||||
IIC_Write_Byte(DEVICE_ADD+1);
|
||||
if(iic_wait_ack()){return;}
|
||||
for(int a=0;a<LONG;a++)
|
||||
{
|
||||
*DATAS=IIC_Read_Byte();
|
||||
DATAS++;
|
||||
}
|
||||
iic_ack();
|
||||
if(iic_wait_ack()){return;}
|
||||
iic_stop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user