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

nRF52840 output the 32.768kHz clock on any GPIO in SPI Communication.

Dear Nordic Developer Zone,

I am working on MAX30003 ECG (https://datasheets.maximintegrated.com/en/ds/MAX30003.pdf)  with Nrf52840-DK. My sensor is work on the 32.768kHz external clock. 

but in Nrf I don't know which GPIO_PIN is assigned for that.

I visited below link but I unable to find solutions: 

https://devzone.nordicsemi.com/f/nordic-q-a/23474/nrf52832-fclk-pin/92210#92210

https://devzone.nordicsemi.com/f/nordic-q-a/15996/can-the-nrf52-output-the-32-768khz-clock-on-a-gpio

I am referring (SDK15.2 -PCA10056-spi code)

I have some questions about that:

1) Can I do the merging of timer and gpiote example code into SPI?

2) please give me detail about how to generate 32.768kHz clock ?

I have stuck  on below issue, 

https://maximsupport.microsoftcrmportals.com/en-us/knowledgebase/article/000096610

Thanks,

Rohit Patil

  • Defalt value is 0x00. The prod specs register descriptions like the LFCLKSRC describes the reset value of each register if applicable. 

    Without writing to the LFCLKSRC you will use the internal 32.768kHz RCOSC, the external clock inputs are disconnected (high impedance). 

    When using an external crystal the voltage of the crystals drive signals are too low to control a digital circuit, the clock signal is therefore amplified by the internal LF Clock peripheral and fed back into the crystal in order to achieve resonance at a higher voltage level. The time it takes to achieve a stable clock signal of high enough voltage is what accounts for the start-up time of a crystal oscillator clock source. 

    You can however use an external clock signal that already has the required voltage level, but then you must bypass the internal amplifier. 

  • Hi haakonsh,

    is it possibe to produce a 32KHz clock on any gpio of nrf52840? What is the closest clock i can produce on GPIO without using any external clock source? 

    Thanks in advance. 

  • In the case of 52832, you can make it by using pwm.

    i am not sure about 840, i think it should work

  • 32.000kHz is not a problem, just set up a TIMER or the PWM peripheral.

    32.768 is not possible: 

    (1/ 32.768 kHz) / (1/ 16MHz) = 488.2812501

    You'll be off by 0.2812501 * (1 / 16MHz) = 17.757813ns. 

    In Hz; 1/ ((1/ 32.768kHz) + 17.757813ns) = 32.74894378kHz

  • Hi ,

    I have generated almost closest frequency near of 32.7KHz using  PWM_Liabrary Example( PCA10056).

    But I unable to get same frequency when  I merge this code into Ble_app_uart.so please help me with this issues, please Find Attachment.

    void pwm_init()
    {
       ret_code_t err_code;
        /* 2-channel PWM, 200Hz, output on DK LED pins. */
        app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(31L, ARDUINO_0_PIN, BSP_LED_1);
        /* Switch the polarity of the second channel. */
        pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;
        /* Initialize and enable PWM. */
        err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
        APP_ERROR_CHECK(err_code);
        app_pwm_enable(&PWM1);
       
    
    //	  while (true)
        {
     for (uint8_t i = 0; i < 40; ++i)
            {
                value = (i < 20) ? (i * 5) : (100 - (i - 20) * 5);
                ready_flag = false;
                /* Set the duty cycle - keep trying until PWM is ready... */
                while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
                /* ... or wait for callback. */
                while (!ready_flag);
                APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 1, value));
            }
    				
        }
    }
    
    int main(void)
    {
    	pwm_init();
        bool erase_bonds;
        uint32_t err_code;
        // Initialize.
        uart_init();
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    	  
    spi_config.frequency = NRF_SPIM_FREQ_125K;
    spi_config.ss_pin = NRFX_SPIM_SS_PIN;
    spi_config.miso_pin = NRFX_SPIM_MISO_PIN;
    spi_config.mosi_pin = NRFX_SPIM_MOSI_PIN;
    spi_config.sck_pin = NRFX_SPIM_SCK_PIN;
    //spi_config.dcx_pin = NRFX_SPIM_DCX_PIN;
    spi_config.use_hw_ss = true;
    spi_config.ss_active_high = false;
    spi_config.mode = NRF_SPIM_MODE_0; // SCK active high, sample on leading edge of clock, CPOL=0/CPHA=0
    spi_config.bit_order=NRF_SPIM_BIT_ORDER_MSB_FIRST; 
    spi_config.orc=0x00;
    APP_ERROR_CHECK(nrfx_spim_init(&spi, &spi_config, spim_event_handler, NULL));
    	NRF_LOG_INFO("NRFX SPIM example started.");
    	MAX30003_begin();
        // Start execution.
        printf("\r\nUART started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        advertising_start();
    
    
        for (;;)
        {	
    			
    			  // Reset rx buffer and transfer done flag
             memset(m_rx_buf, 0, m_length);
             spi_xfer_done = false;
    			  	for(i=0;i<=200;i++)
    	        {
    						nrf_delay_ms(10);
                stored[i]=MAX30003_Reg_Read(ECG_FIFO); //0x0F 
                stored[i]=stored[i]>>8;	
    						
                valid_data[i] = (((uint8_t)stored[i])>>3)&0x07;
    						sprintf(ARRAY,"%d\n",  stored_status[i]);
    						printf(ARRAY);
    	        }
    			  err_code = ble_nus_data_send(&m_nus, ARRAY , &size, m_conn_handle);
            idle_state_handle();
    			  while (!spi_xfer_done)
    
    NRF_LOG_FLUSH();
    
        }
    	}

Related