diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-08-28 01:23:06 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-08-28 01:23:06 +0200 |
commit | d6c747ec1c5c27ba0940517346da75bc4945dc9e (patch) | |
tree | 4f1f2fdc27a3a1f556e87c1024e0a0ce649b99c5 /i2c.cpp | |
parent | 989bd0960ed65739ae7a6112094eced7203276b7 (diff) |
Adapted code to changes on new controller board.
Diffstat (limited to 'i2c.cpp')
-rw-r--r-- | i2c.cpp | 74 |
1 files changed, 37 insertions, 37 deletions
@@ -3,71 +3,71 @@ #include "stm32.h" void I2C::enable() { - RCC.enable(RCC.I2C2); + RCC.enable(RCC.I2C1); asm volatile("nop"); - I2C2.CR1 = 0x8000; - I2C2.CR1 = 0; + I2C1.CR1 = 0x8000; + I2C1.CR1 = 0; - I2C2.CR2 = 36; - I2C2.TRISE = 37; - I2C2.CCR = 180; - I2C2.CR1 = 1; + I2C1.CR2 = 36; + I2C1.TRISE = 37; + I2C1.CCR = 180; + I2C1.CR1 = 1; } void I2C::write_reg(uint8_t addr, uint8_t reg, uint8_t data) { - I2C2.CR1 |= 0x100; - while(!(I2C2.SR1 & 0x01)); + I2C1.CR1 |= 0x100; + while(!(I2C1.SR1 & 0x01)); - I2C2.DR = (addr << 1) | 0; - while (!(I2C2.SR1 & 0x02)); - I2C2.SR2; + I2C1.DR = (addr << 1) | 0; + while (!(I2C1.SR1 & 0x02)); + I2C1.SR2; - I2C2.DR = reg; - while (!(I2C2.SR1 & 0x80)); + I2C1.DR = reg; + while (!(I2C1.SR1 & 0x80)); - I2C2.DR = data; - while (!(I2C2.SR1 & 0x04)); + I2C1.DR = data; + while (!(I2C1.SR1 & 0x04)); - I2C2.CR1 |= 0x200; + I2C1.CR1 |= 0x200; } void I2C::read_reg(uint8_t addr, uint8_t reg, uint8_t len, uint8_t* buf) { - I2C2.CR1 |= 0x100; - while(!(I2C2.SR1 & 0x01)); + I2C1.CR1 |= 0x100; + while(!(I2C1.SR1 & 0x01)); - I2C2.DR = (addr << 1) | 0; - while (!(I2C2.SR1 & 0x02)); - I2C2.SR2; + I2C1.DR = (addr << 1) | 0; + while (!(I2C1.SR1 & 0x02)); + I2C1.SR2; - I2C2.DR = reg; - while (!(I2C2.SR1 & 0x80)); + I2C1.DR = reg; + while (!(I2C1.SR1 & 0x80)); - I2C2.CR1 |= 0x100; - while(!(I2C2.SR1 & 0x01)); + I2C1.CR1 |= 0x100; + while(!(I2C1.SR1 & 0x01)); - I2C2.DR = (addr << 1) | 1; - while (!(I2C2.SR1 & 0x02)); - I2C2.SR2; + I2C1.DR = (addr << 1) | 1; + while (!(I2C1.SR1 & 0x02)); + I2C1.SR2; - I2C2.CR1 |= 0x400; // Set ACK. + I2C1.CR1 |= 0x400; // Set ACK. while(len) { if(len == 3) { - while (!(I2C2.SR1 & 0x04)); // Wait for BTF + while (!(I2C1.SR1 & 0x04)); // Wait for BTF - I2C2.CR1 &= ~0x400; // Clear ACK. - *buf++ = I2C2.DR; + I2C1.CR1 &= ~0x400; // Clear ACK. + *buf++ = I2C1.DR; len--; - I2C2.CR1 |= 0x200; // Set STOP. - *buf++ = I2C2.DR; + I2C1.CR1 |= 0x200; // Set STOP. + *buf++ = I2C1.DR; len--; } else { - while (!(I2C2.SR1 & 0x40)); // Wait for RXNE + while (!(I2C1.SR1 & 0x40)); // Wait for RXNE - *buf++ = I2C2.DR; + *buf++ = I2C1.DR; len--; } } |