Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] SHTW2 Sensor interface with nordic nrf52810 MCU

Status
Not open for further replies.

faiz18

Newbie level 6
Newbie level 6
Joined
Apr 25, 2017
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
133
Hi All,

I am trying to interface the SHTW2 sensor from Sensirion with the nordic nrf52810 mcu. The Sensor uses I2C to communicate and nordic has its own version of I2C called TWI. From the datasheet of the sensor, The flow to get successful measurement is as follow:
measureflow.JPG

I am able to send the data over to the sensor as I get ACK for all the writes but when I try to read data, I get an NACK.

Does anyone have any idea as to what could be the problem here?

This is what I do for measurement:
1. The I2C slave address is 0x70. We start by sending the write condition i.e. I2C address + write bit (0).
2. Then send the command one by one
3. The read condition i.e. I2C address + read bit (1).
4. Read back sensor data into an array. -> this is where I receive a NACK.

Thanks for the help in advance.

Faizan.
 

Hi,

Please give informations that we can validate:
* show your code
* show a scope picture of SCL and SDA

Klaus
 

Hi Klaus,

Please find the snapshot of the scope below:
20190506_194417.jpg

The part of the code that I use to read the sensor is below:
void SHTW2_read(){
uint8_t m_sample[3];
uint8_t writeMode = 0x70U;
uint8_t readMode = 0x71U;
uint8_t reg[2] = {0x7CU, 0xA2U};
uint8_t reg1 = 0xA2U;
ret_code_t err_code;
//while (m_xfer_done == false);

m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, SHTW2_ADDR, &writeMode, sizeof(writeMode), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
//nrf_delay_ms(5);

m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, SHTW2_ADDR, reg, sizeof(reg), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
//nrf_delay_ms(5);

/*m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, SHTW2_ADDR, &reg1, sizeof(reg1), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);*/
nrf_delay_ms(15);

m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, SHTW2_ADDR, &readMode, sizeof(readMode), true);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);

m_xfer_done = false;
err_code = nrf_drv_twi_rx(&m_twi, SHTW2_ADDR, m_sample, sizeof(m_sample));
APP_ERROR_CHECK(err_code);
//while (m_xfer_done == false);
temperature = (m_sample[0] << 8 | m_sample[1]);
//temperature = temperature * 0.0026702880859375;
//temperature = temperature - 45;
}

Let me know if this is ok. Thanks

Faizan.
 

Hi,

Look at your scope picture.
How do you find out: Whether the
* START, STOP, address, data, ACK (values)
* timing
is correct?

For me: this is impossible.

Klaus
 

Hi Klaus,

Sorry for the bad scope picture. I zoomed in and got the transitions, however the waveforms are noisy:
20190507_195842.jpg

From this I can make out a few things like the first data that I am sending is 0x70 and which I think is as marked in the below picture:
Inked20190507_195842_LI.jpg

Am I right? Please let me know.
 

Hi,

What I see now:
* 0V / 1.8V levels are not usual for I2C. Do you expect those levels? And do they comply with the datasheet specifications?
* SCK: is far away from what I expect it should look like. It looks like a (badly coded) soft-I2C. Why don´t you use I2C hardware?
It still is impossible to check setup and hold times SDA to SCL.

From this I can make out a few things like the first data that I am sending is 0x70 and which I think is as marked in the below picture:
This is what you "like" to see. But I don´t see this.

Transmitting a byte with I2C needs 9 clock cycles: ( 8 data bits + 1 ACK). The interface transmits data via SDA with (timing) respect to SCK.
--> Where you want to see "0x70" there are just 4 maybe 5 clock cycles....impossible to receive 8 (9) bits with just 5 clock cycles!

Klaus
 

Hi Klaus,

It turns out my scope was aliasing the signal as the sample rate was too low. I set a quicker sample rate and got the required waveforms. Sample below:
20190508_140859.jpg

I analysed these waveforms based on your comments and it turns out that I was sending a write command which I didn't need to send as the nrf tx function takes care of it. So I changed my code to remove this statement and sent only the measurement command. Then I read and I get the required temperature readings.

Thanks for the help.

Faizan.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top