This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI not working for HRMI using nRF52

Hello,

I am trying to implement a Heart Rate Monitor Interface (HRMI) board with my nRF52, using the TWI_sensor example from SDK 12.2. I am unable to read any heart rate values and it appears the the SDA and SCL lines are not communicating whatsoever. This is because the data I am reading is garbage and will not change.

Here is my process:

  1. Set the HRMI mode by writing <0x53><N> to the HRMI I2C address #define HRMI_I2C_ADDR 127 using HRMI_set_mode(), where <N> sets the mode to average mode when N=1:

     ret_code_t HRMI_set_mode() {
     ret_code_t ret_code;
     uint8_t reg[2] = {0x53, 0x01}; // <0x53><N> 
     ret_code = nrf_drv_twi_tx(&m_twi_master, HRMI_I2C_ADDR, reg, sizeof(reg), false);
     return ret_code;
     }
    
  2. Request a set of heart rate samples by writing <0x47><N> to the HRMI I2C address (127) using start_HR(), where <N> is the number of samples to request:

     ret_code_t start_HR(uint8_t num_samples) 
     {
     ret_code_t ret_code;
     uint8_t reg[2] = {HRMI_GET_HR_DATA, num_samples}; // <0x47><N> 
     ret_code = nrf_drv_twi_tx(&m_twi_master, HRMI_I2C_ADDR, reg, sizeof(reg), false);
     return ret_code;
     }
    
  3. Read the response by allocating an array for data returned over I2C using fetch_HR():

     ret_code_t fetch_HR(uint8_t * hr){
     ret_code_t ret_code;
     uint8_t returned_over_I2C[3]; //Array to hold returned data
     ret_code = nrf_drv_twi_rx(&m_twi_master, HRMI_I2C_ADDR, returned_over_I2C,  sizeof(returned_over_I2C));  
     nrf_delay_ms(10);
     	*hr = returned_over_I2C[2];
     	return ret_code;
     }
    

Here is my main function with the function calls to do this:

    int main(void)
    {	
    ret_code_t err_code;  
    
	uint8_t hr;
		
    err_code = twi_master_init();

    HRMI_set_mode(); // Set HRMI to average mode

    APP_ERROR_CHECK(err_code);
    
    while (true)
    {           
        start_HR(0x01); //Request N = 1 (0x01) HR samples
        fetch_HR(&hr); 
        SEGGER_RTT_printf(0, "Heart Rate: %d\n", hr););
	    } }

As for my circuitry, my SDA and SCL lines both have a 4.7kohm pull-up resistor bridged between 5V. On the HRMI board itself, I have not installed the jumper SJ1, and I have installed jumper OP0. No other jumpers are installed to ensure that the I2C address is in fact 127. This is explained in the HRMI datasheet.

I have checked off everything from the troubleshooting section for I2C in the HRMI datasheet (p.33). I am confident my TWI setup is correct because I am able to get sensor data over I2C concurrently from an accelerometer when I run my code (not shown).

When I read all the values from my returned_over_I2C array, the data appears as <0x00><0x36><0x244>, where <0x244> should be the HR1 value read. Again, these values appear even when I disconnect the SDA and SCL lines from the HRMI board.

Does anyone have any insight into this?

Thank you,

Levi

Parents
  • I have compiled and programmed the TWI Scanner Example onto my nRF52 as you suggested. In putty, I received the following message:

    APP:INFO:TWI scanner.
    APP:INFO:No device was found.
    

    This doesn't seem right since I was able to print sensor data from my accelerometer but not this HRMI board. I will see if I can find a Logic Analyzer to use now. Do you think there is something wrong in my code somewhere? Thanks again.

    EDIT: I switched my SCL and SDA lines to pins 26 and 27. Now, the scanner detects my device at address 0x7F. Still no accelerometer though (should be at address 0x53). Also, my program still reads "244" for the heart rate. I feel like I'm narrowing this problem down, just can't find a final solution yet.

Reply
  • I have compiled and programmed the TWI Scanner Example onto my nRF52 as you suggested. In putty, I received the following message:

    APP:INFO:TWI scanner.
    APP:INFO:No device was found.
    

    This doesn't seem right since I was able to print sensor data from my accelerometer but not this HRMI board. I will see if I can find a Logic Analyzer to use now. Do you think there is something wrong in my code somewhere? Thanks again.

    EDIT: I switched my SCL and SDA lines to pins 26 and 27. Now, the scanner detects my device at address 0x7F. Still no accelerometer though (should be at address 0x53). Also, my program still reads "244" for the heart rate. I feel like I'm narrowing this problem down, just can't find a final solution yet.

Children
No Data
Related