int i2cWrite(u8 a) { u8 i; u8 return_ack; for (i=0; i<8; i++) { SetLowSCL(); if (a & 0x80) SetHighSDA(); else SetLowSDA(); SetHighSCL(); a <<= 1; } SetLowSCL(); SetHighSDA(); SetHighSCL(); if (I2C_GPIO->IDR&(1<<SDA)) return_ack = NO_I2C_ACK; else return_ack = OK_I2C_ACK; SetLowSCL(); i2c_delay(); return(return_ack); }
int CI2C::Write(uint8_t a) { uint8_t i; uint8_t return_ack; for (i=0; i<8; i++) { SetLowSCL(); if (a & 0x80) SetHighSDA(); else SetLowSDA(); SetHighSCL(); a <<= 1; } SetLowSCL(); SetHighSDA(); SetHighSCL(); if (I2C_GPIO->IDR&(1<<SDA)) return_ack = NO_I2C_ACK; else return_ack = OK_I2C_ACK; SetLowSCL(); delay(); return(return_ack); }
void i2cStart() { SetHighSCL(); SetHighSDA(); SetHighSCL(); SetLowSDA(); SetLowSCL(); SetHighSDA(); }
uint8_t CI2C::Read(uint8_t ack) { uint8_t i; uint8_t c = 0x00; SetLowSCL(); for (i = 0; i < 8; i++) { c = c << 1; SetHighSCL(); if (I2C_GPIO->IDR&(1<<SDA)) c = c | 0x01; SetLowSCL(); } if(ack) { SetLowSDA(); } else { SetHighSDA(); } SetHighSCL(); SetLowSCL(); SetHighSDA(); /* if (ack > 0) { //0 SetLowSDA(); SetHighSCL(); SetLowSCL(); // SetHighSDA(); } else { //1 SetHighSDA(); SetHighSCL(); SetLowSCL(); // SetLowSDA(); } */ return (c); }
void CI2C::Start() { SetHighSCL(); SetHighSDA(); SetHighSCL(); SetLowSDA(); SetLowSCL(); SetHighSDA(); }
u8 i2cRead(u8 ack) { u8 i; u8 caracter = 0x00; SetLowSCL(); SetHighSDA(); for (i=0; i<8; i++) { caracter = caracter << 1; SetHighSCL(); if (I2C_GPIO->IDR&(1<<SDA)) caracter = caracter + 1; SetLowSCL(); } if (ack) { SetLowSDA(); } SetHighSCL(); SetLowSCL(); i2c_delay(); return (caracter); }
void i2cStop() { SetLowSCL(); SetLowSDA(); SetHighSCL(); SetLowSDA(); SetHighSCL(); SetHighSDA(); }
void i2c_0_init() { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO_I2C, ENABLE); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = (1<<SDA)|(1<<SCL); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;//this sets the GPIO modules clock speed GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; // this sets the pin type to open drain GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; // this disables resistor GPIO_Init(I2C_GPIO, &GPIO_InitStruct); SetHighSCL(); SetLowSDA(); SetHighSDA(); }