Datasheet
ENS160 Datasheet v0.95 preliminary / December 2020
31
Example: C-code to calculate MISR on the received DATA, to compare with DATA_MISR:
// The polynomial used in the CRC computation in DATA_MISR
// 76543210 bit weight factor
#define POLY 0x1D // 0b00011101 = x^8+x^4+x^3+x^2+x^0 (x^8 is implicit)
// The hardware register DATA_MISR is updated with every read from a
// register in the range 0x20 to 0x37, using a CRC polynomial (POLY).
// For every register read, call `misr_update()` to keep the software
// variable `misr` in sync with the hardware register.
static uint8_t misr = 0; // Mirror of DATA_MISR (0 is hardware default)
uint8_t misr_update(uint8_t data) {
uint8_t misr_xor= ( (misr<<1) ^ data) & 0xFF;
if( misr&0x80==0 )
misr= misr_xor;
else
misr= misr_xor ^ POLY;
}
// Typically, when an I2C/SPI transaction is completed, read DATA_MISR,
// and compare it with the software `misr`. They should equal. If not
// there is a CRC error: one or more bytes were corrupted in the transfer.
uint8_t misr_set(void) {
return misr;
}
// Once the CRC is wrong, or transactions have been executed without
// calling update() the software `misr` is out of sync with DATA_MISR.
// Read DATA_MISR and call `misr_set()` to bring back in sync.
void misr_set(uint8_t * val) {
misr= val;
}
16.2.15 GPR_WRITE (Address 0x40)
This 8-byte register is used by several functions for the Host System to pass data to the
ENS160. Writes to these registers are not valid when the ENS160 is in DEEP SLEEP or during
a low power portion of an operating mode. Writes should only be done during IDLE mode
(OPMODE 0x01).
Table 36: Register GPR_WRITE
Address 0x40
GPR_WRITE0-7
Address
Bits
Field Name
Default
Access
Field Description
0x40
0:7
GPR_WRITE0
0x00
R/W
General Purpose WRITE Register 0
0x41
0:7
GPR_WRITE1
0x00
R/W
General Purpose WRITE Register 1
0x42
0:7
GPR_WRITE2
0x00
R/W
General Purpose WRITE Register 2
0x43
0:7
GPR_WRITE3
0x00
R/W
General Purpose WRITE Register 3
0x44
0:7
GPR_WRITE4
0x00
R/W
General Purpose WRITE Register 4
0x45
0:7
GPR_WRITE5
0x00
R/W
General Purpose WRITE Register 5
0x46
0:7
GPR_WRITE6
0x00
R/W
General Purpose WRITE Register 6
0x47
0:7
GPR_WRITE7
0x00
R/W
General Purpose WRITE Register 7