新手上路
- 积分
- 45
- 金钱
- 45
- 注册时间
- 2014-2-12
- 在线时间
- 1 小时
|

楼主 |
发表于 2014-3-19 01:15:54
|
显示全部楼层
就是连续两次读呢。但第二次读到数都是0。
代码如下,里面用到的start stop ack nack 均是直接用的原子哥的myiic.c呢 。下面的代码没层次来着,不好意思哈,还不知道怎样贴有层次的代码呢
u16 AB4_ReadLenByte(u8 ReadAddr,u8 Len)
{
u8 t;
u16 temp=0;
u16 temp2=0;
IIC_Start();
IIC_Send_Byte(0XE8); //发送写命令
if(IIC_Wait_Ack())
{
printf("\n\n\n读数据时,器件寻址失败\n\n\n");
delay_ms(1000);
}
IIC_Send_Byte(ReadAddr);
if(IIC_Wait_Ack())
{
printf("\n\n\n读数据时,数据地址寻址失败\n\n\n");
delay_ms(1000);
}
IIC_Start();
IIC_Send_Byte(0XE9);
if(IIC_Wait_Ack()) //waiting for the repsonse from slave, in order to confirm that the writing is OK
{
printf("\n\n\n读数据时,器件寻址失败\n\n\n");
delay_ms(1000);
}
for(t=0;t<Len-1;t++)
{
// ack=1时,发送ACK,ack=0,发送nACK
temp|=IIC_Read_Byte(1);
temp><<=8;
delay_ms(50);
}
delay_ms(1000);
temp|=IIC_Read_Byte(0);
IIC_Stop();//产生一个停止条件
delay_ms(50);
temp2=0;
for(t=0;t<Len;t++)
{
temp2=temp2<<8;
temp2|=((temp>>(8*t))&0Xff);
printf("\n\r\nat the No %dth transformation,OUT0(half word)=%d\n\r\n",t,temp2);
}
printf("\n\r\nafter transformation,OUT0(15...8,7...0)=%d\n\r\n",temp2);
return temp2;
} |
|