Hi,
we have just started to work with the HDC1080 to get humidity and temperature readings in our sensor nodes. The MCU on the nodes is a Atmel/Microchip Atsam4 and we're using the ASF TWI/I2C library for interfacing with I2C devices.
We are having some problems interfacing with the HDC1080. We can successfully read the Device ID register (OxFF) which returns 0x1050 as per the docs. So, we can assume it's not an hardware problem. To read the Device ID register however, we first have to do an I2C write to the sensor. It doesn't seem to matter what we write, but if we don't write anything we're not able to read the Device ID register. Does this makes sense? From the docs it looks like the register should be readable without any previous commands.
We are not able to read the temperature and humidity registers however. Even if we first issue a write to reg 0x00, a read of the humidity and temperature registers fails. We've tried various delays between the write and the reads, but it doesn't seem to make any difference.
Could the problem be related to the Atmel/Microchip I2C/TWI libraries not being compatible with the sensor interface. We're using the high level functions twi_master_read and twi_master_write. Here is the code for the twi_master_read:
uint32_t twi_master_read(Twi *p_twi, twi_packet_t *p_packet) { uint32_t status; uint32_t cnt = p_packet->length; uint8_t *buffer = p_packet->buffer; uint8_t stop_sent = 0; uint32_t timeout = TWI_TIMEOUT;; /* Check argument */ if (cnt == 0) { return TWI_INVALID_ARGUMENT; } /* Set read mode, slave address and 3 internal address byte lengths */ p_twi->TWI_MMR = 0; p_twi->TWI_MMR = TWI_MMR_MREAD | TWI_MMR_DADR(p_packet->chip) | ((p_packet->addr_length << TWI_MMR_IADRSZ_Pos) & TWI_MMR_IADRSZ_Msk); /* Set internal address for remote chip */ p_twi->TWI_IADR = 0; p_twi->TWI_IADR = twi_mk_addr(p_packet->addr, p_packet->addr_length); /* Send a START condition */ if (cnt == 1) { p_twi->TWI_CR = TWI_CR_START | TWI_CR_STOP; stop_sent = 1; } else { p_twi->TWI_CR = TWI_CR_START; stop_sent = 0; } while (cnt > 0) { status = p_twi->TWI_SR; if (status & TWI_SR_NACK) { return TWI_RECEIVE_NACK; } if (!timeout--) { return TWI_ERROR_TIMEOUT; } /* Last byte ? */ if (cnt == 1 && !stop_sent) { p_twi->TWI_CR = TWI_CR_STOP; stop_sent = 1; } if (!(status & TWI_SR_RXRDY)) { continue; } *buffer++ = p_twi->TWI_RHR; cnt--; timeout = TWI_TIMEOUT; } while (!(p_twi->TWI_SR & TWI_SR_TXCOMP)) { } p_twi->TWI_SR; return TWI_SUCCESS; }
Could it be that the functions from the ASF API is to high level for the HDC1080 interface?
Best regards,
Erik