1 | cs5460.h:
|
2 | // commands for calibrate control
|
3 | #define CALIBRATE_CONTROL 0xC0
|
4 | #define CALIBRATE_CURRENT 0x08
|
5 | #define CALIBRATE_VOLTAGE 0x10
|
6 | #define CALIBRATE_CURRENT_VOLTAGE 0x18 // both chan.
|
7 | #define CALIBRATE_GAIN 0x02
|
8 | #define CALIBRATE_OFFSET 0x01
|
9 |
|
10 | #define POWER_UP_HALT_CONTROL 0xA0
|
11 | #define DATA_READY (0x01L<<23)
|
12 |
|
13 | cs5460.c:
|
14 | unsigned int cs5460_getStatus()
|
15 | {
|
16 | return cs5460_readReg(STATUS_REGISTER);
|
17 | }
|
18 |
|
19 | void cs5460_clearStatus(uint32_t cmd)
|
20 | {
|
21 | cs5460_writeReg(STATUS_REGISTER, cmd);
|
22 | }
|
23 | void cs5460_calibrate(uint8_t cmd)
|
24 | {
|
25 | cmd = (CALIBRATE_CONTROL | cmd);
|
26 | printf("start cal with mask %i ... \n",cmd);
|
27 |
|
28 | printf("start with status ... %i \n",cs5460_getStatus());
|
29 | cs5460_send(POWER_UP_HALT_CONTROL);
|
30 | cs5460_clearStatus(DATA_READY);
|
31 | printf("now in status ... %i \n",cs5460_getStatus());
|
32 |
|
33 | cs5460_send(cmd);
|
34 | delay_ms(1250);
|
35 | while(!(cs5460_getStatus() & DATA_READY)) { printf("wait toooooooo long ... %i \n",cs5460_getStatus());
|
36 | delay_ms(1000);
|
37 | };
|
38 | // wait until data ready;
|
39 | cs5460_clearStatus(DATA_READY);
|
40 | }
|
41 | uint32_t cs5460_calibrateACVoltageOffset()
|
42 | {
|
43 | cs5460_calibrate(CALIBRATE_VOLTAGE | CALIBRATE_OFFSET);
|
44 | return cs5460_readReg(VOLTAGE_AC_OFFSET_REGISTER);
|
45 | }
|
46 | uint32_t cs5460_calibrateDCVoltageOffset()
|
47 | {
|
48 | cs5460_calibrate(CALIBRATE_VOLTAGE | CALIBRATE_OFFSET);
|
49 | return cs5460_readReg(VOLTAGE_DC_OFFSET_REGISTER);
|
50 | }
|