AD5272.cpp@0:0af3d83fc568, 2017-05-11 (annotated)
- Committer:
- hamzaaday
- Date:
- Thu May 11 16:48:58 2017 +0000
- Revision:
- 0:0af3d83fc568
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hamzaaday | 0:0af3d83fc568 | 1 | // AD5272 Verson 2.3 |
hamzaaday | 0:0af3d83fc568 | 2 | |
hamzaaday | 0:0af3d83fc568 | 3 | #include "AD5272.h" |
hamzaaday | 0:0af3d83fc568 | 4 | #include "mbed.h" |
hamzaaday | 0:0af3d83fc568 | 5 | |
hamzaaday | 0:0af3d83fc568 | 6 | AD5272::AD5272(PinName sda, PinName scl) : i2c(sda,scl) |
hamzaaday | 0:0af3d83fc568 | 7 | { |
hamzaaday | 0:0af3d83fc568 | 8 | addresse=0x5E; //si GND > 0x5E | si NC > 0x5C |
hamzaaday | 0:0af3d83fc568 | 9 | i2c.frequency(100000); |
hamzaaday | 0:0af3d83fc568 | 10 | } |
hamzaaday | 0:0af3d83fc568 | 11 | void AD5272::initPot() |
hamzaaday | 0:0af3d83fc568 | 12 | { |
hamzaaday | 0:0af3d83fc568 | 13 | char dataw[3]; |
hamzaaday | 0:0af3d83fc568 | 14 | |
hamzaaday | 0:0af3d83fc568 | 15 | dataw[0]=0x1C; |
hamzaaday | 0:0af3d83fc568 | 16 | dataw[1]=0x02; |
hamzaaday | 0:0af3d83fc568 | 17 | i2c.write(addresse, dataw, 2,0); |
hamzaaday | 0:0af3d83fc568 | 18 | } |
hamzaaday | 0:0af3d83fc568 | 19 | |
hamzaaday | 0:0af3d83fc568 | 20 | unsigned short AD5272::getPot() |
hamzaaday | 0:0af3d83fc568 | 21 | { |
hamzaaday | 0:0af3d83fc568 | 22 | char dataw[3]; |
hamzaaday | 0:0af3d83fc568 | 23 | char datar[3]; |
hamzaaday | 0:0af3d83fc568 | 24 | unsigned short valpot = 0; |
hamzaaday | 0:0af3d83fc568 | 25 | |
hamzaaday | 0:0af3d83fc568 | 26 | dataw[0]=0x08; |
hamzaaday | 0:0af3d83fc568 | 27 | dataw[1]=0x00; |
hamzaaday | 0:0af3d83fc568 | 28 | i2c.write(addresse, dataw, 2,1); |
hamzaaday | 0:0af3d83fc568 | 29 | i2c.read(addresse, datar, 2); |
hamzaaday | 0:0af3d83fc568 | 30 | |
hamzaaday | 0:0af3d83fc568 | 31 | return valpot; |
hamzaaday | 0:0af3d83fc568 | 32 | } |
hamzaaday | 0:0af3d83fc568 | 33 | |
hamzaaday | 0:0af3d83fc568 | 34 | void AD5272::setPot(unsigned short v) |
hamzaaday | 0:0af3d83fc568 | 35 | { |
hamzaaday | 0:0af3d83fc568 | 36 | char dataw[3]; |
hamzaaday | 0:0af3d83fc568 | 37 | |
hamzaaday | 0:0af3d83fc568 | 38 | dataw[0] = 0x04; |
hamzaaday | 0:0af3d83fc568 | 39 | dataw[0] = (dataw[0]&0xFC)|((v>>8)&0x3); |
hamzaaday | 0:0af3d83fc568 | 40 | dataw[1] = v; |
hamzaaday | 0:0af3d83fc568 | 41 | |
hamzaaday | 0:0af3d83fc568 | 42 | i2c.write(addresse, dataw, 2,0); |
hamzaaday | 0:0af3d83fc568 | 43 | |
hamzaaday | 0:0af3d83fc568 | 44 | } |