//读1个字节,ack=1时,发送ACK,ack=0,发送nACK u8 IIC_Read_Byte(unsigned char ack) { unsigned char i,receive=0; //SDA_IN();//SDA设置为输入 GPIO_InitTypeDef GPIO_InitStructure; // RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOB, &GPIO_InitStructure); for(i=0;i<8;i++ ) { IIC_SCL_0; delay_us(2); IIC_SCL_1; receive<<=1; if(READ_SDA)receive++; delay_us(1); } if (!ack) IIC_NAck();//发送nACK else IIC_Ack(); //发送ACK return receive; }
//读1个字节,ack=1时,发送ACK,ack=0,发送nACK u8 IIC_Read_Byte(unsigned char ack) { unsigned char i, receive = 0; receive = 0; SDA_IN(); //SDA设置为输入 for(i = 0; i < 8; i++) { IIC_SCL = 0; delay_us(2); IIC_SCL = 1; receive <<= 1; if(READ_SDA) receive++; delay_us(1); } if(!ack) IIC_NAck();//发送nACK else IIC_Ack(); //发送ACK return receive; }
void IIC_Read_Byte(unsigned char ack,unsigned char *data) { unsigned char i; unsigned char receive=0; SDA_IN(); for(i=0; i<8; i++) { IIC_SCL(0); delay_us(2); IIC_SCL(1); receive <<= 1; if(READ_SDA)receive++; delay_us(1); } *data = receive; if (!ack) IIC_NAck(); else IIC_Ack(); }
void HAL_I2C_NoAck(void) { #ifdef USE_I2C_OLD I2C_NoAck(); #else IIC_NAck(); #endif }
//读1个字节,ack=1时,发送ACK,ack=0,发送nACK static u8 IIC_Read_Byte(unsigned char ack) { unsigned char i,receive=0; IIC_SDA(1); SDA_IN();//SDA设置为输入 for(i=0;i<8;i++ ) { receive<<=1; IIC_SCL(1); I2C_delay(); if(READ_SDA)receive |= 0x01; IIC_SCL(0); I2C_delay(); } if (ack) IIC_Ack(); //发送ACK else IIC_NAck();//发送nACK return receive; }
/**************************实现函数******************************************** *函数原型: uint8_t IIC_Receive_Byte(unsigned char ack) *功 能: //读1个字节,ack=1时,发送ACK,ack=0,发送nACK *******************************************************************************/ uint8_t IIC_Receive_Byte(unsigned char ack) { unsigned char i,receive = 0; SDA_INMODE(); for(i = 0; i < 8; i++ ) { IIC_SCL = 0U; delay_us(2); IIC_SCL = 1U; receive <<= 1; if(READ_SDA)receive++; //READ_SDA is P5.1 delay_us(1); } if (!ack) IIC_NAck(); //refuse ACK else IIC_Ack(); //ACK return receive; }
u8 IIC_Read_Byte(unsigned char ack) //read A byte from IIC { u8 i,dat; i = 8; SDA = 1; SCL = 0; do { SCL = 1; IIC_Delay(); dat <<= 1; if(SDA) dat++; SCL = 0; IIC_Delay(); } while(--i); if (ack == 0) IIC_NAck();//·¢ËÍnACK else if (ack == 1) IIC_Ack(); //·¢ËÍACK return(dat); }