SPI not working with AFE4490 sensor

Hello community,

I have been recently working with AFE4490 sensor from protocentral (breakout board).

GitHub - Protocentral/protocentral-afe4490-arduino: Arduino Library for the AFE4490 SPO2 shield and breakout boards from Protocentral

Previously I have ported multiple sensors for my hobby projects and never faced any issue but I am not able to initialize the registers with this sensor in nrf52840.

Here are few things I trieD:

1. I evaluated this sensor with ESP32 C3 module and the sensor LED turns ON after succesful intialization.

2. Ported the C++ code base to nrf52840 SPI peripheral example code and description is mentioned below:

3. Used SPI pin as mentioned below:

4. Initialization routine for SPI is mentioned below:

nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.miso_pin = AFE_MISO_PIN;
spi_config.mosi_pin = AFE_MOSI_PIN;
spi_config.sck_pin = AFE_SCK_PIN;
spi_config.ss_pin = AFE_CS_Pin;
spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
APP_ERROR_CHECK(nrf_drv_spi_init(&afe_spi, &spi_config, afe_spi_event_handler, NULL));

nrf_gpio_cfg_output(AFE_MOSI_PIN);
nrf_gpio_cfg_output(AFE_SCK_PIN);
nrf_gpio_cfg_output(AFE_CS_Pin);

nrf_delay_ms(300);

Original working Arduino write function mentioned below:

m more focused on register initialiozation. Once its success then I will proceed further with reading of SPo2 and heart rate values. 

I am not sure where I am going wrong, I tried changing the modes to Mode 0,1,2,3 but nothing works. Its been a week now. Requesting somebody to help me on this.

Thank you.

  • Attached the C file FYR. Attaching the sensor image below:

    Requesting some guidance in the earliest.

    Thank you.

  • Two items to start with, worth fixing and retesting. The Arduino code uses SPI Mode 0 and 2MHz clock:

    #define AFE44XX_SPI_SPEED 2000000
    SPISettings SPI_SETTINGS(AFE44XX_SPI_SPEED, MSBFIRST, SPI_MODE0); 
    

    At 8MHz and with a separate sensor board the nRF52 SPIM requires high-drive outputs (H0H1) on MOSI, SCK and CS. The default S0S1 may work at 2MHz, but will not be reliable unless the sensor is on the same board as the nRF52. Try these settings:

    static NRF_SPIM_Type * const pSPIM = NRF_SPIM0;
    
      pSPIM->ENABLE = 0;                        // disable SPI
      NRF_P0->PIN_CNF[AFE_CS_PIN]   = 0x301;  // output, high drive high and low H0H1
      NRF_P0->PIN_CNF[AFE_SCK_PIN]  = 0x301;  // output, high drive high and low H0H1
      NRF_P0->PIN_CNF[AFE_MOSI_PIN] = 1;      // output, standard drive S0S1
      NRF_P0->PIN_CNF[AFE_MISO_PIN] = 0;      // input pin, input buffer connected, no pull, S0S1, sense disabled
      NRF_P0->OUTSET = 1 << AFE_CS_PIN;       // deactivate by setting chip select high
      pSPIM->PSEL.SCK     = AFE_SCK_PIN;
      pSPIM->PSEL.MOSI    = AFE_MOSI_PIN;
      pSPIM->PSEL.MISO    = AFE_MISO_PIN;
      pSPIM->CONFIG = 0;
      pSPIM->FREQUENCY = AFE44XX_SPI_SPEED;  // Same as Arduino
      pSPIM->ORC = 0xFF;                     // Unused Tx bytes, set all bits high
    
      pSPIM->EVENTS_ENDTX = 0;
      pSPIM->EVENTS_ENDRX = 0;
      pSPIM->EVENTS_END   = 0;
      // Disable all interrupts
      pSPIM->INTENCLR = 0xFFFFFFFFUL;
      // Enable selected interrupts
      pSPIM->INTENSET = 0x040;   // END
      //pSPIM->INTENSET = 0x010;   // END_RX
      //pSPIM->INTENSET = 0x100;   // END_TX
      
      // Set interrupt priority and enable interrupt
      NVIC_SetPriority(IRQn, IRQpriority);
      NVIC_ClearPendingIRQ(IRQn);
      NVIC_EnableIRQ(IRQn);
    
      mSpiInterruptCounter = 0UL;
      pSPIM->ENABLE = 7;               // enable SPI
    

    nrfx style for setting port pins:

    Example:
    nrf_gpio_cfg(AFE_SCK_PIN,  NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);

  • I got the code working (register initialization worked and I did see the sensor light turning ON) with these settings as attached in the code base. Can you please confirm if the read function that I ported is correct? or do i need to do any modifications for the same?

    Thanks in advance.

  • Did you just use the read function that hmolesworth uploaded here? I haven't tested it myself, so I can't confirm whether it's okay and I don't know how exactly you've set it up on your end. Nor do I know what modifications you might need, so please explain further what you mean here.

    Best regards,

    Simon

Related