I have a temperature/humidity sensor from Sensirion. The Type is SHT21x. The sensor has I2C so it should be able to tranfer the data from the sensor to the Nordic chip over I2C. I`m working with the nRF51DK. The sensor works fine. I wrote my own I2C protocol with bit banging and both measurements did what they should. Now I want to use the soft device, because later I would like to send the data to a mobile device. So I tried to get it work with the twi_hw_master example.
SoftDevice 8.0.0 is flashed on the chip.
The measurement for the humidity works fine! But when I try to read the temperature I wont get data from the sensor. But I do get the ACK when I send the read command for the temperature.
I have a case open on nordic support but for days the problem wont get fixed. Maybe somebody worked with the sensor from Sensiron and had the same problem?
Below my code:
static void timer_timeout_handler()
{
hum_temp = !hum_temp;
if(hum_temp == true)
{
nrf_gpio_pin_toggle(24);
twi_master_transfer(0x80, &hm_hum, 1,0);
twi_master_transfer(0x81, hum_data,3,1);
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, *hum_data);
}
else
{
nrf_gpio_pin_toggle(23);
twi_master_transfer(0x80, &hm_temp, 1,0);
twi_master_transfer(0x81, temp_data,3,1);
nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, *temp_data);
}
}
Every 2 seconds I will jump in the timer_timeout_ handler() routine.
Here the read function:
static bool twi_master_read(uint8_t *data, uint8_t data_length, bool issue_stop_condition)
{
uint32_t timeout = MAX_TIMEOUT_LOOPS; /* max loops to wait for RXDREADY event*/
if (data_length == 0)
{
/* Return false for requesting data of size 0 */
NRF_TWI1->SHORTS = 0; //short are not enabled yet, may not be necessary
return false;
}
else if (data_length == 1)
{
NRF_TWI1->SHORTS = TWI_SHORTS_BB_STOP_Enabled << TWI_SHORTS_BB_STOP_Pos;
}
else
{
NRF_TWI1->SHORTS = TWI_SHORTS_BB_SUSPEND_Enabled << TWI_SHORTS_BB_SUSPEND_Pos;
}
NRF_TWI1->EVENTS_RXDREADY = 0;
NRF_TWI1->TASKS_STARTRX = 1;
/** @snippet [TWI HW master read] */
while (true)
{
while(NRF_TWI1->EVENTS_RXDREADY == 0 && NRF_TWI1->EVENTS_ERROR == 0 && (--timeout))
{
// Do nothing.
}
NRF_TWI1->EVENTS_RXDREADY = 0;
if (timeout == 0 || NRF_TWI1->EVENTS_ERROR != 0)
{
// Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
// Product Anomaly Notification document found at
// www.nordicsemi.com/.../
NRF_TWI1->EVENTS_ERROR = 0;
NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
NRF_TWI1->POWER = 0;
nrf_delay_us(5);
NRF_TWI1->POWER = 1;
NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
(void)twi_master_init();
NRF_TWI1->SHORTS = 0;
return false;
}
*data++ = NRF_TWI1->RXD;
if (--data_length == 1)
{
NRF_TWI1->SHORTS = TWI_SHORTS_BB_STOP_Enabled << TWI_SHORTS_BB_STOP_Pos;
}
if (data_length == 0)
{
break;
}
// Recover the peripheral as indicated by PAN 56: "TWI: TWI module lock-up." found at
// Product Anomaly Notification document found at
// www.nordicsemi.com/.../
nrf_delay_us(20);
NRF_TWI1->TASKS_RESUME = 1;
}
/** @snippet [TWI HW master read] */
/* Wait until stop sequence is sent */
while(NRF_TWI1->EVENTS_STOPPED == 0)
{
// Do nothing.
}
NRF_TWI1->EVENTS_STOPPED = 0;
NRF_TWI1->SHORTS = 0;
return true;
}
I need to know how to fix this problem.