nRF52840 SPI does not update register values in MAX30003 module

Hi,

I want to communicate with MAX30003 ECG chip with my nRF52840 board.
I am able to read MAX30003 register values but I cannot write new values to the registers.
Not some specific register but all of them. So I must have done something wrong here...

For example when try to read the INFO register (address 0x0F) of the MAX30003 I get the correct value (chip ID) as I expect which is 0x5131C0 .

Then when I try to enable the ECG_EN bit of the CNFG_GEN register (with address 0x10), I send through SPI the following value:
0x080004( where 08 corresponds to the bit ECG_EN that I want to enable).
When I read back the value of this register I get the initial value (0x00000004) , before I changed it.

This happens with all registers...

here is what I get in the debugger

Here is my code for the spi

void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context)
{
  switch(p_event->type){

    case NRF_DRV_SPI_EVENT_DONE:
    
        spi_xfer_done = true;
        break;
    default:
        NULL;
  }
}

// SPI Initialization
void spi_init(void){ 

    nrf_delay_ms(100); 

    nrf_drv_spi_config_t spi_config  = NRF_DRV_SPI_DEFAULT_CONFIG;   
    spi_config.ss_pin   =  SPI_CS_PN;  // NRF_DRV_SPI_PIN_NOT_USED;  
    spi_config.miso_pin = SPI_MISO_PN; 
    spi_config.mosi_pin = SPI_MOSI_PN; 
    spi_config.sck_pin  = SPI_SCK_PN;  
    spi_config.frequency = NRF_SPI_FREQ_250K;
    spi_config.bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST;
    //spi_config.orc = 0xEE;
    spi_config.mode = NRF_SPI_MODE_0;
    APP_ERROR_CHECK(nrf_drv_spi_init(&m_spi, &spi_config, spi_event_handler, NULL));
}

here are the pin settings

//------SPI------
#define SPI_MOSI_PN    NRF_GPIO_PIN_MAP(0,20)     
#define SPI_SCK_PN     NRF_GPIO_PIN_MAP(0,13)      
#define SPI_CS_PN      NRF_GPIO_PIN_MAP(0,24)       
#define SPI_MISO_PN    NRF_GPIO_PIN_MAP(0,22) 

here are the functions for writing/reading to/from the MAX30003

// SPI read data.    Function returns a register's value in uint32_t form. It also saves the value in ECG_arrayRCV[]
uint32_t ECG_RD_reg(uint8_t reg){  
                      
     uint32_t reg_data = 0;
     uint8_t array_len = 4;

      spi_xfer_done = false;
      ECG_arrayTRF[0] = ((reg << 1) | SPI_RREG );     // prepare data for reception (register to be read + read bit)
      ECG_arrayTRF[1] = 0;
      ECG_arrayTRF[2] = 0;
      ECG_arrayTRF[3] = 0;

      NRF_LOG_INFO( "Send register Address + Read: 0x%02X%02X%02X%02X", ECG_arrayTRF[0], ECG_arrayTRF[1] ,ECG_arrayTRF[2] ,ECG_arrayTRF[3]);
 
      //err_code = nrf_drv_spi_transfer(&m_spi, array_tr, array_len, array_rcv, array_len);  
     err_code = nrf_drv_spi_transfer(&m_spi, ECG_arrayTRF, array_len, ECG_arrayRCV, array_len); 
     while(spi_xfer_done == false);
     APP_ERROR_CHECK(err_code);

     NRF_LOG_INFO( "Register Returns: 0x%02X%02X%02X%02X", ECG_arrayRCV[0], ECG_arrayRCV[1] ,ECG_arrayRCV[2] ,ECG_arrayRCV[3]);
    

     reg_data |= (uint32_t) (ECG_arrayRCV[0] << 24);     // build a uint32_t from the arrayRCV
     reg_data |= (uint32_t) (ECG_arrayRCV[1] << 16);     // ByteH is here, since MSB comes out first from the MAX30003 FIFO 
     reg_data |= (uint32_t) (ECG_arrayRCV[2] <<  8);     // ByteM
     reg_data |= (uint32_t) (ECG_arrayRCV[3] <<  0);     // ByteL

     return reg_data;
}

// SPI send data  
void ECG_WR_reg(uint8_t reg, uint32_t data){

  uint8_t array_dum[4] = {0};
  uint8_t array_len = 4;

  spi_xfer_done = false;
  ECG_arrayTRF[0] = ((reg << 1) & SPI_WREG);        // register to be written + write bit
  ECG_arrayTRF[1] = (uint8_t)((data & 0x00FF0000) >> 16);
  ECG_arrayTRF[2] = (uint8_t)((data & 0x0000FF00) >> 8);
  ECG_arrayTRF[3] = (uint8_t)((data & 0x000000FF) >> 0);

  NRF_LOG_INFO( "Send reg address + Write: 0x%02X%02X%02X%02X", ECG_arrayTRF[0], ECG_arrayTRF[1] ,ECG_arrayTRF[2] ,ECG_arrayTRF[3]);

  err_code = nrf_drv_spi_transfer(&m_spi, ECG_arrayTRF, 4, ECG_arrayRCV, 4);
  while(spi_xfer_done == false);
  APP_ERROR_CHECK(err_code);
}

and here is my main()

    uint32_t res = 0;
    NRF_LOG_INFO("HELLO");
    spi_init();    // Initialize SPI   
 
    NRF_LOG_INFO("ECG_INFO: 0x%08X", ECG_RD_reg(ECG_INFO));
  
   
      
    res = 0x080004;
    ECG_WR_reg(ECG_CNFG_GEN, res);    // Enable [ECG channel, DC Lead-Off Detect, Resistive Bias on Pos/Neg EI], R_bias = 100MU
    nrf_delay_ms(100);
    NRF_LOG_INFO("ECG_CNFG_GEN --> What I get: 0x%06X   ---  What I want: 0x%06X", ECG_RD_reg(ECG_CNFG_GEN), res);


Any ideas what I am doing wrong?

Thank you!

Parents
  • Hardware: If you are using max30003wing breakout board, try to connect both breakout GNDs to the DK.

    Software: I manage to read the data 0x080004 back using max30003wing breakout. I am using the following setup, the rest are the same.

    #define SPI_INSTANCE 1 /**< SPI instance index. */
    static const nrf_drv_spi_t m_spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
    static volatile bool spi_xfer_done; /**< Flag used to indicate that SPI instance completed the transfer. */
    
    #define SPI_MISO_PIN NRF_GPIO_PIN_MAP(1, 8)
    #define SPI_MOSI_PIN 30
    #define SPI_SCK_PIN 31
    #define SPI_SS_PIN NRF_GPIO_PIN_MAP(1, 7)


  • Hi, no I am not using the max30003wing I am using my custom board with MAX300003 and nRF52840 chip
    and I cannot modify the pins unfortunately

Reply Children
No Data
Related